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