ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Configuration/ConfigArea.pm
(Generate patch)

Comparing COMP/SCRAM/src/Configuration/ConfigArea.pm (file contents):
Revision 1.8 by williamc, Thu Feb 10 10:59:44 2000 UTC vs.
Revision 1.24 by sashby, Wed Feb 2 11:10:17 2005 UTC

# Line 1 | Line 1
1   #
2   # ConfigArea.pm
3   #
4 < # Originally Written by Christopher Williams
4 > # Written by Christopher Williams
5   #
6   # Description
7 + # -----------
8 + # creates and manages a configuration area
9 + #
10 + # Notes
11 + # -------
12 + # Persistency - remember to call the save method to make changes persistent
13   #
14   # Interface
15   # ---------
16 < # new(ActiveConfig)             : A new ConfigArea object
17 < # setup()                       : setup the configuration area
18 < # location([dir])               : set/return the location of the area
19 < # version([version])            : set/return the version of the area
20 < # name([name])                  : set/return the name of the area
21 < # store(location)               : store data in file location
22 < # restore(location)             : restore data from file location
23 < # meta()                        : return a description string of the area
24 < # addconfigitem(url)            : add a new item to the area
25 < # configitem(@keys)             : return a list of fig items that match
20 < #                                 the keys - all if left blank
21 < # parentstore()                 : set/return the parent ObjectStore
22 < # bootstrapfromlocation([location]): bootstrap the object based on location.
23 < #                                 no location specified - cwd used
16 > # new()                         : A new ConfigArea object
17 > # name()                        : get/set project name
18 > # setup(dir[,areaname])         : setup a fresh area in dir
19 > # satellite(dir[,areaname])     : setup a satellite area in dir
20 > # version()                     : get/set project version
21 > # location([dir])               : set/return the location of the work area
22 > # bootstrapfromlocation([location]) : bootstrap the object based on location.
23 > #                                     no location specified - cwd used
24 > #                                     return 0 if succesful 1 otherwise
25 > # requirementsdoc()             : get set the requirements doc
26   # searchlocation([startdir])    : returns the location directory. search starts
27   #                                 from cwd if not specified
28 < # defaultdirname()              : return the default directory name string
29 < # copy(location)                : make a copy of the current area at the
30 < #                                 specified location - return an object
31 < #                                 representing the area
28 > # scramversion()                : return the scram version associated with
29 > #                                 area
30 > # configurationdir()            : return the location of the project
31 > #                                 configuration directory
32 > # copy(location)                : copy a configuration
33 > # copysetup(location)           : copy the architecture specific tool setup
34 > #                                 returns 0 if successful, 1 otherwise
35 > # copyenv($ref)                 : copy the areas environment into the hashref
36 > # toolbox()                     : return the areas toolbox object
37 > # save()                        : save changes permanently
38 > # linkto(location)              : link the current area to that at location
39 > # unlinkarea()                  : destroy link (autosave)
40 > # linkarea([ConfigArea])        : link the current area to the apec Area Object
41 > # archname()            : get/set a string to indicate architecture
42 > # archdir()             : return the location of the administration arch dep
43 > #                         directory
44 > # objectstore()         : return the objectStore object of the area
45 > # - temporary
46 > # align()                       : adjust hard paths to suit local loaction
47  
48   package Configuration::ConfigArea;
32 use ActiveDoc::ActiveDoc;
49   require 5.004;
50 + use URL::URLcache;
51   use Utilities::AddDir;
52 + use Utilities::Verbose;
53   use ObjectUtilities::ObjectStore;
36 use Configuration::ConfigStore;
54   use Cwd;
55 < @ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject);
39 <
40 < sub init {
41 <        my $self=shift;
55 > @ISA=qw(Utilities::Verbose);
56  
57 <        $self->newparse("init");
58 <        $self->newparse("download");
59 <        $self->newparse("setup");
60 <        $self->addtag("init","project",\&Project_Start,$self,
47 <            \&Project_text,$self,"", $self );
48 <        $self->addurltags("download");
49 <        $self->addtag("download","use",\&Use_download_Start,$self,
50 <                                                "", $self, "",$self);
51 <        $self->addurltags("setup");
52 <        $self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self);
57 > sub new {
58 >        my $class=shift;
59 >        my $self={};
60 >        bless $self, $class;
61  
62          # data init
63 <        $self->{admindir}=".SCRAM";
64 < }
65 <
66 <
67 < sub defaultdirname {
60 <        my $self=shift;
61 <        my $name=$self->name();
62 <        my $vers=$self->version();
63 <        $vers=~s/^$name_//;
64 <        $name=$name."_".$vers;
65 <        return $name;
63 >        $self->{admindir}=".SCRAM";
64 >        $self->{cachedir}="cache";
65 >        $self->{dbdir}="ObjectDB";
66 >        $self->{tbupdate}=0;
67 >        undef $self->{linkarea};
68  
69 +        return $self;
70   }
71  
72 < sub setup {
72 > sub cache {
73          my $self=shift;
74  
75 <        # --- find out the location - default is cwd
76 <        my $location=$self->option("area_location");
74 <        if ( ! defined $location ) {
75 <                $location=cwd();
75 >        if ( @_ ) {
76 >           $self->{cache}=shift;
77          }
78 <        elsif ( $location!~/^\// ) {
79 <                $location=cwd()."/".$location;
78 >        if ( ! defined $self->{cache} ) {
79 >          my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
80 >          if ( -e $loc  ) {
81 >            $self->{cache}=URL::URLcache->new($loc);
82 >          }
83 >          else {
84 >            $self->{cache}=undef;
85 >          }
86          }
87 +        return $self->{cache};
88 + }
89  
90 <        # --- find area directory name , default name projectname_version
91 <        my $name=$self->option("area_name");
92 <        if ( ! defined $name ) {
93 <          $name=$self->defaultdirname();
94 <        }
95 <        $self->location($location."/".$name);
90 > # Tool and project cache info:
91 > sub cacheinfo
92 >   {
93 >   my $self=shift;
94 >   print "\n","<ConfigArea> cacheinfo: ToolCache = ",$self->{toolcachefile},
95 >   ", ProjectCache = ",$self->{projectcachefile},"\n";
96 >   }
97  
98 <        # make a new store handler
99 <        $self->_setupstore();
98 > sub toolcachename
99 >   {
100 >   my $self=shift;
101 >   return ($self->location()."/".$self->{admindir}."/".$ENV{SCRAM_ARCH}."/ToolCache.db");
102 >   }
103  
104 <        # --- download everything first
105 < # FIX-ME --- cacheing is broken
106 <        $self->parse("download");
107 <        
108 <        # --- and parse the setup file
96 <        $self->parse("setup");
97 <        
98 <        # --- store bootstrap info
99 <        $self->store($self->location()."/".$self->{admindir}."/ConfigArea.dat");
104 > sub projectcachename
105 >   {
106 >   my $self=shift;
107 >   return ($self->location()."/".$self->{admindir}."/".$ENV{SCRAM_ARCH}."/ProjectCache.db");
108 >   }
109  
110 <        # --- store self in original database
111 <        $self->parentconfig()->store($self,"ConfigArea",$self->name(),
112 <                                                        $self->version());
110 > sub _tbupdate
111 >   {
112 >   # Update toolbox relative to new RequirementsDoc:
113 >   my $self=shift;
114 >   @_?$self->{tbupdate}=shift
115 >      :$self->{tbupdate};
116 >   }
117 >
118 > sub _newcache {
119 >        my $self=shift;
120 >        my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
121 >        $self->{cache}=URL::URLcache->new($loc);
122 >        return $self->{cache};
123   }
124  
125 < sub _setupstore {
125 > sub _newobjectstore {
126          my $self=shift;
127 +        my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
128 +        $self->{dbstore}=ObjectUtilities::ObjectStore->new($loc);
129 +        return $self->{dbstore};
130 + }
131  
132 <        # --- make a new ConfigStore at the location and add it to the db list
133 <        my $ad=Configuration::ConfigStore->new($self->location().
111 <                                "/".$self->{admindir});
132 > sub objectstore {
133 >        my $self=shift;
134  
135 <        $self->parentconfig($self->config());
136 < #        $self->config(Configuration::ConfigureStore->new());
137 < #        $self->config()->db("local",$ad);
138 < #        $self->config()->db("parent",$self->parentconfig());
139 < #        $self->config()->policy("cache","local");
140 <        $self->config($ad);
141 <        $self->config()->basedoc($self->parentconfig()->basedoc());
135 >        if ( @_ ) {
136 >            $self->{dbstore}=shift;
137 >        }
138 >        if ( ! defined $self->{dbstore} ) {
139 >          my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
140 >          if ( -e $loc ) {
141 >            $self->{dbstore}=ObjectUtilities::ObjectStore->new($loc);
142 >          }
143 >          else {
144 >            $self->{dbstore}=undef;
145 >          }
146 >        }
147 >        return $self->{dbstore}
148   }
149  
150 < sub bootstrapfromlocation {
150 > sub name {
151          my $self=shift;
152 <        
153 <        if ( ! defined $self->location(@_) ) {
126 <          $self->error("Unable to locate the top of local configuration area");
127 <        }
128 <        print "Found top ".$self->location()."\n";
129 <        $self->_setupstore();
130 <        $self->restore($self->location()."/".$self->{admindir}.
131 <                                                "/ConfigArea.dat");
152 >        @_?$self->{name}=shift
153 >          :$self->{name};
154   }
155  
156 < sub parentconfig {
156 > sub version {
157          my $self=shift;
158 <        @_?$self->{parentconfig}=shift
159 <          :$self->{parentconfig};
158 >        @_?$self->{version}=shift
159 >          :$self->{version};
160   }
161  
162 < sub store {
162 > sub setup {
163          my $self=shift;
164          my $location=shift;
165 +        my $areaname;
166 +
167 +        # -- check we have a project name and version
168 +        my $name=$self->name();
169 +        my $vers=$self->version();
170 +        
171 +        if ( ( ! defined $name ) && ( ! defined $version )) {
172 +          $self->error("Set ConfigArea name and version before setup");
173 +        }
174 +
175 +        # -- check arguments and set location
176 +        if ( ! defined $location ) {
177 +          $self->error("ConfigArea: Cannot setup new area without a location");
178 +        }
179 +        if ( @_ ) {
180 +          $areaname=shift;
181 +        }
182 +        if ( (! defined $areaname) || ( $areaname eq "" ) ) {
183 +          # -- make up a name from the project name and version
184 +          $vers=~s/^$name\_//;
185 +          $areaname=$name."_".$vers;
186 +        }
187 +        my $arealoc=$location."/".$areaname;
188 +        my $workloc=$arealoc."/".$self->{admindir};
189 +        $self->verbose("Building at $arealoc");
190 +        $self->location($arealoc);
191 +
192 +        # -- create top level structure and work area
193 +        AddDir::adddir($workloc);
194 +
195 +        # -- add a cache
196 +        $self->_newcache();
197 +
198 +        # -- add an Objectstore
199 +        $self->_newobjectstore();
200 +
201 +        # -- Save Environment File
202 +        $self->_SaveEnvFile();
203  
144        my $fh=$self->openfile(">".$location);
145        $self->savevar($fh,"location", $self->location());
146        $self->savevar($fh,"url", $self->url());
147        $self->savevar($fh,"name", $self->name());
148        $self->savevar($fh,"version", $self->version());
149        $fh->close();
204   }
205  
206 < sub copy {
206 > sub configurationdir {
207          my $self=shift;
208 <        my $destination=shift;
209 <        use File::Basename;
210 <        # create the area
208 >        if ( @_ ) {
209 >          $self->{configurationdir}=shift;
210 >        }
211 >        return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
212 > }
213  
214 <        AddDir::adddir(dirname($destination));
215 <        
216 <        $temp=$self->location();
217 <        my @cpcmd=(qw(cp -r), "$temp", "$destination");
218 <        print "@cpcmd"."\n";
219 < #       File::Copy::copy("$self->location()", "$destination") or
164 <        system(@cpcmd) == 0 or
165 <                        $self->error("Cannot copy ".$self->location().
166 <                        " to $destination ".$!);
167 <
168 <        # create a new object based on the new area
169 <        my $newarea=ref($self)->new($self->parentconfig());
170 <        $newarea->bootstrapfromlocation($destination);
171 <        # save it with the new location info
172 <        $newarea->store($self->location()."/".$self->{admindir}."/ConfigArea.dat");
214 > sub sourcedir {
215 >        my $self=shift;
216 >        if ( @_ ) {
217 >          $self->{sourcedir}=shift;
218 >        }
219 >        return (defined $self->{sourcedir})?$self->{sourcedir}:undef;
220   }
221  
222 < sub restore {
222 > sub toolbox {
223          my $self=shift;
224 <        my $location=shift;
224 >        if ( ! defined $self->{toolbox} ) {
225 >          $self->{toolbox}=BuildSystem::ToolBox->new($self, $ENV{SCRAM_ARCH});
226 >        }
227 >        return $self->{toolbox};
228 > }
229  
230 <        my $fh=$self->openfile("<".$location);
231 <        my $varhash={};
232 <        $self->restorevars($fh,$varhash);
233 <        if ( ! defined $self->location() ) {
234 <          $self->location($$varhash{"location"});
235 <        }
185 <        $self->_setupstore();
186 <        $self->url($$varhash{"url"});
187 <        $self->name($$varhash{"name"});
188 <        $self->version($$varhash{"version"});
189 <        $fh->close();
230 > sub toolboxversion {
231 >        my $self=shift;
232 >        if ( @_ ) {
233 >          $self->{toolboxversion}=shift;
234 >        }
235 >        return (defined $self->{toolboxversion})?$self->{toolboxversion}:undef;
236   }
237  
238 < sub name {
238 > sub requirementsdoc {
239          my $self=shift;
240 +        if ( @_ ) {
241 +          $self->{reqdoc}=shift;
242 +        }
243 +        if ( defined $self->{reqdoc} ) {
244 +          return $self->location()."/".$self->{reqdoc};
245 +        }
246 +        else {
247 +          return undef;
248 +        }
249 + }
250  
251 <        @_?$self->{name}=shift
252 <          :$self->{name};
251 > sub scramversion {
252 >        my $self=shift;
253 >        if ( ! defined $self->{scramversion} ) {
254 >          my $filename=$self->location()."/".$self->configurationdir()."/".
255 >                                                        "scram_version";
256 >          if ( -f $filename ) {
257 >            use FileHandle;
258 >            $fh=FileHandle->new();
259 >            open ($fh, "<".$filename);
260 >            my $version=<$fh>;
261 >            chomp $version;
262 >            $self->{scramversion}=$version;
263 >            undef $fh;
264 >          }
265 >        }
266 >        return $self->{scramversion};
267   }
268  
269 < sub version {
269 > sub sitename
270 >   {
271 >   ###############################################################
272 >   # sitename()                                                  #
273 >   ###############################################################
274 >   # modified : Mon Dec  3 15:45:35 2001 / SFA                   #
275 >   # params   :                                                  #
276 >   #          :                                                  #
277 >   #          :                                                  #
278 >   #          :                                                  #
279 >   # function : Read the site name from config/site/sitename and #
280 >   #          : export it.                                       #
281 >   #          :                                                  #
282 >   #          :                                                  #
283 >   ###############################################################
284 >   my $self = shift;
285 >   my $sitefile = $self->location()."/".$self->configurationdir()."/site/sitename";
286 >
287 >   $self->{sitename} = 'CERN'; # Use CERN as the default site name
288 >
289 >   use FileHandle;
290 >   my $sitefh = FileHandle->new();
291 >
292 >   # Be verbose and print file we're going to read:
293 >   $self->verbose(">> Going to try to get sitename from: ".$sitefile." ");
294 >  
295 >   # See if we can read from the file. If not, just
296 >   # use default site name:
297 >   open($sitefh,"<".$sitefile) ||
298 >      do
299 >         {
300 >         $self->verbose(">> Unable to read a site name definition file. Using \'CERN\' as the site name.");
301 >         return $self->{sitename};
302 >         };
303 >  
304 >   $sitename = <$sitefh>;
305 >   chomp($sitename);
306 >   $self->{sitename} = $sitename;
307 >  
308 >   # Close the file (be tidy!);
309 >   close($sitefile);
310 >   # Return:
311 >   return $self->{sitename};
312 >   }
313 >
314 >
315 > sub bootstrapfromlocation {
316          my $self=shift;
317  
318 <        @_?$self->{version}=shift
319 <          :$self->{version};
318 >        my $rv=0;
319 >        
320 >        my $location;
321 >        if ( ! defined ($location=$self->searchlocation(@_)) ) {
322 >         $rv=1;
323 >         $self->verbose("Unable to locate the top of local configuration area");
324 >        }
325 >        else {
326 >         $self->location($location);
327 >         $self->verbose("Found top ".$self->location());
328 >         $self->_LoadEnvFile();
329 >        }
330 >        return $rv;
331   }
332  
333   sub location {
# Line 211 | Line 338 | sub location {
338          }
339          elsif ( ! defined $self->{location} ) {
340            # try and find the release location
341 <          #$self->{location}=$self->searchlocation();
341 >          $self->{location}=$self->searchlocation();
342          }
343          return  $self->{location};
344   }
345  
346   sub searchlocation {
347          my $self=shift;
348 <
348 >        
349          #start search in current directory if not specified
350          my $thispath;
351 <        @_?$thispath=shift
352 <          :$thispath=cwd();
353 <
351 >        if ( @_ ) {
352 >          $thispath=shift
353 >        }
354 >        else {
355 >          $thispath=cwd();
356 >        }
357 >        
358          my $rv=0;
359  
360 +        # chop off any files - we only want dirs
361 +        if ( -f $thispath ) {
362 +          $thispath=~s/(.*)\/.*/$1/;
363 +        }
364          Sloop:{
365          do {
366 < #         print "Searching $thispath\n";
366 >          $self->verbose("Searching $thispath");
367            if ( -e "$thispath/".$self->{admindir} ) {
368 < #           print "Found\n";
368 >            $self->verbose("Found\n");
369              $rv=1;
370              last Sloop;
371            }
372          } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
373 <
373 >      
374          return $rv?$thispath:undef;
375   }
376  
377 < sub meta {
377 > sub archname {
378          my $self=shift;
379 +        if ( @_ ) {
380 +          $self->{archname}=shift;
381 +        }
382 +        return $self->{archname};
383 + }
384  
385 <        my $string=$self->name()." ".$self->version()." located at :\n  ".
386 <                $self->location;
385 > sub archdir {
386 >        my $self=shift;
387 >        if ( @_ ) {
388 >          $self->{archdir}=shift;
389 >        }
390 >        if ( ! defined $self->{archdir} ) {
391 >         if ( defined $self->{archname} ) {
392 >          $self->{archdir}=$self->location()."/".$self->{admindir}."/".
393 >                                                        $self->{archname};
394 >         }
395 >         else {
396 >          $self->error("ConfigArea : cannot create arch directory - ".
397 >                                                "architecture name not set")
398 >         }
399 >        }
400 >        return $self->{archdir};
401   }
402  
403 < sub configitem {
403 > sub satellite {
404          my $self=shift;
405 +
406 +        # -- create the sat object
407 +        my $sat=Configuration::ConfigArea->new();
408 +        $sat->name($self->name());
409 +        $sat->version($self->version());
410 +        $sat->requirementsdoc($self->{reqdoc});
411 +        $sat->configurationdir($self->configurationdir());
412 +        $sat->sourcedir($self->sourcedir());
413 +        $sat->toolboxversion($self->toolboxversion());
414 +        $sat->setup(@_);
415 +
416 +        # -- copy across the cache and ObjectStore
417 +        # -- make sure we dont try building new caches in release areas
418 +        my $rcache=$self->cache();
419 +        if ( defined $rcache ) {
420 +          copy($rcache->location(),$sat->cache()->location());
421 +        }
422 +
423 +        # -- make sure we dont try building new objectstores in release areas
424 +        my $rostore=$self->objectstore();
425 +        if ( defined $rostore ) {
426 +          copy($rostore->location(),$sat->objectstore()->location());
427 +        }
428 +
429 +        # and make sure in reinitialises
430 +        undef ($sat->{cache});
431 +
432 +        # -- link it to this area
433 +        $sat->linkarea($self);
434          
435 <        return ($self->config()->find("ConfigItem",@_));
435 >        # -- save it
436 >        $sat->save();
437 >
438 >        return $sat;
439   }
440  
441 < sub addconfigitem {
441 > sub copy {
442          my $self=shift;
443 <        my $url=shift;
443 >        my $destination=shift;
444  
445 <        my $docref=$self->activatedoc($url);
446 <        # Set up the document
447 <        $docref->setup();
448 <        $docref->save();
449 < #       $self->config()->storepolicy("local");
445 >        # copy across the admin dir
446 >        my $temp=$self->location()."/".$self->{admindir};
447 >        AddDir::copydir($temp,"$destination/".$self->{admindir});
448 > }
449 >
450 > sub align {
451 >        my $self=shift;
452 >        use File::Copy;
453 >
454 >        $self->_LoadEnvFile();
455 >        my $Envfile=$self->location()."/".$self->{admindir}."/Environment";
456 >        my $tmpEnvfile=$Envfile.".bak";
457 >        my $rel=$self->{ENV}{RELEASETOP};
458 >        my $local=$self->location();
459 >
460 >        rename( $Envfile, $tmpEnvfile );
461 >        use FileHandle;
462 >        my $fh=FileHandle->new();
463 >        my $fout=FileHandle->new();
464 >        open ( $fh, "<".$tmpEnvfile ) or
465 >                $self->error("Cannot find Environment file. Area Corrupted? ("
466 >                                .$self->location().")\n $!");
467 >        open ( $fout, ">".$Envfile ) or
468 >                $self->error("Cannot find Environment file. Area Corrupted? ("
469 >                                .$self->location().")\n $!");
470 >        while ( <$fh> ) {
471 >          $_=~s/\Q$rel\L/$local/g;
472 >          print $fout $_;
473 >        }
474 >        undef $fh;
475 >        undef $fout;
476   }
477  
478 < # -------------- Tags ---------------------------------
267 < # -- init parse
268 < sub Project_Start {
478 > sub copysetup {
479          my $self=shift;
480 <        my $name=shift;
481 <        my $hashref=shift;
480 >        my $dest=shift;
481 >        my $rv=1;
482 >        # copy across the admin dir
483 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
484 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
485 >        if ( $temp ne $temp2 ) {
486 >         if ( -d $temp ) {
487 >          AddDir::copydir($temp,$temp2);
488 >          $rv=0;
489 >         }
490 >        }
491 >        return $rv;
492 > }
493  
494 <        $self->checktag($name,$hashref,'name');
495 <        $self->checktag($name,$hashref,'version');
494 > sub copywithskip {
495 >        my $self=shift;
496 >        my $dest=shift;
497 >        my ($filetoskip)=@_;            
498 >        my $rv=1;
499 >        # copy across the admin dir
500 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
501 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
502 >        if ( $temp ne $temp2 ) {
503 >         if ( -d $temp ) {
504 >          AddDir::copydirwithskip($temp,$temp2,$filetoskip);
505 >          $rv=0;
506 >         }
507 >        }
508 >        return $rv;
509 > }
510  
511 <        $self->name($$hashref{'name'});
512 <        $self->version($$hashref{'version'});
511 > sub copyenv {
512 >        my $self=shift;
513 >        my $hashref=shift;
514 >        
515 >        foreach $elem ( keys %{$self->{ENV}} ) {
516 >           $$hashref{$elem}=$self->{ENV}{$elem};
517 >        }
518   }
519  
520 + sub arch {
521 +        my $self=shift;
522 +        return $ENV{SCRAM_ARCH};
523 + }
524  
525 < sub Project_text {
525 > sub linkto {
526          my $self=shift;
527 <        my $name=shift;
284 <        my $string=shift;
527 >        my $location=shift;
528  
529 <        print $string;
529 >        if ( -d $location ) {
530 >        my $area=Configuration::ConfigArea->new();
531 >        $area->bootstrapfromlocation($location);
532 >        $self->linkarea($area);
533 >        }
534 >        else {
535 >          $self->error("ConfigArea : Unable to link to non existing directory ".
536 >                         $location);
537 >        }
538   }
539  
540 < # ---- download parse
540 > sub unlinkarea {
541 >        my $self=shift;
542 >        undef $self->{linkarea};
543 >        $self->{linkarea}=undef;
544 >        $self->save();
545 > }
546  
547 < sub Use_download_Start {
547 > sub linkarea {
548          my $self=shift;
549 <        my $name=shift;
550 <        my $hashref=shift;
549 >        my $area=shift;
550 >        if ( defined $area ) {
551 >          $self->{linkarea}=$area;
552 >        }
553 >        return (defined $self->{linkarea} && $self->{linkarea} ne "")?
554 >                        $self->{linkarea}:undef;
555 > }
556  
557 <        $self->checktag($name,$hashref,'url');
558 <        print "Downloading .... ".$$hashref{'url'}."\n";
559 <        $self->getfile($$hashref{'url'});
557 > sub save {
558 >        my $self=shift;
559 >        $self->_SaveEnvFile();
560   }
561  
562 < # --- setup parse
562 > # ---- support routines
563  
564 < sub Use_Start {
564 > sub _SaveEnvFile {
565          my $self=shift;
566 <        my $name=shift;
567 <        my $hashref=shift;
566 >        use FileHandle;
567 >        my $fh=FileHandle->new();
568 >        open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
569 >                "Environment" ) or
570 >                $self->error("Cannot Open Environment file to Save ("
571 >                                .$self->location().")\n $!");
572          
573 <        $self->checktag($name,$hashref,'url');
574 <        $self->addconfigitem($$hashref{'url'});
573 >        print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
574 >        print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
575 >        print $fh "SCRAM_CONFIGDIR=".$self->configurationdir()."\n";
576 >        print $fh "SCRAM_SOURCEDIR=".$self->sourcedir()."\n";
577 >        print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n";
578 >        print $fh "SCRAM_TOOLBOXVERSION=".$self->{toolboxversion}."\n";
579 >        if ( defined $self->linkarea() ) {
580 >          my $area=$self->linkarea()->location();
581 >          if ( $area ne "" ) {
582 >          print $fh "RELEASETOP=".$area."\n";
583 >          }
584 >        }
585 >        undef $fh;
586   }
587  
588 +
589 + sub _LoadEnvFile
590 +   {
591 +   my $self=shift;
592 +
593 +   use FileHandle;
594 +   my $fh=FileHandle->new();
595 +   open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
596 +          "Environment" ) or
597 +          $self->error("Cannot find Environment file. Area Corrupted? ("
598 +                       .$self->location().")\n $!");
599 +   while ( <$fh> )
600 +      {
601 +      chomp;
602 +      next if /^#/;
603 +      next if /^\s*$/ ;
604 +      ($name, $value)=split /=/;
605 +      eval "\$self->{ENV}{${name}}=\"$value\"";
606 +      }
607 +   undef $fh;
608 +        
609 +   # -- set internal variables appropriately
610 +   if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} )
611 +      {
612 +      $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
613 +      }
614 +   if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} )
615 +      {
616 +      $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
617 +      }
618 +   if ( defined $self->{ENV}{"SCRAM_CONFIGDIR"} )
619 +      {
620 +      $self->configurationdir($self->{ENV}{"SCRAM_CONFIGDIR"});
621 +      }
622 +   if ( defined $self->{ENV}{"SCRAM_SOURCEDIR"} )
623 +      {
624 +      $self->sourcedir($self->{ENV}{"SCRAM_SOURCEDIR"});
625 +      }
626 +   if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} )
627 +      {
628 +      $self->requirementsdoc($self->{ENV}{"SCRAM_ProjReqsDoc"});
629 +      }
630 +   if ( defined $self->{ENV}{"SCRAM_TOOLBOXVERSION"} )
631 +      {
632 +      $self->toolboxversion($self->{ENV}{"SCRAM_TOOLBOXVERSION"});
633 +      }
634 +  
635 +   if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
636 +        ($self->{ENV}{"RELEASETOP"} ne $self->location()))
637 +      {
638 +      $self->linkto($self->{ENV}{"RELEASETOP"});
639 +      }
640 +   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines