- Timestamp:
- May 7, 2012, 4:44:13 AM (13 years ago)
- Location:
- devel
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb-modules/lib/ProjectBuilder/Conf.pm
r1156 r1495 24 24 25 25 our @ISA = qw(Exporter); 26 our @EXPORT = qw(pb_conf_init pb_conf_add pb_conf_read pb_conf_read_if pb_conf_get pb_conf_get_if );26 our @EXPORT = qw(pb_conf_init pb_conf_add pb_conf_read pb_conf_read_if pb_conf_get pb_conf_get_if pb_conf_print); 27 27 ($VERSION,$REVISION) = pb_version_init(); 28 28 … … 32 32 my %pbconffiles; 33 33 34 # Global hash of cached values. 34 # Global hash of conf file content 35 # Key is the config keyword 36 # Value is a hash whose key depends on the nature of the config keyword as documented 37 # and value is the confguration value 35 38 # We consider that values can not change during the life of pb 36 # my %cachedval;39 my $h = (); 37 40 38 41 =pod … … 72 75 my $proj=shift || undef; 73 76 77 pb_log(1,"Entering pb_conf_init\n"); 74 78 if (defined $proj) { 75 79 $ENV{'PBPROJ'} = $proj; … … 77 81 $ENV{'PBPROJ'} = "default"; 78 82 } 79 } 80 81 83 pb_log(1,"PBPROJ = $ENV{'PBPROJ'}\n"); 84 } 85 86 87 =item B<pb_conf_cache> 88 89 This function caches the configuration file content passed as first parameter into the a hash passed in second parameter 90 It returns the modified hash 91 Can be used in correlation with the %h hash to store permanently values or not if temporarily. 92 93 =cut 94 95 sub pb_conf_cache { 96 97 my $cf = shift; 98 my $lh = shift; 99 100 # Read the content of the config file and cache it in the %h hash further availble for queries 101 open(CONF,$cf) || die "Unable to open $cf"; 102 while(<CONF>) { 103 if (/^\s*([A-z0-9-_.]+)\s+([[A-z0-9-_.]+)\s*=\s*(.+)$/) { 104 pb_log(3,"DEBUG: 1:$1 2:$2 3:$3\n"); 105 $lh->{$1}->{$2}=$3; 106 } 107 } 108 close(CONF); 109 return($lh); 110 } 82 111 83 112 =item B<pb_conf_add> 84 113 85 This function adds the configuration file to the list last .114 This function adds the configuration file to the list last, and cache their content in the %h hash 86 115 87 116 =cut … … 90 119 91 120 pb_log(2,"DEBUG: pb_conf_add with ".Dumper(@_)."\n"); 121 my $lh; 92 122 93 123 foreach my $cf (@_) { 124 if (! -r $cf) { 125 pb_log(0,"WARNING: pb_conf_add can not read $cf\n"); 126 next; 127 } 94 128 # Skip already used conf files 95 next if (defined $pbconffiles{$cf}); 129 return($lh) if (defined $pbconffiles{$cf}); 130 96 131 # Add the new one at the end 97 132 my $num = keys %pbconffiles; 98 pb_log(2,"DEBUG: pb_conf_ add$cf at position $num\n");133 pb_log(2,"DEBUG: pb_conf_cache of $cf at position $num\n"); 99 134 $pbconffiles{$cf} = $num; 100 pb_log(0,"WARNING: pb_conf_add can not read $cf\n") if (! -r $cf); 101 } 102 } 135 136 # Read the content of the config file 137 $lh = pb_conf_cache($cf,$lh); 138 # and cache it in the %h hash for further queries but after the previous 139 # as we load conf files in reverse order (most precise first) 140 pb_conf_add_last_in_hash($lh) 141 } 142 } 143 103 144 104 145 =item B<pb_conf_read_if> … … 131 172 Valid chars for keys and tags are letters, numbers, '-' and '_'. 132 173 174 The file read is forgotten after its usage. If you want permanent caching of the data, use pb_conf_add then pb_conf_get 175 133 176 =cut 134 177 … … 153 196 my $conffile = shift; 154 197 my @param = @_; 155 my $trace;156 198 my @ptr; 157 my %h; 158 159 open(CONF,$conffile) || die "Unable to open $conffile"; 160 while(<CONF>) { 161 if (/^\s*([A-z0-9-_.]+)\s+([[A-z0-9-_.]+)\s*=\s*(.+)$/) { 162 pb_log(3,"DEBUG: 1:$1 2:$2 3:$3\n"); 163 $h{$1}{$2}=$3; 164 } 165 } 166 close(CONF); 167 168 for my $param (@param) { 169 push @ptr,$h{$param}; 199 my $lh; 200 201 $lh = pb_conf_cache($conffile,$lh); 202 203 foreach my $param (@param) { 204 push @ptr,$lh->{$param}; 170 205 } 171 206 return(@ptr); 172 207 } 173 208 209 210 211 =item B<pb_conf_get_in_hash_if> 212 213 This function returns a table, corresponding to a set of values queried in the hash passe in parameter or undef if it doen't exist. It takes a table of keys as an input parameter. 214 215 =cut 216 217 sub pb_conf_get_in_hash_if { 218 219 my $lh = shift || return(()); 220 my @params = @_; 221 my @ptr = (); 222 223 pb_log(2,"DEBUG: pb_conf_get_in_hash_if on params ".join(' ',@params)."\n"); 224 foreach my $k (@params) { 225 push @ptr,$lh->{$k}; 226 } 227 228 pb_log(2,"DEBUG: pb_conf_get_in_hash_if returns\n".Dumper(@ptr)); 229 return(@ptr); 230 } 231 232 233 174 234 =item B<pb_conf_get_if> 175 235 176 This function returns a table, corresponding to a set of values queried in the conf filesor undef if it doen't exist. It takes a table of keys as an input parameter.236 This function returns a table, corresponding to a set of values queried in the %h hash or undef if it doen't exist. It takes a table of keys as an input parameter. 177 237 178 238 The format of the configurations file is as follows: … … 180 240 key tag = value1,value2,... 181 241 182 It will gather the values from all the configurations files passed to pb_conf_add, and return the values for the keys , taking in account the order of conf files, to manage overloading.242 It will gather the values from all the configurations files passed to pb_conf_add, and return the values for the keys 183 243 184 244 $ cat $HOME/.pbrc … … 205 265 sub pb_conf_get_if { 206 266 207 my @param = @_; 208 209 my $ptr = undef; 210 211 # the most important conf file is first, so read them in reverse order 212 foreach my $f (reverse sort { $pbconffiles{$a} <=> $pbconffiles{$b} } keys %pbconffiles) { 213 pb_log(2,"DEBUG: pb_conf_get_if in file $f\n"); 214 $ptr = pb_conf_get_fromfile_if("$f",$ptr,@param); 215 } 216 217 return(@$ptr); 218 } 219 220 =item B<pb_conf_fromfile_if> 221 222 This function returns a pointer on a table, corresponding to a merge of values queried in the conf file and the pointer on another table passed as parameter. It takes a table of keys as last input parameter. 223 224 my ($k1) = pb_conf_fromfile_if("$HOME/.pbrc",undef,"pbver","pblist"); 225 my ($k2) = pb_conf_fromfile_if("$HOME/.pbrc3",$k1,"pbver","pblist"); 226 227 It is used internally by pb_conf_get_if and is not exported yet. 228 229 =cut 230 231 232 sub pb_conf_get_fromfile_if { 233 234 my $conffile = shift; 235 my $ptr2 = shift || undef; 236 my @param = @_; 237 238 # Everything is returned via ptr1 239 my @ptr1 = (); 240 my @ptr2 = (); 241 242 # @ptr1 contains the values overloading what @ptr2 may contain. 243 @ptr1 = pb_conf_read_if("$conffile", @param) if (defined $conffile); 244 @ptr2 = @$ptr2 if (defined $ptr2); 267 my @params = @_; 268 my @ptr = undef; 269 270 return(pb_conf_get_in_hash_if($h,@params)); 271 } 272 273 =item B<pb_conf_add_last_in_hash> 274 275 This function merges the values passed in the hash parameter into the %h hash, but only if itdoesn't already contain a value, or if the value is more precise (real value instead of default) 276 277 It is used internally by pb_conf_add and is not exported. 278 279 =cut 280 281 sub pb_conf_add_last_in_hash { 282 283 my $ptr = shift || undef; 284 285 return if (not defined $ptr); 286 # TODO: test $ptr is a hash pointer 287 288 my @params = (sort keys %$ptr); 289 290 # Everything is returned via @h 291 # @h contains the values overloading what @ptr may contain. 292 my @h = pb_conf_get_if(@params); 293 my @ptr = pb_conf_get_in_hash_if($ptr,@params); 245 294 246 295 my $p1; 247 296 my $p2; 248 297 249 pb_log(2,"DEBUG: pb_conf_get_from_file $conffile: ".Dumper(@ptr1)."\n"); 250 pb_log(2,"DEBUG: pb_conf_get_from_file input: ".Dumper(@ptr2)."\n"); 251 pb_log(2,"DEBUG: pb_conf_get_from_file param: ".Dumper(@param)."\n"); 252 253 foreach my $i (0..$#param) { 254 $p1 = $ptr1[$i]; 255 # Optimisation doesn't seem useful 256 # if ((defined $p1) && (defined $cachedval{$p1})) { 257 # $ptr1[$i] = $cachedval{$p1}; 258 # next; 259 # } 260 $p2 = $ptr2[$i]; 261 # Always try to take the param from ptr1 262 # in order to mask what could be defined already in ptr2 298 pb_log(2,"DEBUG: pb_conf_add_last_in_hash params: ".Dumper(@params)."\n"); 299 pb_log(2,"DEBUG: pb_conf_add_last_in_hash hash: ".Dumper(@h)."\n"); 300 pb_log(2,"DEBUG: pb_conf_add_last_in_hash input: ".Dumper(@ptr)."\n"); 301 302 foreach my $i (0..$#params) { 303 $p1 = $h[$i]; 304 $p2 = $ptr[$i]; 305 # Always try to take the param from h 306 # in order to mask what could be defined already in ptr 263 307 if (not defined $p2) { 264 308 # exit if no p1 either … … 294 338 } 295 339 } 296 $ptr1[$i] = $p1; 297 # Cache values to avoid redoing all that analyze when asked again on a known value 298 # $cachedval{$p1} = $p1; 299 } 300 pb_log(2,"DEBUG: pb_conf_get output: ".Dumper(@ptr1)."\n"); 301 return(\@ptr1); 340 $h->{$params[$i]} = $p1; 341 } 342 pb_log(2,"DEBUG: pb_conf_add_last_in_hash output: ".Dumper($h)."\n"); 302 343 } 303 344 … … 328 369 } 329 370 371 372 =item B<pb_conf_print> 373 374 This function prints every configuration parameter in order to help debug stacking issues with conf files 375 376 =cut 377 378 sub pb_conf_print { 379 380 pb_log(0,"Full pb configuration for project $ENV{'PBPROJ'}\n"); 381 pb_log(0,"====================================\n"); 382 foreach my $k (sort keys %$h) { 383 pb_log(0,"$k => ".Dumper($h->{$k})."\n"); 384 } 385 } 386 330 387 =back 331 388 -
devel/pb-modules/lib/ProjectBuilder/Env.pm
r1469 r1495 145 145 my $tag; 146 146 147 pb_conf_init($proj); 147 148 pb_env_init_pbrc(); 148 149 … … 151 152 # Could be with env var PBPROJ 152 153 # or option -p 153 # if not define take the first in conf file154 # if not defined take the first in conf file 154 155 # 155 156 if ((defined $ENV{'PBPROJ'}) && -
devel/pb/bin/pb
r1486 r1495 383 383 384 384 Create tar files for the website under your CMS. 385 386 =item B<getconf> 387 388 Print the full configuration parameters as found in the various configuration files. help to debug conf issues. 385 389 386 390 =item B<clean> … … 713 717 } elsif ($action =~ /^newproj$/) { 714 718 # Nothing to do - already done in pb_env_init 719 } elsif ($action =~ /^getconf$/) { 720 my $pbos = pb_distro_get_context(); 721 pb_conf_print(); 715 722 } elsif ($action =~ /^clean$/) { 716 723 pb_clean(); -
devel/pb/lib/ProjectBuilder/CMS.pm
r1487 r1495 158 158 my $ver = basename($dir); 159 159 my $msg = "updated to $ver"; 160 $msg = "Project $ENV{ PBPROJ} creation" if (defined $pbinit);160 $msg = "Project $ENV{'PBPROJ'} creation" if (defined $pbinit); 161 161 162 162 pb_vcs_checkin($scheme,$dir,$msg);
Note:
See TracChangeset
for help on using the changeset viewer.