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.10 by williamc, Thu Feb 24 09:55:13 2000 UTC vs.
Revision 1.21 by sashby, Mon Dec 3 19:02:05 2001 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  
87        my $area;
74          if ( @_ ) {
75 <          $area=shift;
90 <          $self->config()->store($area,"BaseArea");
75 >           $self->{cache}=shift;
76          }
77 <        else {
78 <          ($area)=$self->config()->restore("BaseArea");
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 $area;
86 >        return $self->{cache};
87   }
88  
89 < sub freebase {
89 > sub _newcache {
90          my $self=shift;
91 <        $self->config()->delete("BaseArea");
91 >        my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
92 >        $self->{cache}=URL::URLcache->new($loc);
93 >        return $self->{cache};
94   }
95  
96 < sub defaultdirname {
96 > sub _newobjectstore {
97          my $self=shift;
98 <        my $name=$self->name();
99 <        my $vers=$self->version();
100 <        $vers=~s/^$name\_//;
108 <        $name=$name."_".$vers;
109 <        return $name;
98 >        my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
99 >        $self->{dbstore}=ObjectUtilities::ObjectStore->new($loc);
100 >        return $self->{dbstore};
101   }
102  
103 <
113 < sub setup {
103 > sub objectstore {
104          my $self=shift;
105  
106 <        # --- find out the location - default is cwd
107 <        my $location=$self->option("ConfigArea_location");
118 <        if ( ! defined $location ) {
119 <                $location=cwd();
120 <        }
121 <        elsif ( $location!~/^\// ) {
122 <                $location=cwd()."/".$location;
106 >        if ( @_ ) {
107 >            $self->{dbstore}=shift;
108          }
109 <
110 <        # --- find area directory name , default name projectname_version
111 <        my $name=$self->option("ConfigArea_name");
112 <        if ( ! defined $name ) {
113 <          $name=$self->defaultdirname();
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 <        $self->location($location."/".$name);
131 <
132 <        # make a new store handler
133 <        $self->_setupstore();
134 <
135 <        # --- download everything first
136 <        $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");
144 <
145 <        # --- store self in original database
146 <        $self->parentconfig()->store($self,"ConfigArea",$self->name(),
147 <                                                        $self->version());
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());
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 < }
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 <        
180 <        if ( ! defined $self->location(@_) ) {
181 <          $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 <        print "Found top ".$self->location()."\n";
150 <        $self->_setupstore();
151 <        $self->restore($self->location()."/".$self->{admindir}.
152 <                                                "/ConfigArea.dat");
153 < }
149 >        if ( @_ ) {
150 >          $areaname=shift;
151 >        }
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 >        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;
191 <        @_?$self->{parentconfig}=shift
192 <          :$self->{parentconfig};
193 < }
162 >        # -- create top level structure and work area
163 >        AddDir::adddir($workloc);
164  
165 < sub store {
166 <        my $self=shift;
167 <        my $location=shift;
165 >        # -- add a cache
166 >        $self->_newcache();
167 >
168 >        # -- add an Objectstore
169 >        $self->_newobjectstore();
170  
171 <        my $fh=$self->openfile(">".$location);
172 <        $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();
171 >        # -- Save Environment File
172 >        $self->_SaveEnvFile();
173  
206        $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, $ENV{SCRAM_ARCH});
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();
227 <          $destination=$location."/".$name
201 >          return undef;
202          }
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;
203   }
204  
205 < sub restore {
205 > sub scramversion {
206          my $self=shift;
207 <        my $location=shift;
208 <
209 <        my $fh=$self->openfile("<".$location);
210 <        my $varhash={};
211 <        $self->restorevars($fh,$varhash);
212 <        if ( ! defined $self->location() ) {
213 <          $self->location($$varhash{"location"});
214 <        }
215 <        $self->_setupstore();
216 <        $self->url($$varhash{"url"});
217 <        $self->name($$varhash{"name"});
218 <        $self->version($$varhash{"version"});
219 <        $fh->close();
220 <
260 <        $self->_restorestructures();
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 name {
224 <        my $self=shift;
223 > sub sitename
224 >   {
225 >   ###############################################################
226 >   # sitename()                                                  #
227 >   ###############################################################
228 >   # modified : Mon Dec  3 15:45:35 2001 / SFA                   #
229 >   # params   :                                                  #
230 >   #          :                                                  #
231 >   #          :                                                  #
232 >   #          :                                                  #
233 >   # function : Read the site name from config/site/sitename and #
234 >   #          : export it.                                       #
235 >   #          :                                                  #
236 >   #          :                                                  #
237 >   ###############################################################
238 >   my $self = shift;
239 >   my $sitefile = $self->location()."/".$self->configurationdir()."/site/sitename";
240 >
241 >   $self->{sitename} = 'CERN'; # Use CERN as the default site name
242 >
243 >   use FileHandle;
244 >   my $sitefh = FileHandle->new();
245 >  
246 >   # See if we can read from the file. If not, just
247 >   # use default site name:
248 >   open($sitefh,"<".$sitefile) ||
249 >      do
250 >         {
251 >         $self->verbose("Unable to read a site name definition file. Using \'CERN\' as the site name.");
252 >         return $self->{sitename};
253 >         };
254 >  
255 >   $sitename = <$sitefh>;
256 >   chomp($sitename);
257 >   $self->{sitename} = $sitename;
258 >  
259 >   # Close the file (be tidy!);
260 >   close($sitefile);
261 >   # Return:
262 >   return $self->{sitename};
263 >   }
264  
266        @_?$self->{name}=shift
267          :$self->{name};
268 }
265  
266 < sub version {
266 > sub bootstrapfromlocation {
267          my $self=shift;
268  
269 <        @_?$self->{version}=shift
270 <          :$self->{version};
269 >        my $rv=0;
270 >        
271 >        my $location;
272 >        if ( ! defined ($location=$self->searchlocation(@_)) ) {
273 >         $rv=1;
274 >         $self->verbose("Unable to locate the top of local configuration area");
275 >        }
276 >        else {
277 >         $self->location($location);
278 >         $self->verbose("Found top ".$self->location());
279 >         my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat";
280 >         $self->_LoadEnvFile();
281 >        }
282 >        return $rv;
283   }
284  
285   sub location {
# Line 289 | Line 297 | sub location {
297  
298   sub searchlocation {
299          my $self=shift;
300 <
300 >        
301          #start search in current directory if not specified
302          my $thispath;
303 <        @_?$thispath=shift
304 <          :$thispath=cwd();
305 <
303 >        if ( @_ ) {
304 >          $thispath=shift
305 >        }
306 >        else {
307 >          $thispath=cwd();
308 >        }
309 >        
310          my $rv=0;
311  
312 +        # chop off any files - we only want dirs
313 +        if ( -f $thispath ) {
314 +          $thispath=~s/(.*)\/.*/$1/;
315 +        }
316          Sloop:{
317          do {
318 < #         print "Searching $thispath\n";
318 >          $self->verbose("Searching $thispath");
319            if ( -e "$thispath/".$self->{admindir} ) {
320 < #           print "Found\n";
320 >            $self->verbose("Found\n");
321              $rv=1;
322              last Sloop;
323            }
324          } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
325 <
325 >      
326          return $rv?$thispath:undef;
327   }
328  
329 < sub meta {
329 > sub archname {
330          my $self=shift;
331 <
332 <        my $string=$self->name()." ".$self->version()." located at :\n  ".
333 <                $self->location;
331 >        if ( @_ ) {
332 >          $self->{archname}=shift;
333 >        }
334 >        return $self->{archname};
335   }
336  
337 < sub configitem {
337 > sub archdir {
338          my $self=shift;
339 <        
340 <        return ($self->config()->find("ConfigItem",@_));
339 >        if ( @_ ) {
340 >          $self->{archdir}=shift;
341 >        }
342 >        if ( ! defined $self->{archdir} ) {
343 >         if ( defined $self->{archname} ) {
344 >          $self->{archdir}=$self->location()."/".$self->{admindir}."/".
345 >                                                        $self->{archname};
346 >         }
347 >         else {
348 >          $self->error("ConfigArea : cannot create arch directory - ".
349 >                                                "architecture name not set")
350 >         }
351 >        }
352 >        return $self->{archdir};
353   }
354  
355 < sub addconfigitem {
355 > sub satellite {
356          my $self=shift;
328        my $url=shift;
357  
358 <        my $docref=$self->activatedoc($url);
359 <        # Set up the document
360 <        $docref->setup();
361 <        $docref->save();
362 < #       $self->config()->storepolicy("local");
358 >        # -- create the sat object
359 >        my $sat=Configuration::ConfigArea->new();
360 >        $sat->name($self->name());
361 >        $sat->version($self->version());
362 >        $sat->requirementsdoc($self->{reqdoc});
363 >        $sat->configurationdir($self->configurationdir());
364 >        $sat->setup(@_);
365 >
366 >        # -- copy across the cache and ObjectStore
367 >        # -- make sure we dont try building new caches in release areas
368 >        my $rcache=$self->cache();
369 >        if ( defined $rcache ) {
370 >          copy($rcache->location(),$sat->cache()->location());
371 >        }
372 >
373 >        # -- make sure we dont try building new objectstores in release areas
374 >        my $rostore=$self->objectstore();
375 >        if ( defined $rostore ) {
376 >          copy($rostore->location(),$sat->objectstore()->location());
377 >        }
378 >
379 >        # and make sure in reinitialises
380 >        undef ($sat->{cache});
381 >
382 >        # -- link it to this area
383 >        $sat->linkarea($self);
384 >        
385 >        # -- save it
386 >        $sat->save();
387 >
388 >        return $sat;
389   }
390  
391 < sub downloadtotop {
391 > sub copy {
392          my $self=shift;
393 <        my $url=shift;
394 <        my $dir=shift;
395 <        
396 <        # only download once
397 <        if ( ! -e $self->location()."/".$dir ) {
344 <          $self->{urlhandler}->download($url,$self->location()."/".$dir);
345 <        }
393 >        my $destination=shift;
394 >
395 >        # copy across the admin dir
396 >        my $temp=$self->location()."/".$self->{admindir};
397 >        AddDir::copydir($temp,"$destination/".$self->{admindir});
398   }
399  
400 < sub _makesatellites {
400 > sub align {
401          my $self=shift;
402 <        foreach $st ( values %{$self->{structures}} ) {
403 <           $st->setupsatellite()
404 <        }
402 >        use File::Copy;
403 >
404 >        $self->_LoadEnvFile();
405 >        my $Envfile=$self->location()."/".$self->{admindir}."/Environment";
406 >        my $tmpEnvfile=$Envfile.".bak";
407 >        my $rel=$self->{ENV}{RELEASETOP};
408 >        my $local=$self->location();
409 >
410 >        rename( $Envfile, $tmpEnvfile );
411 >        use FileHandle;
412 >        my $fh=FileHandle->new();
413 >        my $fout=FileHandle->new();
414 >        open ( $fh, "<".$tmpEnvfile ) or
415 >                $self->error("Cannot find Environment file. Area Corrupted? ("
416 >                                .$self->location().")\n $!");
417 >        open ( $fout, ">".$Envfile ) or
418 >                $self->error("Cannot find Environment file. Area Corrupted? ("
419 >                                .$self->location().")\n $!");
420 >        while ( <$fh> ) {
421 >          $_=~s/\Q$rel\L/$local/g;
422 >          print $fout $_;
423 >        }
424 >        undef $fh;
425 >        undef $fout;
426   }
427  
428 < sub _storestructures {
428 > sub copysetup {
429          my $self=shift;
430 <        foreach $struct ( values %{$self->{structures}} ) {
431 <          $self->config()->store($struct, "Structures", $struct->name());
430 >        my $dest=shift;
431 >
432 >        my $rv=1;
433 >        # copy across the admin dir
434 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
435 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
436 >        if ( $temp ne $temp2 ) {
437 >         if ( -d $temp ) {
438 >          AddDir::copydir($temp,$temp2);
439 >          $rv=0;
440 >         }
441          }
442 +        return $rv;
443   }
444  
445 < sub _restorestructures {
445 > sub copyenv {
446          my $self=shift;
447 <        my @strs=$self->config()->find("Structures");
448 <        foreach $struct ( @strs ) {
449 <          $struct->parent($self);
450 <          $self->{structures}{$struct->name()}=$struct;
447 >        my $hashref=shift;
448 >        
449 >        foreach $elem ( keys %{$self->{ENV}} ) {
450 >           $$hashref{$elem}=$self->{ENV}{$elem};
451          }
452   }
453  
454 < sub _defaultoptions {
454 > sub arch {
455          my $self=shift;
456 <        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);
456 >        return $ENV{SCRAM_ARCH};
457   }
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');
458  
459 <        $self->name($$hashref{'name'});
460 <        $self->version($$hashref{'version'});
459 > sub linkto {
460 >        my $self=shift;
461 >        my $location=shift;
462 >        if ( -d $location ) {
463 >        my $area=Configuration::ConfigArea->new();
464 >        $area->bootstrapfromlocation($location);
465 >        $self->linkarea($area);
466 >        }
467 >        else {
468 >          $self->error("ConfigArea : Unable to link to non existing directory ".
469 >                         $location);
470 >        }
471   }
472  
473 <
407 < sub Project_text {
473 > sub unlinkarea {
474          my $self=shift;
475 <        my $name=shift;
476 <        my $string=shift;
477 <
412 <        print $string;
475 >        undef $self->{linkarea};
476 >        $self->{linkarea}=undef;
477 >        $self->save();
478   }
479  
480 < # ---- download parse
416 <
417 < sub Download_Start {
480 > sub linkarea {
481          my $self=shift;
482 <        my $name=shift;
483 <        my $hashref=shift;
484 <
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");
482 >        my $area=shift;
483 >        if ( defined $area ) {
484 >          $self->{linkarea}=$area;
485          }
486 <        print "Downloading .... ".$$hashref{'url'}."\n";
487 <        $self->downloadtotop($$hashref{'url'},$$hashref{'location'});
486 >        return (defined $self->{linkarea} && $self->{linkarea} ne "")?
487 >                        $self->{linkarea}:undef;
488   }
489  
490 < sub Use_download_Start {
490 > sub save {
491          my $self=shift;
492 <        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'});
492 >        $self->_SaveEnvFile();
493   }
494  
495 < # --- setup parse
495 > # ---- support routines
496  
497 < sub Structure_Start {
497 > sub _SaveEnvFile {
498          my $self=shift;
499 <        my $name=shift;
500 <        my $hashref=shift;
501 <
502 <        $self->checktag($name,$hashref,'name');
503 <        if ( !( exists $$hashref{'type'}) || ( exists $$hashref{'url'}) ) {
504 <            $self->parseerror("No url or type given in <$name> tag");
505 <        }
506 <        if ( ! exists $self->{structures}{$$hashref{'name'}} ) {
507 <          if ( exists $$hashref{'type'}) {
508 <            # create a new object of the specified type
509 <            eval "require $$hashref{'type'} ";
510 <            if  ( $@ ) {
511 <                $self->parseerror("Unable to instantiate type=".
512 <                        $$hashref{'type'}." in <$name> .".$@);
513 <            }
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 <          }
467 <          else { # its an activedoc
468 <                $self->{structures}{$$hashref{'name'}}=
469 <                                $self->activatedoc($$hashref{'url'});
499 >        use FileHandle;
500 >        my $fh=FileHandle->new();
501 >        open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
502 >                "Environment" ) or
503 >                $self->error("Cannot Open Environment file to Save ("
504 >                                .$self->location().")\n $!");
505 >        
506 >        print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
507 >        print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
508 >        print $fh "projconfigdir=".$self->configurationdir()."\n";
509 >        print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n";
510 >        if ( defined $self->linkarea() ) {
511 >          my $area=$self->linkarea()->location();
512 >          if ( $area ne "" ) {
513 >          print $fh "RELEASETOP=".$area."\n";
514            }
471          $self->{structures}{$$hashref{'name'}}->setupbase();
472        }
473        else {
474             $self->parseerror("Multiply defined Structure - ".
475                                                        $$hashref{'name'});
515          }
516 +        undef $fh;
517   }
518  
519 < sub Use_Start {
519 >
520 > sub _LoadEnvFile {
521          my $self=shift;
522 <        my $name=shift;
523 <        my $hashref=shift;
522 >
523 >        use FileHandle;
524 >        my $fh=FileHandle->new();
525 >        open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
526 >                "Environment" ) or
527 >                $self->error("Cannot find Environment file. Area Corrupted? ("
528 >                                .$self->location().")\n $!");
529 >        while ( <$fh> ) {
530 >           chomp;
531 >           next if /^#/;
532 >           next if /^\s*$/ ;
533 >           ($name, $value)=split /=/;
534 >           eval "\$self->{ENV}{${name}}=\"$value\"";
535 >        }
536 >        undef $fh;
537          
538 <        $self->checktag($name,$hashref,'url');
539 <        $self->addconfigitem($$hashref{'url'});
538 >        # -- set internal variables appropriately
539 >        if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} ) {
540 >          $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
541 >        }
542 >        if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} ) {
543 >          $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
544 >        }
545 >        if ( defined $self->{ENV}{"projconfigdir"} ) {
546 >          $self->configurationdir($self->{ENV}{projconfigdir});
547 >        }
548 >        if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} ) {
549 >          $self->requirementsdoc($self->{ENV}{SCRAM_ProjReqsDoc});
550 >        }
551 >        if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
552 >                        ($self->{ENV}{"RELEASETOP"} ne $self->location())) {
553 >          $self->linkto($self->{ENV}{"RELEASETOP"});
554 >        }
555 >        else {
556 >          $self->{ENV}{"RELEASETOP"}=$self->location();
557 >        }
558   }
487

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines