Subversion Repositories camp_sysinfo_client_3

Rev

Rev 197 | Rev 218 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 197 Rev 211
Line 180... Line 180...
180
# to the calling routine
180
# to the calling routine
181
sub readConfig {
181
sub readConfig {
182
   my $filename = shift;
182
   my $filename = shift;
183
   my $config;
183
   my $config;
184
   return $config unless -e $filename;
184
   return $config unless -e $filename;
185
   if ( open CONF,"<$filename" ) {
-
 
186
      my $contents = join( '', <CONF> );
-
 
187
      close CONF;
-
 
188
      # now, look to see what kind of file this is.
-
 
189
      if ( $contents =~ m/^---(\s*#.*)?$/m ) {
-
 
190
         print "Reading $filename as YAML\n";
-
 
191
         #print "Contents are:\n\n=====================$contents\n=====================\n";
-
 
192
         # this is a yaml file
-
 
193
         #$contents = YAML::Tiny->read( $config );
185
   my $yaml = YAML::Tiny->read( $filename );
194
         # try to load the contents into $config, and warn if there is a problem.
-
 
195
         eval( $config = Load( $contents ) ); warn $@ if $@;
-
 
196
      } elsif ( $contents =~ m/\$clientName/ ) {
-
 
197
         # this is old style
-
 
198
         print "Reading $filename as old school file\n";
-
 
199
         my $clientName = '';
-
 
200
         my $serialNumber = '';
-
 
201
         my $hostname = '';
-
 
202
         my @moduleDirs;
-
 
203
         my @scriptDirs;
-
 
204
         my $UUID = '';
-
 
205
         my $transports;
-
 
206
         # now, eval the information we just read.
-
 
207
         # NOTE: we must turn off strict while doing this, and we die if something breaks.
-
 
208
         no strict "vars";
-
 
209
         eval( $contents );
-
 
210
         use strict "vars";
-
 
211
         die "Error during eval: $@\n" if $@;
-
 
212
         $config->{'clientName'} = $clientName if $clientName;
-
 
213
         $config->{'serialNumber'} = $serialNumber if $serialNumber;
-
 
214
         $config->{'UUID'} = $UUID unless $config->{'UUID'};
-
 
215
         $config->{'hostname'} = $hostname if $hostname;
-
 
216
         $config->{'moduleDirs'} = [ @moduleDirs ] if @moduleDirs;
-
 
217
         $config->{'scriptDirs'} = [ @scriptDirs ] if @scriptDirs;
-
 
218
         $config->{'transports'} = $transports if $transports;
-
 
219
         foreach my $trans ( keys %{$config->{'transports'}} ) {
-
 
220
            if ( exists ( $config->{'transports'}->{$trans}->{'-name-'} ) ) {
-
 
221
               $config->{'transports'}->{$trans}->{'name'} = $config->{'transports'}->{$trans}->{'-name-'};
-
 
222
               delete( $config->{'transports'}->{$trans}->{'-name-'} );
-
 
223
            }
-
 
224
         }
-
 
225
      }
-
 
226
   } else {
-
 
227
         warn "Could not read config file $filename, skipped: $!\n";
-
 
228
   }
-
 
229
   return $config;
186
   return $yaml->[0];
230
}
187
}
231
 
188
 
232
sub makeConfig {
189
sub makeConfig {
233
   my @configFileNames = @_;
190
   my @configFileNames = @_;
234
   my %config;
191
   my %config;