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.11 by williamc, Thu Feb 24 14:24:29 2000 UTC vs.
Revision 1.13.2.6.2.7.2.1 by williamc, Thu Sep 21 12:44:42 2000 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 < # Options
10 > # Notes
11   # -------
12 < # ConfigArea_location
13 < # ConfigArea_name
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
27 < #                                 the keys - all if left blank
28 < # parentstore()                 : set/return the parent ObjectStore
29 < # basearea(ConfigArea)          : Set/Get the base area
30 < # freebase()                    : Remove any link to a base area
31 < # bootstrapfromlocation([location]): bootstrap the object based on location.
32 < #                                 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 - defaults to cwd/default
31 < #                                 if not specified . ConfigArea_name,
32 < #                                 ConfigArea_location also override .
33 < #                                 Return an object representing the area
34 < # satellite()                   : make a satellite area based on $self
35 < # arch([archobj])               : Set/get the architecture object
36 < # structure(name)               : return the object corresponding to the
37 < #                                 structure name
38 < # structurelist()               : return list of structure objectS
39 < # downloadtotop(dir,url)        : download the url to a dir in the config area
40 < #                                
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;
50 use ActiveDoc::ActiveDoc;
49   require 5.004;
50 + use URL::URLcache;
51   use Utilities::AddDir;
52 + use Utilities::Verbose;
53   use ObjectUtilities::ObjectStore;
54 use Configuration::ConfigStore;
55 use Configuration::ActiveDoc_arch;
54   use Cwd;
55 < @ISA=qw(Configuration::ActiveDoc_arch ObjectUtilities::StorableObject);
55 > @ISA=qw(Utilities::Verbose);
56  
57 < sub init {
58 <        my $self=shift;
59 <
60 <        $self->newparse("init");
63 <        $self->newparse("download");
64 <        $self->newparse("setup");
65 <        $self->newparse("setup_tools");
66 <        $self->addarchtags("setup_tools");
67 <        $self->addarchtags("setup");
68 <        $self->addtag("init","project",\&Project_Start,$self,
69 <            \&Project_text,$self,"", $self );
70 <        $self->addurltags("download");
71 <        $self->addtag("download","download",\&Download_Start,$self,
72 <                                                "", $self, "",$self);
73 <        $self->addtag("download","use",\&Use_download_Start,$self,
74 <                                                "", $self, "",$self);
75 <        $self->addurltags("setup");
76 <        $self->addtag("setup_tools","use",\&Use_Start,$self, "", $self, "",$self);
77 <        $self->addtag("setup","structure",\&Structure_Start,$self,
78 <                         "", $self, "",$self);
57 > sub new {
58 >        my $class=shift;
59 >        my $self={};
60 >        bless $self, $class;
61  
62          # data init
63 <        $self->{admindir}=".SCRAM";
63 >        $self->{admindir}=".SCRAM";
64 >        $self->{cachedir}="cache";
65 >        $self->{dbdir}="ObjectDB";
66 >        undef $self->{linkarea};
67 >
68 >        return $self;
69   }
70  
71 < sub basearea {
71 > sub cache {
72          my $self=shift;
73  
74 <        my $area;
74 >        my $exist=0;
75          if ( @_ ) {
76 <          $area=shift;
77 <          $self->config()->store($area,"BaseArea");
76 >          my $cache=shift;
77 >          if ( $cache!~/^</ ) {
78 >            $self->{cache}=$cache;
79 >          }
80 >          $exist=1;
81          }
82 <        else {
83 <          ($area)=$self->config()->restore("BaseArea");
82 >        elsif ( ! defined $self->{cache} ) {
83 >          my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
84 >          if ( ! $exist ) {
85 >            $self->{cache}=URL::URLcache->new($loc);
86 >          }
87          }
88 <        return $area;
88 >        return $self->{cache};
89   }
90  
91 < sub freebase {
91 > sub objectstore {
92          my $self=shift;
93 <        $self->config()->delete("BaseArea");
93 >
94 >        my $exist="";
95 >        if ( @_ ) {
96 >          my $db=shift;
97 >          if ( $db!~/^</ ) {
98 >            $self->{dbstore}=cache;
99 >          }
100 >          $exist="<";
101 >        }
102 >        elsif ( ! defined $self->{dbstore} ) {
103 >          my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
104 >          $self->{dbstore}=ObjectUtilities::ObjectStore->new($exist.$loc);
105 >        }
106 >        return $self->{dbstore}
107   }
108  
109 < sub defaultdirname {
109 > sub name {
110          my $self=shift;
111 <        my $name=$self->name();
112 <        my $vers=$self->version();
107 <        $vers=~s/^$name\_//;
108 <        $name=$name."_".$vers;
109 <        return $name;
111 >        @_?$self->{name}=shift
112 >          :$self->{name};
113   }
114  
115 + sub version {
116 +        my $self=shift;
117 +        @_?$self->{version}=shift
118 +          :$self->{version};
119 + }
120  
121   sub setup {
122          my $self=shift;
123 +        my $location=shift;
124 +        my $areaname;
125  
126 <        # --- find out the location - default is cwd
127 <        my $location=$self->option("ConfigArea_location");
126 >        # -- check we have a project name and version
127 >        my $name=$self->name();
128 >        my $vers=$self->version();
129 >        if ( ( ! defined $name ) && ( ! defined $version )) {
130 >          $self->error("Set ConfigArea name and version before setup");
131 >        }
132 >
133 >        # -- check arguments and set location
134          if ( ! defined $location ) {
135 <                $location=cwd();
135 >          $self->error("ConfigArea: Cannot setup new area without a location");
136          }
137 <        elsif ( $location!~/^\// ) {
138 <                $location=cwd()."/".$location;
137 >        if ( @_ ) {
138 >          $areaname=shift;
139          }
140 <
141 <        # --- find area directory name , default name projectname_version
142 <        my $name=$self->option("ConfigArea_name");
143 <        if ( ! defined $name ) {
128 <          $name=$self->defaultdirname();
140 >        if ( (! defined $areaname) || ( $areaname eq "" ) ) {
141 >          # -- make up a name from the project name and version
142 >          $vers=~s/^$name\_//;
143 >          $areaname=$name."_".$vers;
144          }
145 <        $self->location($location."/".$name);
146 <
147 <        # make a new store handler
148 <        $self->_setupstore();
145 >        my $arealoc=$location."/".$areaname;
146 >        my $workloc=$arealoc."/".$self->{admindir};
147 >        $self->verbose("Building at $arealoc");
148 >        $self->location($arealoc);
149  
150 <        # --- download everything first
151 <        $self->parse("download");
137 <        
138 <        # --- and parse the setup file
139 <        $self->parse("setup");
140 <        $self->parse("setup_tools");
141 <        
142 <        # --- store bootstrap info
143 <        $self->store($self->location()."/".$self->{admindir}."/ConfigArea.dat");
150 >        # -- create top level structure and work area
151 >        AddDir::adddir($workloc);
152  
153 <        # --- store self in original database
154 <        $self->parentconfig()->store($self,"ConfigArea",$self->name(),
147 <                                                        $self->version());
148 < }
153 >        # -- add a cache
154 >        $self->cache();
155  
156 < sub structure {
157 <        my $self=shift;
152 <        my $vr=shift;
153 <        return $self->{structures}{$vr};
154 < }
156 >        # -- Save Environment File
157 >        $self->_SaveEnvFile();
158  
156 sub structurelist {
157        my $self=shift;
158        return ( keys %{$self->{structures}} );
159   }
160  
161 < sub _setupstore {
161 > sub configurationdir {
162          my $self=shift;
163 <
164 <        # --- make a new ConfigStore at the location and add it to the db list
165 <        my $ad=Configuration::ConfigStore->new($self->location().
166 <                                "/".$self->{admindir}, $self->arch());
167 <
168 <        $self->parentconfig($self->config());
169 < #        $self->config(Configuration::ConfigureStore->new());
170 < #        $self->config()->db("local",$ad);
171 < #        $self->config()->db("parent",$self->parentconfig());
172 < #        $self->config()->policy("cache","local");
173 <        $self->config($ad);
174 <        $self->config()->basedoc($self->parentconfig()->basedoc());
175 < }
176 <
177 < sub bootstrapfromlocation {
178 <        my $self=shift;
179 <        
180 <        if ( ! defined $self->location(@_) ) {
181 <          $self->error("Unable to locate the top of local configuration area");
163 >        if ( @_ ) {
164 >          $self->{configurationdir}=shift;
165          }
166 <        print "Found top ".$self->location()."\n";
184 <        $self->_setupstore();
185 <        $self->restore($self->location()."/".$self->{admindir}.
186 <                                                "/ConfigArea.dat");
187 < }
188 <
189 < sub parentconfig {
190 <        my $self=shift;
191 <        @_?$self->{parentconfig}=shift
192 <          :$self->{parentconfig};
193 < }
194 <
195 < sub store {
196 <        my $self=shift;
197 <        my $location=shift;
198 <
199 <        my $fh=$self->openfile(">".$location);
200 <        $self->savevar($fh,"location", $self->location());
201 <        $self->savevar($fh,"url", $self->url());
202 <        $self->savevar($fh,"name", $self->name());
203 <        $self->savevar($fh,"version", $self->version());
204 <        $fh->close();
205 <
206 <        $self->_storestructures();
166 >        return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
167   }
168  
169 < sub satellite {
169 > sub toolbox {
170          my $self=shift;
171 <        my $newarea=$self->copy(@_);
172 <        $newarea->_makesatellites();
173 <        return $newarea;
171 >        if ( ! defined $self->{toolbox} ) {
172 >          $self->{toolbox}=BuildSystem::ToolBox->new($self);
173 >        }
174 >        return $self->{toolbox};
175   }
176  
177 < sub copy {
177 > sub requirementsdoc {
178          my $self=shift;
218        use File::Basename;
219        # create the area
220
221        my $destination;
179          if ( @_ ) {
180 <         $destination=shift;
180 >          $self->{reqdoc}=shift;
181 >        }
182 >        if ( defined $self->{reqdoc} ) {
183 >          return $self->location()."/".$self->{reqdoc};
184          }
185          else {
186 <          my($location,$name)=$self->_defaultoptions();
227 <          $destination=$location."/".$name
186 >          return undef;
187          }
229        #AddDir::adddir(dirname($destination)."/".$self->{admindir});
230        #AddDir::adddir($destination."/".$self->{admindir});
231        
232        # copy across the admin dir
233        $temp=$self->location()."/".$self->{admindir};
234        AddDir::copydir($temp,"$destination/".$self->{admindir});
235        # create a new object based on the new area
236        my $newarea=ref($self)->new($self->parentconfig());
237        $newarea->bootstrapfromlocation($destination);
238        # save it with the new location info
239        $newarea->store($self->location()."/".$self->{admindir}.
240                                                        "/ConfigArea.dat");
241        return $newarea;
188   }
189  
190 < sub restore {
190 > sub scramversion {
191          my $self=shift;
192 <        my $location=shift;
193 <
194 <        my $fh=$self->openfile("<".$location);
195 <        my $varhash={};
196 <        $self->restorevars($fh,$varhash);
197 <        if ( ! defined $self->location() ) {
198 <          $self->location($$varhash{"location"});
199 <        }
200 <        $self->_setupstore();
201 <        $self->url($$varhash{"url"});
202 <        $self->name($$varhash{"name"});
203 <        $self->version($$varhash{"version"});
204 <        $fh->close();
205 <
260 <        $self->_restorestructures();
261 < }
262 <
263 < sub name {
264 <        my $self=shift;
265 <
266 <        @_?$self->{name}=shift
267 <          :$self->{name};
192 >        if ( ! defined $self->{scramversion} ) {
193 >          my $filename=$self->location()."/".$self->configurationdir()."/".
194 >                                                        "scram_version";
195 >          if ( -f $filename ) {
196 >            use FileHandle;
197 >            $fh=FileHandle->new();
198 >            open ($fh, "<".$filename);
199 >            my $version=<$fh>;
200 >            chomp $version;
201 >            $self->{scramversion}=$version;
202 >            undef $fh;
203 >          }
204 >        }
205 >        return $self->{scramversion};
206   }
207  
208 < sub version {
208 > sub bootstrapfromlocation {
209          my $self=shift;
210  
211 <        @_?$self->{version}=shift
212 <          :$self->{version};
211 >        my $rv=0;
212 >        
213 >        my $location;
214 >        if ( ! defined ($location=$self->searchlocation(@_)) ) {
215 >         $rv=1;
216 >         $self->verbose("Unable to locate the top of local configuration area");
217 >        }
218 >        else {
219 >         $self->location($location);
220 >         $self->verbose("Found top ".$self->location());
221 >         my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat";
222 >         $self->_LoadEnvFile();
223 >        }
224 >        return $rv;
225   }
226  
227   sub location {
# Line 292 | Line 242 | sub searchlocation {
242  
243          #start search in current directory if not specified
244          my $thispath;
245 <        @_?$thispath=shift
246 <          :$thispath=cwd();
245 >        if ( @_ ) {
246 >          $thispath=shift
247 >        }
248 >        else {
249 >          $thispath=cwd();
250 >        }
251  
252          my $rv=0;
253  
254 +        # chop off any files - we only want dirs
255 +        if ( -f $thispath ) {
256 +          $thispath=~s/(.*)\/.*/$1/;
257 +        }
258          Sloop:{
259          do {
260 < #         print "Searching $thispath\n";
260 >          $self->verbose("Searching $thispath");
261            if ( -e "$thispath/".$self->{admindir} ) {
262 < #           print "Found\n";
262 >            $self->verbose("Found\n");
263              $rv=1;
264              last Sloop;
265            }
# Line 310 | Line 268 | sub searchlocation {
268          return $rv?$thispath:undef;
269   }
270  
271 < sub meta {
271 > sub archname {
272          my $self=shift;
273 <
274 <        my $string=$self->name()." ".$self->version()." located at :\n  ".
275 <                $self->location;
273 >        if ( @_ ) {
274 >          $self->{archname}=shift;
275 >        }
276 >        return $self->{archname};
277   }
278  
279 < sub configitem {
279 > sub archdir {
280          my $self=shift;
281 <        
282 <        return ($self->config()->find("ConfigItem",@_));
281 >        if ( @_ ) {
282 >          $self->{archdir}=shift;
283 >        }
284 >        if ( ! defined $self->{archdir} ) {
285 >         if ( defined $self->{archname} ) {
286 >          $self->{archdir}=$self->location()."/".$self->{admindir}."/".
287 >                                                        $self->{archname};
288 >         }
289 >         else {
290 >          $self->error("ConfigArea : cannot create arch directory - ".
291 >                                                "architecture name not set")
292 >         }
293 >        }
294 >        return $self->{archdir};
295   }
296  
297 < sub addconfigitem {
297 > sub satellite {
298          my $self=shift;
328        my $url=shift;
299  
300 <        my $docref=$self->activatedoc($url);
301 <        # Set up the document
302 <        $docref->setup();
303 <        $docref->save();
304 < #       $self->config()->storepolicy("local");
300 >        # -- create the sat object
301 >        my $sat=Configuration::ConfigArea->new();
302 >        $sat->name($self->name());
303 >        $sat->version($self->version());
304 >        $sat->requirementsdoc($self->{reqdoc});
305 >        $sat->configurationdir($self->configurationdir());
306 >        $sat->setup(@_);
307 >
308 >        # -- copy across the cache and ObjectStore
309 >        # -- make sure we dont try building new caches in release areas
310 >        my $rcache=$self->cache("<");
311 >        if ( defined $rcache ) {
312 >          copy($rcache->location(),$sat->cache()->location());
313 >        }
314 >
315 >        # -- make sure we dont try building new objectstores in release areas
316 >        my $rostore=$self->objectstore("<");
317 >        if ( defined $rostore ) {
318 >          copy($rostore->location(),$sat->objectstore()->location());
319 >        }
320 >
321 >        # and make sure in reinitialises
322 >        undef ($sat->{cache});
323 >
324 >        # -- link it to this area
325 >        $sat->linkarea($self);
326 >        
327 >        # -- save it
328 >        $sat->save();
329 >
330 >        return $sat;
331   }
332  
333 < sub downloadtotop {
333 > sub copy {
334          my $self=shift;
335 <        my $url=shift;
336 <        my $dir=shift;
337 <        
338 <        # only download once
339 <        if ( ! -e $self->location()."/".$dir ) {
344 <          $self->{urlhandler}->download($url,$self->location()."/".$dir);
345 <        }
335 >        my $destination=shift;
336 >
337 >        # copy across the admin dir
338 >        my $temp=$self->location()."/".$self->{admindir};
339 >        AddDir::copydir($temp,"$destination/".$self->{admindir});
340   }
341  
342 < sub _makesatellites {
342 > sub align {
343          my $self=shift;
344 <        foreach $st ( values %{$self->{structures}} ) {
345 <           $st->setupsatellite()
346 <        }
344 >        use File::Copy;
345 >
346 >        $self->_LoadEnvFile();
347 >        my $Envfile=$self->location()."/".$self->{admindir}."/Environment";
348 >        my $tmpEnvfile=$Envfile.".bak";
349 >        my $rel=$self->{ENV}{RELEASETOP};
350 >        my $local=$self->location();
351 >
352 >        rename( $Envfile, $tmpEnvfile );
353 >        use FileHandle;
354 >        my $fh=FileHandle->new();
355 >        my $fout=FileHandle->new();
356 >        open ( $fh, "<".$tmpEnvfile ) or
357 >                $self->error("Cannot find Environment file. Area Corrupted? ("
358 >                                .$self->location().")\n $!");
359 >        open ( $fout, ">".$Envfile ) or
360 >                $self->error("Cannot find Environment file. Area Corrupted? ("
361 >                                .$self->location().")\n $!");
362 >        while ( <$fh> ) {
363 >          $_=~s/\Q$rel\L/$local/g;
364 >          print $fout $_;
365 >        }
366 >        undef $fh;
367 >        undef $fout;
368   }
369  
370 < sub _storestructures {
370 > sub copysetup {
371          my $self=shift;
372 <        foreach $struct ( values %{$self->{structures}} ) {
373 <          $self->config()->store($struct, "Structures", $struct->name());
372 >        my $dest=shift;
373 >
374 >        my $rv=1;
375 >        # copy across the admin dir
376 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
377 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
378 >        if ( $temp ne $temp2 ) {
379 >         if ( -d $temp ) {
380 >          AddDir::copydir($temp,$temp2);
381 >          $rv=0;
382 >         }
383          }
384 +        return $rv;
385   }
386  
387 < sub _restorestructures {
387 > sub copyenv {
388          my $self=shift;
389 <        my @strs=$self->config()->find("Structures");
390 <        foreach $struct ( @strs ) {
391 <          $struct->parent($self);
392 <          $self->{structures}{$struct->name()}=$struct;
389 >        my $hashref=shift;
390 >        
391 >        foreach $elem ( keys %{$self->{ENV}} ) {
392 >           $$hashref{$elem}=$self->{ENV}{$elem};
393          }
394   }
395  
396 < sub _defaultoptions {
396 > sub arch {
397          my $self=shift;
398 <        my $name;
374 <        my $location;
375 <
376 <        # --- find out the location - default is cwd
377 <        $location=$self->option("ConfigArea_location");
378 <        if ( ! defined $location ) {
379 <                $location=cwd();
380 <        }
381 <        elsif ( $location!~/^\// ) {
382 <                $location=cwd()."/".$location;
383 <        }
384 <
385 <        # --- find area directory name , default name projectname_version
386 <        $name=$self->option("ConfigArea_name");
387 <        if ( ! defined $name ) {
388 <          $name=$self->defaultdirname();
389 <        }
390 <        return ($location,$name);
398 >        return $ENV{SCRAM_ARCH};
399   }
392 # -------------- Tags ---------------------------------
393 # -- init parse
394 sub Project_Start {
395        my $self=shift;
396        my $name=shift;
397        my $hashref=shift;
398
399        $self->checktag($name,$hashref,'name');
400        $self->checktag($name,$hashref,'version');
400  
401 <        $self->name($$hashref{'name'});
402 <        $self->version($$hashref{'version'});
401 > sub linkto {
402 >        my $self=shift;
403 >        my $location=shift;
404 >        if ( -d $location ) {
405 >        my $area=Configuration::ConfigArea->new();
406 >        $area->bootstrapfromlocation($location);
407 >        $self->linkarea($area);
408 >        }
409 >        else {
410 >          $self->error("ConfigArea : Unable to link to non existing directory ".
411 >                         $location);
412 >        }
413   }
414  
415 <
407 < sub Project_text {
415 > sub unlinkarea {
416          my $self=shift;
417 <        my $name=shift;
418 <        my $string=shift;
419 <
412 <        print $string;
417 >        undef $self->{linkarea};
418 >        $self->{linkarea}=undef;
419 >        $self->save();
420   }
421  
422 < # ---- download parse
416 <
417 < sub Download_Start {
422 > sub linkarea {
423          my $self=shift;
424 <        my $name=shift;
425 <        my $hashref=shift;
426 <
422 <        $self->checktag($name,$hashref,'url');
423 <        $self->checktag($name,$hashref,'location');
424 <        if ( $$hashref{'location'}!~/^\w/ ) {
425 <          $self->parseerror("location must start with an".
426 <                " alphanumeric character");
424 >        my $area=shift;
425 >        if ( defined $area ) {
426 >          $self->{linkarea}=$area;
427          }
428 <        print "Downloading .... ".$$hashref{'url'}."\n";
429 <        $self->downloadtotop($$hashref{'url'},$$hashref{'location'});
428 >        return (defined $self->{linkarea} && $self->{linkarea} ne "")?
429 >                        $self->{linkarea}:undef;
430   }
431  
432 < sub Use_download_Start {
432 > sub save {
433          my $self=shift;
434 <        my $name=shift;
435 <        my $hashref=shift;
436 <
437 <        $self->checktag($name,$hashref,'url');
438 <        print "Downloading .... ".$$hashref{'url'}."\n";
439 <        $self->getfile($$hashref{'url'});
434 >        $self->_SaveEnvFile();
435   }
436  
437 < # --- setup parse
437 > # ---- support routines
438  
439 < sub Structure_Start {
439 > sub _SaveEnvFile {
440          my $self=shift;
441 <        my $name=shift;
442 <        my $hashref=shift;
443 <
444 <        $self->checktag($name,$hashref,'name');
445 <        if ( !(( exists $$hashref{'type'}) || ( exists $$hashref{'url'})) ) {
446 <            $self->parseerror("No url or type given in <$name> tag");
447 <        }
448 <        if ( ! exists $self->{structures}{$$hashref{'name'}} ) {
449 <          if ( exists $$hashref{'type'}) {
450 <            # create a new object of the specified type
451 <            eval "require $$hashref{'type'} ";
452 <            if  ( $@ ) {
453 <                $self->parseerror("Unable to instantiate type=".
454 <                        $$hashref{'type'}." in <$name> .".$@);
455 <            }
461 <            $self->{structures}{$$hashref{'name'}}=
462 <                $$hashref{'type'}->new($self->config());
463 <            $self->{structures}{$$hashref{'name'}}->name($$hashref{'name'});
464 <            $self->{structures}{$$hashref{'name'}}->parent($self);
465 <            $self->{structures}{$$hashref{'name'}}->vars($hashref);
466 <            $self->{structures}{$$hashref{'name'}}->arch($self->arch());
467 <          }
468 <          else { # its an activedoc
469 <                $self->{structures}{$$hashref{'name'}}=
470 <                                $self->activatedoc($$hashref{'url'});
441 >        use FileHandle;
442 >        my $fh=FileHandle->new();
443 >        open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
444 >                "Environment" ) or
445 >                $self->error("Cannot Open Environment file to Save ("
446 >                                .$self->location().")\n $!");
447 >        
448 >        print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
449 >        print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
450 >        print $fh "projconfigdir=".$self->configurationdir()."\n";
451 >        print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n";
452 >        if ( defined $self->linkarea() ) {
453 >          my $area=$self->linkarea()->location();
454 >          if ( $area ne "" ) {
455 >          print $fh "RELEASETOP=".$area."\n";
456            }
472          $self->{structures}{$$hashref{'name'}}->setupbase();
473        }
474        else {
475             $self->parseerror("Multiply defined Structure - ".
476                                                        $$hashref{'name'});
457          }
458 +        undef $fh;
459   }
460  
461 < sub Use_Start {
461 >
462 > sub _LoadEnvFile {
463          my $self=shift;
464 <        my $name=shift;
465 <        my $hashref=shift;
464 >
465 >        use FileHandle;
466 >        my $fh=FileHandle->new();
467 >        open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
468 >                "Environment" ) or
469 >                $self->error("Cannot find Environment file. Area Corrupted? ("
470 >                                .$self->location().")\n $!");
471 >        while ( <$fh> ) {
472 >           chomp;
473 >           next if /^#/;
474 >           next if /^\s*$/ ;
475 >           ($name, $value)=split /=/;
476 >           eval "\$self->{ENV}{${name}}=\"$value\"";
477 >        }
478 >        undef $fh;
479          
480 <        $self->checktag($name,$hashref,'url');
481 <        $self->addconfigitem($$hashref{'url'});
480 >        # -- set internal variables appropriately
481 >        if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} ) {
482 >          $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
483 >        }
484 >        if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} ) {
485 >          $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
486 >        }
487 >        if ( defined $self->{ENV}{"projconfigdir"} ) {
488 >          $self->configurationdir($self->{ENV}{projconfigdir});
489 >        }
490 >        if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} ) {
491 >          $self->requirementsdoc($self->{ENV}{SCRAM_ProjReqsDoc});
492 >        }
493 >        if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
494 >                        ($self->{ENV}{"RELEASETOP"} ne $self->location())) {
495 >          $self->linkto($self->{ENV}{"RELEASETOP"});
496 >        }
497 >        else {
498 >          $self->{ENV}{"RELEASETOP"}=$self->location();
499 >        }
500   }
488

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines