Changeset 2239 in ProjectBuilder for devel/pb-modules/lib/ProjectBuilder/Conf.pm
- Timestamp:
- Jul 31, 2017, 1:25:12 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb-modules/lib/ProjectBuilder/Conf.pm
r2176 r2239 19 19 use ProjectBuilder::Base; 20 20 use ProjectBuilder::Version; 21 #use YAML;22 21 23 22 # Inherit from the "Exporter" module which handles exporting functions. 24 23 25 use vars qw($VERSION $REVISION @ISA @EXPORT);24 use vars qw($VERSION $REVISION $PBCONFVER @ISA @EXPORT); 26 25 use Exporter; 27 26 … … 31 30 our @ISA = qw(Exporter); 32 31 our @EXPORT = qw(pb_conf_init pb_conf_add pb_conf_read pb_conf_read_if pb_conf_write pb_conf_get pb_conf_get_if pb_conf_get_all pb_conf_get_hash pb_conf_cache); 33 ($VERSION,$REVISION ) = pb_version_init();32 ($VERSION,$REVISION,$PBCONFVER) = pb_version_init(); 34 33 35 34 # Global hash of conf files … … 70 69 to allow for overwrite to work: 71 70 72 1. /usr/share/pb/pb. conf- the read-only system conf file provided by install73 2. /etc/pb/pb. conf- the same global conf file given to the sysadmin in order to make system wide modifications71 1. /usr/share/pb/pb.yml - the read-only system conf file provided by install 72 2. /etc/pb/pb.yml - the same global conf file given to the sysadmin in order to make system wide modifications 74 73 3. /path/to/project.pb - Configuration file for the project we're building for 75 74 4. /(vm|ve|rm)path/to/.pbrc - configuration file for VM, VE or RM specific parameters. Cumulative should be orthogonal … … 124 123 my $cf = shift; 125 124 my $lh = shift; 126 my $confver = "0.14"; 125 126 my $ldfunc; 127 128 eval { 129 require YAML; 130 YAML->import(); 131 $ldfunc = \&YAML::LoadFile; 132 }; 133 if ($@) { 134 # No YAML found using a more std but less complete one. Old perl only 135 use Module::Build::YAML; 136 $ldfunc = \&Module::Build::YAML::LoadFile; 137 } 127 138 128 139 # Read the content of the config file and cache it in the %h hash then available for queries 129 if ($ confver < 0.15) {140 if ($PBCONFVER < 1) { 130 141 open(CONF,$cf) || confess "Unable to open $cf"; 131 142 # This is the original conf file format for versions up to 0.14 … … 139 150 close(CONF); 140 151 } else { 141 $lh = LoadFile($cf);152 $lh = $ldfunc->($cf); 142 153 } 143 154 return($lh); … … 251 262 my $conffile = shift; 252 263 my $h = shift; 253 my $confver = "0.14"; 264 my $dpfunc; 265 266 eval { 267 require YAML; 268 YAML->import(); 269 $dpfunc = \&YAML::Dump; 270 }; 271 if ($@) { 272 # No YAML found using a more std but less complete one. Old perl only 273 use Module::Build::YAML; 274 $dpfunc = \&Module::Build::YAML::Dump; 275 } 254 276 255 277 confess "No configuration file defined to write into !" if (not defined $conffile); … … 257 279 open(CONF,"> $conffile") || confess "Unable to write into $conffile"; 258 280 259 if ($ confver < 0.15) {281 if ($PBCONFVER < 1) { 260 282 # This is the original conf file format for versions up to 0.14 261 283 foreach my $p (sort keys %$h) { … … 267 289 } else { 268 290 # This is the new YAML format 269 print CONF Dump($h);291 print CONF $dpfunc->($h); 270 292 } 271 293 close(CONF);
Note:
See TracChangeset
for help on using the changeset viewer.