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

Comparing COMP/SCRAM/src/Configuration/ConfigArea.pm (file contents):
Revision 1.11 by williamc, Thu Feb 24 14:24:29 2000 UTC vs.
Revision 1.29 by sashby, Thu Mar 10 12:39:28 2005 UTC

# Line 1 | Line 1
1   #
2   # ConfigArea.pm
3   #
4 < # Originally Written by Christopher Williams
4 > # Written by Christopher Williams
5   #
6   # Description
7   # -----------
8   # creates and manages a configuration area
9   #
10 < # 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 >        $self->{tbupdate}=0;
67 >        undef $self->{linkarea};
68 >
69 >        return $self;
70   }
71  
72 < sub basearea {
72 > sub cache {
73          my $self=shift;
74  
87        my $area;
75          if ( @_ ) {
76 <          $area=shift;
90 <          $self->config()->store($area,"BaseArea");
76 >           $self->{cache}=shift;
77          }
78 <        else {
79 <          ($area)=$self->config()->restore("BaseArea");
78 >        if ( ! defined $self->{cache} ) {
79 >          my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
80 >          if ( -e $loc  ) {
81 >            $self->{cache}=URL::URLcache->new($loc);
82 >          }
83 >          else {
84 >            $self->{cache}=undef;
85 >          }
86          }
87 <        return $area;
87 >        return $self->{cache};
88   }
89  
90 < sub freebase {
90 > # Tool and project cache info:
91 > sub cacheinfo
92 >   {
93 >   my $self=shift;
94 >   print "\n","<ConfigArea> cacheinfo: ToolCache = ",$self->{toolcachefile},
95 >   ", ProjectCache = ",$self->{projectcachefile},"\n";
96 >   }
97 >
98 > sub toolcachename
99 >   {
100 >   my $self=shift;
101 >   return ($self->location()."/".$self->{admindir}."/".$ENV{SCRAM_ARCH}."/ToolCache.db");
102 >   }
103 >
104 > sub projectcachename
105 >   {
106 >   my $self=shift;
107 >   return ($self->location()."/".$self->{admindir}."/".$ENV{SCRAM_ARCH}."/ProjectCache.db");
108 >   }
109 >
110 > sub _tbupdate
111 >   {
112 >   # Update toolbox relative to new RequirementsDoc:
113 >   my $self=shift;
114 >   @_?$self->{tbupdate}=shift
115 >      :$self->{tbupdate};
116 >   }
117 >
118 > sub _newcache {
119          my $self=shift;
120 <        $self->config()->delete("BaseArea");
120 >        my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
121 >        $self->{cache}=URL::URLcache->new($loc);
122 >        return $self->{cache};
123   }
124  
125 < sub defaultdirname {
125 > sub _newobjectstore {
126          my $self=shift;
127 <        my $name=$self->name();
128 <        my $vers=$self->version();
129 <        $vers=~s/^$name\_//;
108 <        $name=$name."_".$vers;
109 <        return $name;
127 >        my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
128 >        $self->{dbstore}=ObjectUtilities::ObjectStore->new($loc);
129 >        return $self->{dbstore};
130   }
131  
132 <
113 < sub setup {
132 > sub objectstore {
133          my $self=shift;
134  
135 <        # --- find out the location - default is cwd
136 <        my $location=$self->option("ConfigArea_location");
118 <        if ( ! defined $location ) {
119 <                $location=cwd();
120 <        }
121 <        elsif ( $location!~/^\// ) {
122 <                $location=cwd()."/".$location;
135 >        if ( @_ ) {
136 >            $self->{dbstore}=shift;
137          }
138 <
139 <        # --- find area directory name , default name projectname_version
140 <        my $name=$self->option("ConfigArea_name");
141 <        if ( ! defined $name ) {
142 <          $name=$self->defaultdirname();
138 >        if ( ! defined $self->{dbstore} ) {
139 >          my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
140 >          if ( -e $loc ) {
141 >            $self->{dbstore}=ObjectUtilities::ObjectStore->new($loc);
142 >          }
143 >          else {
144 >            $self->{dbstore}=undef;
145 >          }
146          }
147 <        $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());
147 >        return $self->{dbstore}
148   }
149  
150 < sub structure {
150 > sub name {
151          my $self=shift;
152 <        my $vr=shift;
153 <        return $self->{structures}{$vr};
152 >        @_?$self->{name}=shift
153 >          :$self->{name};
154   }
155  
156 < sub structurelist {
156 > sub version {
157          my $self=shift;
158 <        return ( keys %{$self->{structures}} );
158 >        @_?$self->{version}=shift
159 >          :$self->{version};
160   }
161  
162 < sub _setupstore {
162 > sub setup {
163          my $self=shift;
164 +        my $location=shift;
165 +        my $areaname;
166  
167 <        # --- make a new ConfigStore at the location and add it to the db list
168 <        my $ad=Configuration::ConfigStore->new($self->location().
169 <                                "/".$self->{admindir}, $self->arch());
167 >        # -- check we have a project name and version
168 >        my $name=$self->name();
169 >        my $vers=$self->version();
170 >        
171 >        if ( ( ! defined $name ) && ( ! defined $version )) {
172 >          $self->error("Set ConfigArea name and version before setup");
173 >        }
174 >
175 >        # -- check arguments and set location
176 >        if ( ! defined $location ) {
177 >          $self->error("ConfigArea: Cannot setup new area without a location");
178 >        }
179 >        if ( @_ ) {
180 >          $areaname=shift;
181 >        }
182 >        if ( (! defined $areaname) || ( $areaname eq "" ) ) {
183 >          # -- make up a name from the project name and version
184 >          $vers=~s/^$name\_//;
185 >          $areaname=$name."_".$vers;
186 >        }
187 >        my $arealoc=$location."/".$areaname;
188 >        my $workloc=$arealoc."/".$self->{admindir};
189 >        $self->verbose("Building at $arealoc");
190 >        $self->location($arealoc);
191 >
192 >        # -- create top level structure and work area
193 >        AddDir::adddir($workloc);
194 >
195 >        # -- add a cache
196 >        $self->_newcache();
197 >
198 >        # -- add an Objectstore
199 >        $self->_newobjectstore();
200 >
201 >        # -- Save Environment File
202 >        $self->_SaveEnvFile();
203  
168        $self->parentconfig($self->config());
169 #        $self->config(Configuration::ConfigureStore->new());
170 #        $self->config()->db("local",$ad);
171 #        $self->config()->db("parent",$self->parentconfig());
172 #        $self->config()->policy("cache","local");
173        $self->config($ad);
174        $self->config()->basedoc($self->parentconfig()->basedoc());
204   }
205  
206 < sub bootstrapfromlocation {
206 > sub configurationdir {
207          my $self=shift;
208 <        
209 <        if ( ! defined $self->location(@_) ) {
181 <          $self->error("Unable to locate the top of local configuration area");
208 >        if ( @_ ) {
209 >          $self->{configurationdir}=shift;
210          }
211 <        print "Found top ".$self->location()."\n";
184 <        $self->_setupstore();
185 <        $self->restore($self->location()."/".$self->{admindir}.
186 <                                                "/ConfigArea.dat");
211 >        return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
212   }
213  
214 < sub parentconfig {
214 > sub sourcedir {
215          my $self=shift;
216 <        @_?$self->{parentconfig}=shift
217 <          :$self->{parentconfig};
216 >        if ( @_ ) {
217 >          $self->{sourcedir}=shift;
218 >        }
219 >        return (defined $self->{sourcedir})?$self->{sourcedir}:undef;
220   }
221  
222 < sub store {
222 > sub toolbox {
223          my $self=shift;
224 <        my $location=shift;
225 <
226 <        my $fh=$self->openfile(">".$location);
227 <        $self->savevar($fh,"location", $self->location());
201 <        $self->savevar($fh,"url", $self->url());
202 <        $self->savevar($fh,"name", $self->name());
203 <        $self->savevar($fh,"version", $self->version());
204 <        $fh->close();
205 <
206 <        $self->_storestructures();
224 >        if ( ! defined $self->{toolbox} ) {
225 >          $self->{toolbox}=BuildSystem::ToolBox->new($self, $ENV{SCRAM_ARCH});
226 >        }
227 >        return $self->{toolbox};
228   }
229  
230 < sub satellite {
230 > sub toolboxversion {
231          my $self=shift;
232 <        my $newarea=$self->copy(@_);
233 <        $newarea->_makesatellites();
234 <        return $newarea;
232 >        if ( @_ ) {
233 >          $self->{toolboxversion}=shift;
234 >        }
235 >        return (defined $self->{toolboxversion})?$self->{toolboxversion}:undef;
236   }
237  
238 < sub copy {
238 > sub requirementsdoc {
239          my $self=shift;
218        use File::Basename;
219        # create the area
220
221        my $destination;
240          if ( @_ ) {
241 <         $destination=shift;
241 >          $self->{reqdoc}=shift;
242 >        }
243 >        if ( defined $self->{reqdoc} ) {
244 >          return $self->location()."/".$self->{reqdoc};
245          }
246          else {
247 <          my($location,$name)=$self->_defaultoptions();
227 <          $destination=$location."/".$name
247 >          return undef;
248          }
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;
249   }
250  
251 < sub restore {
251 > sub scramversion {
252          my $self=shift;
253 <        my $location=shift;
254 <
255 <        my $fh=$self->openfile("<".$location);
256 <        my $varhash={};
257 <        $self->restorevars($fh,$varhash);
258 <        if ( ! defined $self->location() ) {
259 <          $self->location($$varhash{"location"});
260 <        }
261 <        $self->_setupstore();
262 <        $self->url($$varhash{"url"});
263 <        $self->name($$varhash{"name"});
264 <        $self->version($$varhash{"version"});
265 <        $fh->close();
266 <
260 <        $self->_restorestructures();
253 >        if ( ! defined $self->{scramversion} ) {
254 >          my $filename=$self->location()."/".$self->configurationdir()."/".
255 >                                                        "scram_version";
256 >          if ( -f $filename ) {
257 >            use FileHandle;
258 >            $fh=FileHandle->new();
259 >            open ($fh, "<".$filename);
260 >            my $version=<$fh>;
261 >            chomp $version;
262 >            $self->{scramversion}=$version;
263 >            undef $fh;
264 >          }
265 >        }
266 >        return $self->{scramversion};
267   }
268  
269 < sub name {
270 <        my $self=shift;
269 > sub sitename
270 >   {
271 >   ###############################################################
272 >   # sitename()                                                  #
273 >   ###############################################################
274 >   # modified : Mon Dec  3 15:45:35 2001 / SFA                   #
275 >   # params   :                                                  #
276 >   #          :                                                  #
277 >   #          :                                                  #
278 >   #          :                                                  #
279 >   # function : Read the site name from config/site/sitename and #
280 >   #          : export it.                                       #
281 >   #          :                                                  #
282 >   #          :                                                  #
283 >   ###############################################################
284 >   my $self = shift;
285 >   my $sitefile = $self->location()."/".$self->configurationdir()."/site/sitename";
286 >
287 >   $self->{sitename} = 'CERN'; # Use CERN as the default site name
288 >
289 >   use FileHandle;
290 >   my $sitefh = FileHandle->new();
291 >
292 >   # Be verbose and print file we're going to read:
293 >   $self->verbose(">> Going to try to get sitename from: ".$sitefile." ");
294 >  
295 >   # See if we can read from the file. If not, just
296 >   # use default site name:
297 >   open($sitefh,"<".$sitefile) ||
298 >      do
299 >         {
300 >         $self->verbose(">> Unable to read a site name definition file. Using \'CERN\' as the site name.");
301 >         return $self->{sitename};
302 >         };
303 >  
304 >   $sitename = <$sitefh>;
305 >   chomp($sitename);
306 >   $self->{sitename} = $sitename;
307 >  
308 >   # Close the file (be tidy!);
309 >   close($sitefile);
310 >   # Return:
311 >   return $self->{sitename};
312 >   }
313 >
314 > sub admindir()
315 >   {
316 >   my $self=shift;
317 >  
318 >   @_ ? $self->{admindir} = shift
319 >      : $self->{admindir};
320 >   }
321  
322 <        @_?$self->{name}=shift
267 <          :$self->{name};
268 < }
269 <
270 < sub version {
322 > sub bootstrapfromlocation {
323          my $self=shift;
324  
325 <        @_?$self->{version}=shift
326 <          :$self->{version};
325 >        my $rv=0;
326 >        
327 >        my $location;
328 >        if ( ! defined ($location=$self->searchlocation(@_)) ) {
329 >         $rv=1;
330 >         $self->verbose("Unable to locate the top of local configuration area");
331 >        }
332 >        else {
333 >         $self->location($location);
334 >         $self->verbose("Found top ".$self->location());
335 >         $self->_LoadEnvFile();
336 >        }
337 >        return $rv;
338   }
339  
340   sub location {
# Line 289 | Line 352 | sub location {
352  
353   sub searchlocation {
354          my $self=shift;
355 <
355 >        
356          #start search in current directory if not specified
357          my $thispath;
358 <        @_?$thispath=shift
359 <          :$thispath=cwd();
360 <
358 >        if ( @_ ) {
359 >          $thispath=shift
360 >        }
361 >        else {
362 >          $thispath=cwd();
363 >        }
364 >        
365          my $rv=0;
366  
367 +        # chop off any files - we only want dirs
368 +        if ( -f $thispath ) {
369 +          $thispath=~s/(.*)\/.*/$1/;
370 +        }
371          Sloop:{
372          do {
373 < #         print "Searching $thispath\n";
373 >          $self->verbose("Searching $thispath");
374            if ( -e "$thispath/".$self->{admindir} ) {
375 < #           print "Found\n";
375 >            $self->verbose("Found\n");
376              $rv=1;
377              last Sloop;
378            }
379          } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
380 <
380 >      
381          return $rv?$thispath:undef;
382   }
383  
384 < sub meta {
384 > sub archname {
385          my $self=shift;
386 <
387 <        my $string=$self->name()." ".$self->version()." located at :\n  ".
388 <                $self->location;
386 >        if ( @_ ) {
387 >          $self->{archname}=shift;
388 >        }
389 >        return $self->{archname};
390   }
391  
392 < sub configitem {
392 > sub archdir {
393          my $self=shift;
394 <        
395 <        return ($self->config()->find("ConfigItem",@_));
394 >        if ( @_ ) {
395 >          $self->{archdir}=shift;
396 >        }
397 >        if ( ! defined $self->{archdir} ) {
398 >         if ( defined $self->{archname} ) {
399 >          $self->{archdir}=$self->location()."/".$self->{admindir}."/".
400 >                                                        $self->{archname};
401 >         }
402 >         else {
403 >          $self->error("ConfigArea : cannot create arch directory - ".
404 >                                                "architecture name not set")
405 >         }
406 >        }
407 >        return $self->{archdir};
408   }
409  
410 < sub addconfigitem {
410 > sub satellite {
411          my $self=shift;
328        my $url=shift;
412  
413 <        my $docref=$self->activatedoc($url);
414 <        # Set up the document
415 <        $docref->setup();
416 <        $docref->save();
417 < #       $self->config()->storepolicy("local");
418 < }
413 >        # -- create the sat object
414 >        my $sat=Configuration::ConfigArea->new();
415 >        $sat->name($self->name());
416 >        $sat->version($self->version());
417 >        $sat->requirementsdoc($self->{reqdoc});
418 >        $sat->configurationdir($self->configurationdir());
419 >        $sat->sourcedir($self->sourcedir());
420 >        $sat->toolboxversion($self->toolboxversion());
421 >        $sat->setup(@_);
422 >
423 >        # -- copy across the cache and ObjectStore
424 >        # -- make sure we dont try building new caches in release areas
425 >        my $rcache=$self->cache();
426 >        if ( defined $rcache ) {
427 >          copy($rcache->location(),$sat->cache()->location());
428 >        }
429 >
430 >        # -- make sure we dont try building new objectstores in release areas
431 >        my $rostore=$self->objectstore();
432 >        if ( defined $rostore ) {
433 >          copy($rostore->location(),$sat->objectstore()->location());
434 >        }
435  
436 < sub downloadtotop {
437 <        my $self=shift;
438 <        my $url=shift;
439 <        my $dir=shift;
436 >        # and make sure in reinitialises
437 >        undef ($sat->{cache});
438 >
439 >        # -- link it to this area
440 >        $sat->linkarea($self);
441          
442 <        # only download once
443 <        if ( ! -e $self->location()."/".$dir ) {
344 <          $self->{urlhandler}->download($url,$self->location()."/".$dir);
345 <        }
346 < }
442 >        # -- save it
443 >        $sat->save();
444  
445 < sub _makesatellites {
349 <        my $self=shift;
350 <        foreach $st ( values %{$self->{structures}} ) {
351 <           $st->setupsatellite()
352 <        }
445 >        return $sat;
446   }
447  
448 < sub _storestructures {
448 > sub copy {
449          my $self=shift;
450 <        foreach $struct ( values %{$self->{structures}} ) {
358 <          $self->config()->store($struct, "Structures", $struct->name());
359 <        }
360 < }
450 >        my $destination=shift;
451  
452 < sub _restorestructures {
453 <        my $self=shift;
454 <        my @strs=$self->config()->find("Structures");
365 <        foreach $struct ( @strs ) {
366 <          $struct->parent($self);
367 <          $self->{structures}{$struct->name()}=$struct;
368 <        }
452 >        # copy across the admin dir
453 >        my $temp=$self->location()."/".$self->{admindir};
454 >        AddDir::copydir($temp,"$destination/".$self->{admindir});
455   }
456  
457 < sub _defaultoptions {
457 > sub align {
458          my $self=shift;
459 <        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 <        }
459 >        use File::Copy;
460  
461 <        # --- find area directory name , default name projectname_version
462 <        $name=$self->option("ConfigArea_name");
463 <        if ( ! defined $name ) {
464 <          $name=$self->defaultdirname();
465 <        }
466 <        return ($location,$name);
461 >        $self->_LoadEnvFile();
462 >        my $Envfile=$self->location()."/".$self->{admindir}."/Environment";
463 >        my $tmpEnvfile=$Envfile.".bak";
464 >        my $rel=$self->{ENV}{RELEASETOP};
465 >        my $local=$self->location();
466 >
467 >        rename( $Envfile, $tmpEnvfile );
468 >        use FileHandle;
469 >        my $fh=FileHandle->new();
470 >        my $fout=FileHandle->new();
471 >        open ( $fh, "<".$tmpEnvfile ) or
472 >                $self->error("Cannot find Environment file. Area Corrupted? ("
473 >                                .$self->location().")\n $!");
474 >        open ( $fout, ">".$Envfile ) or
475 >                $self->error("Cannot find Environment file. Area Corrupted? ("
476 >                                .$self->location().")\n $!");
477 >        while ( <$fh> ) {
478 >          $_=~s/\Q$rel\L/$local/g;
479 >          print $fout $_;
480 >        }
481 >        undef $fh;
482 >        undef $fout;
483   }
392 # -------------- Tags ---------------------------------
393 # -- init parse
394 sub Project_Start {
395        my $self=shift;
396        my $name=shift;
397        my $hashref=shift;
484  
485 <        $self->checktag($name,$hashref,'name');
486 <        $self->checktag($name,$hashref,'version');
487 <
488 <        $self->name($$hashref{'name'});
489 <        $self->version($$hashref{'version'});
485 > sub copysetup {
486 >        my $self=shift;
487 >        my $dest=shift;
488 >        my $rv=1;
489 >        # copy across the admin dir
490 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
491 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
492 >        if ( $temp ne $temp2 ) {
493 >         if ( -d $temp ) {
494 >          AddDir::copydir($temp,$temp2);
495 >          $rv=0;
496 >         }
497 >        }
498 >        return $rv;
499   }
500  
501 <
407 < sub Project_text {
501 > sub copyurlcache {
502          my $self=shift;
503 <        my $name=shift;
504 <        my $string=shift;
505 <
506 <        print $string;
503 >        my $dest=shift;
504 >        my $rv=1;
505 >        # copy across the admin dir
506 >        my $temp=$self->location()."/".$self->{admindir}."/cache";
507 >        my $temp2=$dest."/".$self->{admindir}."/cache";
508 >        if ( $temp ne $temp2 ) {
509 >         if ( -d $temp ) {
510 >          AddDir::copydir($temp,$temp2);
511 >          $rv=0;
512 >         }
513 >        }
514 >        return $rv;
515 > }
516 >
517 > sub copywithskip {
518 >        my $self=shift;
519 >        my $dest=shift;
520 >        my ($filetoskip)=@_;            
521 >        my $rv=1;
522 >        # copy across the admin dir
523 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
524 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
525 >        if ( $temp ne $temp2 ) {
526 >         if ( -d $temp ) {
527 >          AddDir::copydirwithskip($temp,$temp2,$filetoskip);
528 >          $rv=0;
529 >         }
530 >        }
531 >        return $rv;
532   }
533  
534 < # ---- download parse
416 <
417 < sub Download_Start {
534 > sub copyenv {
535          my $self=shift;
536 <        my $name=shift;
537 <        my $hashref=shift;
538 <
539 <        $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");
536 >        my $hashref=shift;
537 >        
538 >        foreach $elem ( keys %{$self->{ENV}} ) {
539 >           $$hashref{$elem}=$self->{ENV}{$elem};
540          }
428        print "Downloading .... ".$$hashref{'url'}."\n";
429        $self->downloadtotop($$hashref{'url'},$$hashref{'location'});
541   }
542  
543 < sub Use_download_Start {
543 > sub arch {
544          my $self=shift;
545 <        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'});
545 >        return $ENV{SCRAM_ARCH};
546   }
547  
548 < # --- setup parse
443 <
444 < sub Structure_Start {
548 > sub linkto {
549          my $self=shift;
550 <        my $name=shift;
447 <        my $hashref=shift;
550 >        my $location=shift;
551  
552 <        $self->checktag($name,$hashref,'name');
553 <        if ( !(( exists $$hashref{'type'}) || ( exists $$hashref{'url'})) ) {
554 <            $self->parseerror("No url or type given in <$name> tag");
555 <        }
453 <        if ( ! exists $self->{structures}{$$hashref{'name'}} ) {
454 <          if ( exists $$hashref{'type'}) {
455 <            # create a new object of the specified type
456 <            eval "require $$hashref{'type'} ";
457 <            if  ( $@ ) {
458 <                $self->parseerror("Unable to instantiate type=".
459 <                        $$hashref{'type'}." in <$name> .".$@);
460 <            }
461 <            $self->{structures}{$$hashref{'name'}}=
462 <                $$hashref{'type'}->new($self->config());
463 <            $self->{structures}{$$hashref{'name'}}->name($$hashref{'name'});
464 <            $self->{structures}{$$hashref{'name'}}->parent($self);
465 <            $self->{structures}{$$hashref{'name'}}->vars($hashref);
466 <            $self->{structures}{$$hashref{'name'}}->arch($self->arch());
467 <          }
468 <          else { # its an activedoc
469 <                $self->{structures}{$$hashref{'name'}}=
470 <                                $self->activatedoc($$hashref{'url'});
471 <          }
472 <          $self->{structures}{$$hashref{'name'}}->setupbase();
552 >        if ( -d $location ) {
553 >        my $area=Configuration::ConfigArea->new();
554 >        $area->bootstrapfromlocation($location);
555 >        $self->linkarea($area);
556          }
557          else {
558 <             $self->parseerror("Multiply defined Structure - ".
559 <                                                        $$hashref{'name'});
558 >          $self->error("ConfigArea : Unable to link to non existing directory ".
559 >                         $location);
560          }
561   }
562  
563 < sub Use_Start {
563 > sub unlinkarea {
564          my $self=shift;
565 <        my $name=shift;
566 <        my $hashref=shift;
565 >        undef $self->{linkarea};
566 >        $self->{linkarea}=undef;
567 >        $self->save();
568 > }
569 >
570 > sub linkarea {
571 >        my $self=shift;
572 >        my $area=shift;
573 >        if ( defined $area ) {
574 >          $self->{linkarea}=$area;
575 >        }
576 >        return (defined $self->{linkarea} && $self->{linkarea} ne "")?
577 >                        $self->{linkarea}:undef;
578 > }
579 >
580 > sub save {
581 >        my $self=shift;
582 >        $self->_SaveEnvFile();
583 > }
584 >
585 > sub reqdoc()
586 >   {
587 >   my $self=shift;
588 >   my ($path)=@_;
589 >   return $path."/".$self->{reqdoc};
590 >   }
591 >
592 > sub creationtime()
593 >   {
594 >   my $self=shift;
595 >   my ($location)= @_;
596 >   $location||=$self->location();
597 >   my $requirementsdoc = $self->reqdoc($location);
598 >   my ($mode, $time) = (stat($requirementsdoc))[2, 9];
599 >   my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
600 >
601 >   ($sec < 10) ? ($sec = "0".$sec) : $sec;
602 >   ($min < 10) ? ($min = "0".$min) : $min;
603 >
604 >   $year += 1900;
605 >   my $months =
606 >      {
607 >      0 => "Jan", 1 => "Feb",
608 >      2 => "Mar", 3 => "Apr",
609 >      4 => "May", 5 => "Jun",
610 >      6 => "Jul", 7 => "Aug",
611 >      8 => "Sept", 9 => "Oct",
612 >      10 => "Nov", 11 => "Dec" };
613 >  
614 >   my $days = { 1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat", 7 => "Sun"};
615 >  
616 >   # Return the timestamp (as string) of the requirementsdoc:
617 >   return $days->{$wday}."-".$mday."-".$months->{$mon}."-".$year." ".$hour.":".$min.":".$sec;
618 >   }
619 >
620 > # ---- support routines
621 >
622 > sub _SaveEnvFile
623 >   {
624 >   my $self=shift;
625 >   my $filemode = 0644;
626 >  
627 >   use FileHandle;
628 >   my $fh=FileHandle->new();
629 >   open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
630 >          "Environment" ) or
631 >          $self->error("Cannot Open Environment file to Save ("
632 >                       .$self->location().")\n $!");
633          
634 <        $self->checktag($name,$hashref,'url');
635 <        $self->addconfigitem($$hashref{'url'});
636 < }
637 <
634 >   print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
635 >   print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
636 >   print $fh "SCRAM_CONFIGDIR=".$self->configurationdir()."\n";
637 >   print $fh "SCRAM_SOURCEDIR=".$self->sourcedir()."\n";
638 >   print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n";
639 >   print $fh "SCRAM_TOOLBOXVERSION=".$self->{toolboxversion}."\n";
640 >
641 >   if ( defined $self->linkarea() )
642 >      {
643 >      my $area=$self->linkarea()->location();
644 >      if ( $area ne "" )
645 >         {
646 >         print $fh "RELEASETOP=".$area."\n";
647 >         }
648 >      }
649 >  
650 >   undef $fh;
651 >  
652 >   # Set the default permissions (-rw-r--r--):
653 >   chmod $filemode, $self->location()."/".$self->{admindir}."/Environment";
654 >   }
655 >
656 > sub _LoadEnvFile
657 >   {
658 >   my $self=shift;
659 >
660 >   use FileHandle;
661 >   my $fh=FileHandle->new();
662 >   open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
663 >          "Environment" ) or
664 >          $self->error("Cannot find Environment file. Area Corrupted? ("
665 >                       .$self->location().")\n $!");
666 >   while ( <$fh> )
667 >      {
668 >      chomp;
669 >      next if /^#/;
670 >      next if /^\s*$/ ;
671 >      ($name, $value)=split /=/;
672 >      eval "\$self->{ENV}{${name}}=\"$value\"";
673 >      }
674 >   undef $fh;
675 >        
676 >   # -- set internal variables appropriately
677 >   if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} )
678 >      {
679 >      $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
680 >      }
681 >   if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} )
682 >      {
683 >      $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
684 >      }
685 >   if ( defined $self->{ENV}{"SCRAM_CONFIGDIR"} )
686 >      {
687 >      $self->configurationdir($self->{ENV}{"SCRAM_CONFIGDIR"});
688 >      }
689 >   if ( defined $self->{ENV}{"SCRAM_SOURCEDIR"} )
690 >      {
691 >      $self->sourcedir($self->{ENV}{"SCRAM_SOURCEDIR"});
692 >      }
693 >   if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} )
694 >      {
695 >      $self->requirementsdoc($self->{ENV}{"SCRAM_ProjReqsDoc"});
696 >      }
697 >   if ( defined $self->{ENV}{"SCRAM_TOOLBOXVERSION"} )
698 >      {
699 >      if ($self->{ENV}{"SCRAM_TOOLBOXVERSION"} eq '')
700 >         {
701 >         $self->toolboxversion("STANDALONE");
702 >         }
703 >      else
704 >         {
705 >         $self->toolboxversion($self->{ENV}{"SCRAM_TOOLBOXVERSION"});
706 >         }
707 >      }
708 >  
709 >   if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
710 >        ($self->{ENV}{"RELEASETOP"} ne $self->location()))
711 >      {
712 >      $self->linkto($self->{ENV}{"RELEASETOP"});
713 >      }
714 >   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines