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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines