ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Configuration/ConfigArea.pm
Revision: 1.35.2.2
Committed: Tue Feb 19 15:06:16 2008 UTC (17 years, 2 months ago) by muzaffar
Content type: text/plain
Branch: forBinLess_SCRAM
CVS Tags: V1_2_1b, V1_2_1a, V1_2_3, V1_2_2, V1_2_2_relcand2, V1_2_2_relcand1, V1_2_1, V1_2_0, V1_2_0-cand11, V1_2_0-cand10, V1_2_0-cand9, V1_2_0-cand8, V1_2_0-cand7, V1_2_0-cand6, V1_2_0-cand5, V1_2_0-cand4
Branch point for: SCRAM_V2_0
Changes since 1.35.2.1: +5 -5 lines
Log Message:
fully qualified packages names

File Contents

# User Rev Content
1 sashby 1.30 =head1 NAME
2    
3     Configuration::ConfigArea - Creates and manages a configuration area (i.e. a project area).
4    
5     =head1 SYNOPSIS
6    
7     my $obj = Configuration::ConfigArea->new();
8    
9     =head1 DESCRIPTION
10    
11     Create and manage SCRAM project configuration areas.
12    
13     =head1 METHODS
14    
15     =over
16    
17     =cut
18    
19     =item C<new()>
20    
21     Create a new Configuration::ConfigArea object.
22    
23     =item C<name()>
24    
25     Get/set project name.
26    
27     =item C<setup($dir[,$areaname])>
28    
29     Set up a fresh area in $dir.
30    
31     =item C<satellite($dir[,$areaname])>
32    
33     Set up a satellite area in $dir.
34    
35     =item C<version()>
36    
37     Get/set project version.
38    
39     =item C<location([$dir])>
40    
41     Set/return the location of the work area.
42    
43     =item C<bootstrapfromlocation([$location])>
44    
45     Bootstrap the object based on location.
46     No location specified - current directory used
47     Return 0 if succesful, 1 otherwise.
48    
49     =item C<requirementsdoc()>
50    
51     Get or set the requirements document.
52    
53     =item C<searchlocation([$startdir])>
54    
55     Returns the location directory. search starts
56     from current directory if not specified.
57    
58     =item C<scramversion()>
59    
60     Return the scram version associated with the area.
61    
62     =item C<configurationdir()>
63    
64     Return the location of the project configuration directory.
65    
66     =item C<copy($location)>
67    
68     Copy a configuration from $location.
69    
70     =item C<copysetup($location)>
71    
72     Copy the architecture-specific tool setup.
73     Returns 0 if successful, 1 otherwise.
74    
75     =item C<copyenv($ref)>
76    
77     Copy the area environment into the hashref $ref.
78    
79     =item C<toolbox()>
80    
81     Return the area toolbox object.
82    
83     =item C<save()>
84    
85     Save changes permanently.
86    
87     =item C<linkto($location)>
88    
89     Link the current area to that at location.
90    
91     =item C<unlinkarea()>
92    
93     Destroy link ($autosave).
94    
95     =item C<linkarea([Configuration::ConfigArea])>
96    
97     Link the current area to the specified area object.
98    
99     =item C<archname()>
100    
101     Get/set a string to indicate architecture.
102    
103     =item C<archdir()>
104    
105     Return the location of the administration
106     architecture-dependent directory.
107    
108     =item C<objectstore()>
109    
110     Return the B<objectStore> object of the area temporary.
111    
112     =item C<align()>
113    
114     Adjust hard paths to suit local location.
115    
116    
117     =back
118    
119     =head1 AUTHOR
120    
121     Originally written by Christopher Williams.
122    
123     =head1 MAINTAINER
124    
125     Shaun ASHBY
126    
127     =cut
128 williamc 1.1
129     package Configuration::ConfigArea;
130     require 5.004;
131 williamc 1.14 use URL::URLcache;
132 williamc 1.1 use Utilities::AddDir;
133 williamc 1.14 use Utilities::Verbose;
134 williamc 1.1 use ObjectUtilities::ObjectStore;
135 williamc 1.6 use Cwd;
136 williamc 1.14 @ISA=qw(Utilities::Verbose);
137 williamc 1.1
138 williamc 1.14 sub new {
139 muzaffar 1.33 my $class=shift;
140     my $self={};
141     bless $self, $class;
142    
143     # data init
144     $self->{admindir}=".SCRAM";
145     $self->{cachedir}="cache";
146     $self->{dbdir}="ObjectDB";
147     $self->{tbupdate}=0;
148     undef $self->{linkarea};
149    
150     return $self;
151 williamc 1.1 }
152    
153 williamc 1.14 sub cache {
154 muzaffar 1.33 my $self=shift;
155    
156     if ( @_ ) {
157     $self->{cache}=shift;
158     }
159     if ( ! defined $self->{cache} ) {
160     my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
161     if ( -e $loc ) {
162 sashby 1.32 $self->{cache}=URL::URLcache->new($loc);
163 muzaffar 1.33 }
164     else {
165 williamc 1.19 $self->{cache}=undef;
166 muzaffar 1.33 }
167 williamc 1.19 }
168 muzaffar 1.33 return $self->{cache};
169 williamc 1.14 }
170 williamc 1.9
171 sashby 1.23 # Tool and project cache info:
172     sub cacheinfo
173     {
174     my $self=shift;
175     print "\n","<ConfigArea> cacheinfo: ToolCache = ",$self->{toolcachefile},
176     ", ProjectCache = ",$self->{projectcachefile},"\n";
177     }
178    
179     sub toolcachename
180     {
181     my $self=shift;
182     return ($self->location()."/".$self->{admindir}."/".$ENV{SCRAM_ARCH}."/ToolCache.db");
183     }
184    
185     sub projectcachename
186     {
187     my $self=shift;
188     return ($self->location()."/".$self->{admindir}."/".$ENV{SCRAM_ARCH}."/ProjectCache.db");
189     }
190    
191     sub _tbupdate
192     {
193     # Update toolbox relative to new RequirementsDoc:
194     my $self=shift;
195     @_?$self->{tbupdate}=shift
196     :$self->{tbupdate};
197     }
198    
199 williamc 1.18 sub _newcache {
200 williamc 1.19 my $self=shift;
201     my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
202     $self->{cache}=URL::URLcache->new($loc);
203     return $self->{cache};
204 williamc 1.18 }
205    
206     sub _newobjectstore {
207 williamc 1.19 my $self=shift;
208     my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
209     $self->{dbstore}=ObjectUtilities::ObjectStore->new($loc);
210     return $self->{dbstore};
211     }
212 williamc 1.18
213 williamc 1.14 sub objectstore {
214 williamc 1.19 my $self=shift;
215 williamc 1.16
216 williamc 1.19 if ( @_ ) {
217     $self->{dbstore}=shift;
218     }
219     if ( ! defined $self->{dbstore} ) {
220     my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
221     if ( -e $loc ) {
222     $self->{dbstore}=ObjectUtilities::ObjectStore->new($loc);
223     }
224     else {
225     $self->{dbstore}=undef;
226     }
227     }
228     return $self->{dbstore}
229 williamc 1.9 }
230    
231 muzaffar 1.34 sub symlinks {
232     my $self=shift;
233     if (@_) {$self->{symlinks}=shift;}
234     return $self->{symlinks};
235     }
236    
237 williamc 1.14 sub name {
238 williamc 1.9 my $self=shift;
239 williamc 1.14 @_?$self->{name}=shift
240     :$self->{name};
241 williamc 1.9 }
242 williamc 1.7
243 williamc 1.14 sub version {
244 williamc 1.6 my $self=shift;
245 williamc 1.14 @_?$self->{version}=shift
246     :$self->{version};
247 williamc 1.9 }
248 williamc 1.8
249 williamc 1.1 sub setup {
250     my $self=shift;
251 williamc 1.14 my $location=shift;
252     my $areaname;
253 muzaffar 1.34 my $symlinks=0;
254 williamc 1.1
255 williamc 1.14 # -- check we have a project name and version
256     my $name=$self->name();
257     my $vers=$self->version();
258 sashby 1.23
259 williamc 1.14 if ( ( ! defined $name ) && ( ! defined $version )) {
260     $self->error("Set ConfigArea name and version before setup");
261     }
262    
263     # -- check arguments and set location
264 williamc 1.7 if ( ! defined $location ) {
265 williamc 1.14 $self->error("ConfigArea: Cannot setup new area without a location");
266 williamc 1.7 }
267 williamc 1.14 if ( @_ ) {
268     $areaname=shift;
269 williamc 1.6 }
270 muzaffar 1.34 if ( @_ ) {
271     $symlinks=shift || 0;
272     }
273 williamc 1.14 if ( (! defined $areaname) || ( $areaname eq "" ) ) {
274 muzaffar 1.35 $areaname=$vers;
275 williamc 1.1 }
276 williamc 1.14 my $arealoc=$location."/".$areaname;
277     my $workloc=$arealoc."/".$self->{admindir};
278     $self->verbose("Building at $arealoc");
279     $self->location($arealoc);
280 muzaffar 1.34 $self->symlinks($symlinks);
281 williamc 1.1
282 williamc 1.14 # -- create top level structure and work area
283 muzaffar 1.35.2.2 Utilities::AddDir::adddir($workloc);
284 williamc 1.1
285 williamc 1.14 # -- add a cache
286 williamc 1.18 $self->_newcache();
287    
288 williamc 1.19 # -- add an Objectstore
289     $self->_newobjectstore();
290 williamc 1.5
291 williamc 1.14 # -- Save Environment File
292     $self->_SaveEnvFile();
293 williamc 1.3
294 williamc 1.9 }
295    
296 williamc 1.14 sub configurationdir {
297 williamc 1.9 my $self=shift;
298 williamc 1.14 if ( @_ ) {
299     $self->{configurationdir}=shift;
300     }
301     return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
302 williamc 1.9 }
303    
304 sashby 1.23 sub sourcedir {
305     my $self=shift;
306     if ( @_ ) {
307     $self->{sourcedir}=shift;
308     }
309     return (defined $self->{sourcedir})?$self->{sourcedir}:undef;
310     }
311    
312 williamc 1.14 sub toolbox {
313 williamc 1.3 my $self=shift;
314 williamc 1.14 if ( ! defined $self->{toolbox} ) {
315 williamc 1.19 $self->{toolbox}=BuildSystem::ToolBox->new($self, $ENV{SCRAM_ARCH});
316 williamc 1.14 }
317     return $self->{toolbox};
318 williamc 1.4 }
319    
320 sashby 1.23 sub toolboxversion {
321     my $self=shift;
322     if ( @_ ) {
323     $self->{toolboxversion}=shift;
324     }
325     return (defined $self->{toolboxversion})?$self->{toolboxversion}:undef;
326     }
327    
328 williamc 1.14 sub requirementsdoc {
329 williamc 1.5 my $self=shift;
330 williamc 1.14 if ( @_ ) {
331     $self->{reqdoc}=shift;
332     }
333     if ( defined $self->{reqdoc} ) {
334     return $self->location()."/".$self->{reqdoc};
335 williamc 1.12 }
336     else {
337 williamc 1.14 return undef;
338 williamc 1.12 }
339 williamc 1.5 }
340    
341 williamc 1.14 sub scramversion {
342 williamc 1.4 my $self=shift;
343 williamc 1.14 if ( ! defined $self->{scramversion} ) {
344     my $filename=$self->location()."/".$self->configurationdir()."/".
345     "scram_version";
346     if ( -f $filename ) {
347     use FileHandle;
348     $fh=FileHandle->new();
349     open ($fh, "<".$filename);
350     my $version=<$fh>;
351     chomp $version;
352     $self->{scramversion}=$version;
353     undef $fh;
354     }
355     }
356     return $self->{scramversion};
357 williamc 1.1 }
358    
359 sashby 1.29 sub admindir()
360     {
361     my $self=shift;
362    
363     @_ ? $self->{admindir} = shift
364     : $self->{admindir};
365     }
366 sashby 1.21
367 williamc 1.14 sub bootstrapfromlocation {
368 williamc 1.1 my $self=shift;
369    
370 williamc 1.14 my $rv=0;
371    
372     my $location;
373     if ( ! defined ($location=$self->searchlocation(@_)) ) {
374     $rv=1;
375     $self->verbose("Unable to locate the top of local configuration area");
376 williamc 1.9 }
377     else {
378 williamc 1.14 $self->location($location);
379     $self->verbose("Found top ".$self->location());
380     $self->_LoadEnvFile();
381 williamc 1.9 }
382 williamc 1.14 return $rv;
383 williamc 1.1 }
384    
385     sub location {
386     my $self=shift;
387    
388 williamc 1.5 if ( @_ ) {
389 williamc 1.6 $self->{location}=shift;
390 williamc 1.5 }
391     elsif ( ! defined $self->{location} ) {
392     # try and find the release location
393 williamc 1.9 $self->{location}=$self->searchlocation();
394 williamc 1.5 }
395     return $self->{location};
396     }
397    
398     sub searchlocation {
399     my $self=shift;
400 sashby 1.20
401 williamc 1.5 #start search in current directory if not specified
402     my $thispath;
403 williamc 1.14 if ( @_ ) {
404     $thispath=shift
405     }
406     else {
407     $thispath=cwd();
408     }
409 sashby 1.20
410 williamc 1.5 my $rv=0;
411    
412 williamc 1.14 # chop off any files - we only want dirs
413     if ( -f $thispath ) {
414     $thispath=~s/(.*)\/.*/$1/;
415     }
416 williamc 1.6 Sloop:{
417     do {
418 williamc 1.14 $self->verbose("Searching $thispath");
419 williamc 1.8 if ( -e "$thispath/".$self->{admindir} ) {
420 williamc 1.14 $self->verbose("Found\n");
421 williamc 1.5 $rv=1;
422 williamc 1.6 last Sloop;
423 williamc 1.5 }
424 williamc 1.6 } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
425 sashby 1.20
426 williamc 1.5 return $rv?$thispath:undef;
427 williamc 1.1 }
428    
429 williamc 1.14 sub archname {
430 williamc 1.1 my $self=shift;
431 williamc 1.14 if ( @_ ) {
432     $self->{archname}=shift;
433     }
434     return $self->{archname};
435     }
436 williamc 1.1
437 williamc 1.14 sub archdir {
438     my $self=shift;
439     if ( @_ ) {
440     $self->{archdir}=shift;
441     }
442     if ( ! defined $self->{archdir} ) {
443     if ( defined $self->{archname} ) {
444     $self->{archdir}=$self->location()."/".$self->{admindir}."/".
445     $self->{archname};
446     }
447     else {
448     $self->error("ConfigArea : cannot create arch directory - ".
449     "architecture name not set")
450     }
451     }
452     return $self->{archdir};
453 williamc 1.1 }
454    
455 williamc 1.14 sub satellite {
456 williamc 1.1 my $self=shift;
457 williamc 1.14
458     # -- create the sat object
459     my $sat=Configuration::ConfigArea->new();
460     $sat->name($self->name());
461     $sat->version($self->version());
462     $sat->requirementsdoc($self->{reqdoc});
463     $sat->configurationdir($self->configurationdir());
464 sashby 1.23 $sat->sourcedir($self->sourcedir());
465     $sat->toolboxversion($self->toolboxversion());
466 williamc 1.14 $sat->setup(@_);
467    
468     # -- copy across the cache and ObjectStore
469 williamc 1.16 # -- make sure we dont try building new caches in release areas
470 williamc 1.18 my $rcache=$self->cache();
471 williamc 1.16 if ( defined $rcache ) {
472     copy($rcache->location(),$sat->cache()->location());
473     }
474    
475     # -- make sure we dont try building new objectstores in release areas
476 williamc 1.18 my $rostore=$self->objectstore();
477 williamc 1.16 if ( defined $rostore ) {
478     copy($rostore->location(),$sat->objectstore()->location());
479     }
480 williamc 1.14
481     # and make sure in reinitialises
482     undef ($sat->{cache});
483    
484     # -- link it to this area
485     $sat->linkarea($self);
486 williamc 1.1
487 williamc 1.14 # -- save it
488     $sat->save();
489    
490     return $sat;
491 williamc 1.1 }
492    
493 williamc 1.14 sub copy {
494 williamc 1.1 my $self=shift;
495 williamc 1.14 my $destination=shift;
496 williamc 1.1
497 williamc 1.14 # copy across the admin dir
498     my $temp=$self->location()."/".$self->{admindir};
499 muzaffar 1.35.2.2 Utilities::AddDir::copydir($temp,"$destination/".$self->{admindir});
500 williamc 1.13 }
501    
502 williamc 1.14 sub align {
503 williamc 1.13 my $self=shift;
504 williamc 1.14 use File::Copy;
505    
506     $self->_LoadEnvFile();
507     my $Envfile=$self->location()."/".$self->{admindir}."/Environment";
508     my $tmpEnvfile=$Envfile.".bak";
509     my $rel=$self->{ENV}{RELEASETOP};
510     my $local=$self->location();
511    
512     rename( $Envfile, $tmpEnvfile );
513     use FileHandle;
514     my $fh=FileHandle->new();
515     my $fout=FileHandle->new();
516     open ( $fh, "<".$tmpEnvfile ) or
517     $self->error("Cannot find Environment file. Area Corrupted? ("
518     .$self->location().")\n $!");
519     open ( $fout, ">".$Envfile ) or
520     $self->error("Cannot find Environment file. Area Corrupted? ("
521     .$self->location().")\n $!");
522     while ( <$fh> ) {
523     $_=~s/\Q$rel\L/$local/g;
524     print $fout $_;
525     }
526     undef $fh;
527     undef $fout;
528 williamc 1.1 }
529    
530 williamc 1.14 sub copysetup {
531 williamc 1.9 my $self=shift;
532 sashby 1.24 my $dest=shift;
533     my $rv=1;
534     # copy across the admin dir
535     my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
536     my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
537     if ( $temp ne $temp2 ) {
538     if ( -d $temp ) {
539 muzaffar 1.35.2.2 Utilities::AddDir::copydir($temp,$temp2);
540 sashby 1.24 $rv=0;
541     }
542     }
543     return $rv;
544     }
545    
546 sashby 1.26 sub copyurlcache {
547     my $self=shift;
548     my $dest=shift;
549     my $rv=1;
550     # copy across the admin dir
551     my $temp=$self->location()."/".$self->{admindir}."/cache";
552     my $temp2=$dest."/".$self->{admindir}."/cache";
553     if ( $temp ne $temp2 ) {
554     if ( -d $temp ) {
555 muzaffar 1.35.2.2 Utilities::AddDir::copydir($temp,$temp2);
556 sashby 1.26 $rv=0;
557     }
558     }
559     return $rv;
560     }
561    
562 sashby 1.24 sub copywithskip {
563     my $self=shift;
564 williamc 1.14 my $dest=shift;
565 muzaffar 1.33 my $filetoskip=shift || [];
566 williamc 1.14 my $rv=1;
567     # copy across the admin dir
568     my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
569     my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
570     if ( $temp ne $temp2 ) {
571     if ( -d $temp ) {
572 muzaffar 1.33 my $fs=[];
573     foreach my $f (@$filetoskip) {push @$fs,"${temp}/${f}";}
574 muzaffar 1.35.2.2 Utilities::AddDir::copydirwithskip($temp,$temp2,$fs);
575 williamc 1.14 $rv=0;
576     }
577 williamc 1.9 }
578 williamc 1.14 return $rv;
579 williamc 1.9 }
580    
581 williamc 1.14 sub copyenv {
582 williamc 1.9 my $self=shift;
583 williamc 1.14 my $hashref=shift;
584    
585     foreach $elem ( keys %{$self->{ENV}} ) {
586     $$hashref{$elem}=$self->{ENV}{$elem};
587 williamc 1.9 }
588     }
589    
590 williamc 1.14 sub arch {
591 williamc 1.9 my $self=shift;
592 williamc 1.14 return $ENV{SCRAM_ARCH};
593 williamc 1.9 }
594    
595 williamc 1.14 sub linkto {
596 williamc 1.9 my $self=shift;
597 williamc 1.14 my $location=shift;
598 sashby 1.23
599 williamc 1.14 if ( -d $location ) {
600     my $area=Configuration::ConfigArea->new();
601     $area->bootstrapfromlocation($location);
602     $self->linkarea($area);
603     }
604     else {
605     $self->error("ConfigArea : Unable to link to non existing directory ".
606     $location);
607 williamc 1.9 }
608     }
609    
610 williamc 1.14 sub unlinkarea {
611 williamc 1.9 my $self=shift;
612 williamc 1.14 undef $self->{linkarea};
613     $self->{linkarea}=undef;
614     $self->save();
615     }
616 williamc 1.9
617 williamc 1.14 sub linkarea {
618 williamc 1.1 my $self=shift;
619 williamc 1.14 my $area=shift;
620     if ( defined $area ) {
621     $self->{linkarea}=$area;
622     }
623     return (defined $self->{linkarea} && $self->{linkarea} ne "")?
624     $self->{linkarea}:undef;
625 williamc 1.1 }
626    
627 williamc 1.14 sub save {
628 williamc 1.1 my $self=shift;
629 williamc 1.14 $self->_SaveEnvFile();
630 williamc 1.1 }
631    
632 sashby 1.27 sub reqdoc()
633     {
634     my $self=shift;
635     my ($path)=@_;
636     return $path."/".$self->{reqdoc};
637     }
638    
639     sub creationtime()
640     {
641     my $self=shift;
642     my ($location)= @_;
643     $location||=$self->location();
644     my $requirementsdoc = $self->reqdoc($location);
645     my ($mode, $time) = (stat($requirementsdoc))[2, 9];
646     my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
647    
648     ($sec < 10) ? ($sec = "0".$sec) : $sec;
649     ($min < 10) ? ($min = "0".$min) : $min;
650    
651     $year += 1900;
652     my $months =
653     {
654     0 => "Jan", 1 => "Feb",
655     2 => "Mar", 3 => "Apr",
656     4 => "May", 5 => "Jun",
657     6 => "Jul", 7 => "Aug",
658     8 => "Sept", 9 => "Oct",
659     10 => "Nov", 11 => "Dec" };
660    
661     my $days = { 1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat", 7 => "Sun"};
662    
663     # Return the timestamp (as string) of the requirementsdoc:
664     return $days->{$wday}."-".$mday."-".$months->{$mon}."-".$year." ".$hour.":".$min.":".$sec;
665     }
666    
667 williamc 1.14 # ---- support routines
668 williamc 1.1
669 sashby 1.25 sub _SaveEnvFile
670     {
671     my $self=shift;
672     my $filemode = 0644;
673    
674     use FileHandle;
675     my $fh=FileHandle->new();
676     open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
677     "Environment" ) or
678     $self->error("Cannot Open Environment file to Save ("
679     .$self->location().")\n $!");
680 williamc 1.14
681 sashby 1.25 print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
682     print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
683     print $fh "SCRAM_CONFIGDIR=".$self->configurationdir()."\n";
684     print $fh "SCRAM_SOURCEDIR=".$self->sourcedir()."\n";
685     print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n";
686     print $fh "SCRAM_TOOLBOXVERSION=".$self->{toolboxversion}."\n";
687 muzaffar 1.34 print $fh "SCRAM_SYMLINKS=",$self->{symlinks},"\n";
688 williamc 1.9
689 sashby 1.25 if ( defined $self->linkarea() )
690     {
691     my $area=$self->linkarea()->location();
692     if ( $area ne "" )
693     {
694     print $fh "RELEASETOP=".$area."\n";
695     }
696     }
697    
698     undef $fh;
699    
700 sashby 1.31 # Repeat the exercise to save as XML:
701     my $fh=FileHandle->new();
702     open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
703     "Environment.xml" ) or
704     $self->error("Cannot Open Environment.xml file to Save ("
705     .$self->location().")\n $!");
706     print $fh "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
707     print $fh "<doc type=\"Configuration::ProjectEnvironment\" version=\"1.0\">\n";
708     print $fh " <environment SCRAM_PROJECTNAME=\"".$self->name()."\"/>\n";
709     print $fh " <environment SCRAM_PROJECTVERSION=\"".$self->version()."\"/>\n";
710     print $fh " <environment SCRAM_CONFIGDIR=\"".$self->configurationdir()."\"/>\n";
711     print $fh " <environment SCRAM_SOURCEDIR=\"".$self->sourcedir()."\"/>\n";
712     print $fh " <environment SCRAM_ProjReqsDoc=\"".$self->{reqdoc}."\"/>\n";
713     print $fh " <environment SCRAM_TOOLBOXVERSION=\"".$self->{toolboxversion}."\"/>\n";
714 muzaffar 1.34 print $fh "<environment SCRAM_SYMLINKS=\"",$self->{symlinks},"\"/>\n";
715 sashby 1.31
716     if ( defined $self->linkarea() )
717     {
718     my $area=$self->linkarea()->location();
719     if ( $area ne "" )
720     {
721     print $fh " <environment RELEASETOP=\"".$area."\"/>\n";
722     }
723     }
724    
725     print $fh "</doc>\n";
726     undef $fh;
727    
728 sashby 1.25 # Set the default permissions (-rw-r--r--):
729     chmod $filemode, $self->location()."/".$self->{admindir}."/Environment";
730 sashby 1.31 chmod $filemode, $self->location()."/".$self->{admindir}."/Environment.xml";
731 sashby 1.25 }
732 williamc 1.1
733 sashby 1.23 sub _LoadEnvFile
734     {
735     my $self=shift;
736 williamc 1.9
737 sashby 1.23 use FileHandle;
738     my $fh=FileHandle->new();
739     open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
740     "Environment" ) or
741     $self->error("Cannot find Environment file. Area Corrupted? ("
742     .$self->location().")\n $!");
743     while ( <$fh> )
744     {
745     chomp;
746     next if /^#/;
747     next if /^\s*$/ ;
748     ($name, $value)=split /=/;
749     eval "\$self->{ENV}{${name}}=\"$value\"";
750     }
751     undef $fh;
752 williamc 1.14
753 sashby 1.23 # -- set internal variables appropriately
754     if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} )
755     {
756     $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
757     }
758     if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} )
759     {
760     $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
761     }
762     if ( defined $self->{ENV}{"SCRAM_CONFIGDIR"} )
763     {
764     $self->configurationdir($self->{ENV}{"SCRAM_CONFIGDIR"});
765     }
766     if ( defined $self->{ENV}{"SCRAM_SOURCEDIR"} )
767     {
768     $self->sourcedir($self->{ENV}{"SCRAM_SOURCEDIR"});
769     }
770     if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} )
771     {
772     $self->requirementsdoc($self->{ENV}{"SCRAM_ProjReqsDoc"});
773     }
774     if ( defined $self->{ENV}{"SCRAM_TOOLBOXVERSION"} )
775     {
776 sashby 1.28 if ($self->{ENV}{"SCRAM_TOOLBOXVERSION"} eq '')
777     {
778     $self->toolboxversion("STANDALONE");
779     }
780     else
781     {
782     $self->toolboxversion($self->{ENV}{"SCRAM_TOOLBOXVERSION"});
783     }
784 sashby 1.23 }
785    
786     if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
787     ($self->{ENV}{"RELEASETOP"} ne $self->location()))
788     {
789     $self->linkto($self->{ENV}{"RELEASETOP"});
790     }
791     }