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.32 by sashby, Tue Feb 27 12:46:01 2007 UTC

# Line 1 | Line 1
1 < #
2 < # ConfigArea.pm
3 < #
4 < # Originally Written by Christopher Williams
5 < #
6 < # Description
7 < # -----------
8 < # creates and manages a configuration area
9 < #
10 < # Options
11 < # -------
12 < # ConfigArea_location
13 < # ConfigArea_name
14 < #
15 < # Interface
16 < # ---------
17 < # new(ActiveConfig)             : A new ConfigArea object
18 < # setup()                       : setup the configuration area
19 < # location([dir])               : set/return the location of the area
20 < # version([version])            : set/return the version of the area
21 < # name([name])                  : set/return the name of the area
22 < # store(location)               : store data in file location
23 < # restore(location)             : restore data from file location
24 < # meta()                        : return a description string of the area
25 < # addconfigitem(url)            : add a new item to the area
26 < # 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
33 < # searchlocation([startdir])    : returns the location directory. search starts
34 < #                                 from cwd if not specified
35 < # defaultdirname()              : return the default directory name string
36 < # copy(location)                : make a copy of the current area at the
37 < #                                 specified location - defaults to cwd/default
38 < #                                 if not specified . ConfigArea_name,
39 < #                                 ConfigArea_location also override .
40 < #                                 Return an object representing the area
41 < # satellite()                   : make a satellite area based on $self
42 < # arch([archobj])               : Set/get the architecture object
43 < # structure(name)               : return the object corresponding to the
44 < #                                 structure name
45 < # structurelist()               : return list of structure objectS
46 < # downloadtotop(dir,url)        : download the url to a dir in the config area
47 < #                                
1 > =head1 NAME
2 >
3 > Configuration::ConfigArea - Creates and manages a configuration area (i.e. a project area).
4 >
5 > =head1 SYNOPSIS
6 >
7 >        my $obj = Configuration::ConfigArea->new();
8 >
9 > =head1 DESCRIPTION
10 >
11 > Create and manage SCRAM project configuration areas.
12 >
13 > =head1 METHODS
14 >
15 > =over
16 >
17 > =cut
18 >
19 > =item C<new()>
20 >
21 > Create a new Configuration::ConfigArea object.
22 >
23 > =item C<name()>
24 >
25 > Get/set project name.
26 >
27 > =item C<setup($dir[,$areaname])>
28 >
29 > Set up a fresh area in $dir.
30 >
31 > =item C<satellite($dir[,$areaname])>
32 >
33 > Set up a satellite area in $dir.
34 >
35 > =item C<version()>
36 >
37 > Get/set project version.
38 >
39 > =item C<location([$dir])>
40 >
41 > Set/return the location of the work area.
42 >
43 > =item C<bootstrapfromlocation([$location])>
44 >
45 > Bootstrap the object based on location.
46 > No location specified - current directory used
47 > Return 0 if succesful, 1 otherwise.
48 >
49 > =item C<requirementsdoc()>
50 >
51 > Get or set the requirements document.
52 >
53 > =item C<searchlocation([$startdir])>
54 >
55 > Returns the location directory. search starts
56 > from current directory if not specified.
57 >
58 > =item C<scramversion()>
59 >
60 > Return the scram version associated with the area.
61 >
62 > =item C<configurationdir()>
63 >
64 > Return the location of the project configuration directory.
65 >
66 > =item C<copy($location)>
67 >
68 > Copy a configuration from $location.
69 >
70 > =item C<copysetup($location)>
71 >
72 > Copy the architecture-specific tool setup.
73 > Returns 0 if successful, 1 otherwise.
74 >
75 > =item C<copyenv($ref)>
76 >
77 > Copy the area environment into the hashref $ref.
78 >
79 > =item C<toolbox()>
80 >
81 > Return the area toolbox object.
82 >
83 > =item C<save()>
84 >
85 > Save changes permanently.
86 >
87 > =item C<linkto($location)>
88 >
89 > Link the current area to that at location.
90 >
91 > =item C<unlinkarea()>
92 >
93 > Destroy link ($autosave).
94 >
95 > =item C<linkarea([Configuration::ConfigArea])>
96 >
97 > Link the current area to the specified area object.
98 >
99 > =item C<archname()>
100 >
101 > Get/set a string to indicate architecture.
102 >
103 > =item C<archdir()>
104 >
105 > Return the location of the administration
106 > architecture-dependent directory.
107 >
108 > =item C<objectstore()>
109 >
110 > Return the B<objectStore> object of the area temporary.
111 >
112 > =item C<align()>
113 >
114 > Adjust hard paths to suit local location.
115 >
116 >
117 > =back
118 >
119 > =head1 AUTHOR
120 >
121 > Originally written by Christopher Williams.
122 >  
123 > =head1 MAINTAINER
124 >
125 > Shaun ASHBY
126 >
127 > =cut
128  
129   package Configuration::ConfigArea;
50 use ActiveDoc::ActiveDoc;
130   require 5.004;
131 + use URL::URLcache;
132   use Utilities::AddDir;
133 + use Utilities::Verbose;
134   use ObjectUtilities::ObjectStore;
54 use Configuration::ConfigStore;
55 use Configuration::ActiveDoc_arch;
135   use Cwd;
136 < @ISA=qw(Configuration::ActiveDoc_arch ObjectUtilities::StorableObject);
136 > @ISA=qw(Utilities::Verbose);
137  
138 < sub init {
139 <        my $self=shift;
138 > sub new {
139 >    my $class=shift;
140 >    my $self={};
141 >    bless $self, $class;
142 >    
143 >    # data init
144 >    $self->{admindir}=".SCRAM";
145 >    $self->{cachedir}="cache";
146 >    $self->{dbdir}="ObjectDB";
147 >    $self->{tbupdate}=0;
148 >    undef $self->{linkarea};
149 >    
150 >    return $self;
151 > }
152 >
153 > sub cache {
154 >    my $self=shift;
155 >    
156 >    if ( @_ ) {
157 >        $self->{cache}=shift;
158 >    }
159 >    if ( ! defined $self->{cache} ) {
160 >        my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
161 >        if ( -e $loc  ) {
162 >            $self->{cache}=URL::URLcache->new($loc);
163 >        }
164 >        else {
165 >            $self->{cache}=undef;
166 >        }
167 >    }
168 >    return $self->{cache};
169 > }
170 >
171 > # Tool and project cache info:
172 > sub cacheinfo
173 >   {
174 >   my $self=shift;
175 >   print "\n","<ConfigArea> cacheinfo: ToolCache = ",$self->{toolcachefile},
176 >   ", ProjectCache = ",$self->{projectcachefile},"\n";
177 >   }
178 >
179 > sub toolcachename
180 >   {
181 >   my $self=shift;
182 >   return ($self->location()."/".$self->{admindir}."/".$ENV{SCRAM_ARCH}."/ToolCache.db");
183 >   }
184  
185 <        $self->newparse("init");
186 <        $self->newparse("download");
187 <        $self->newparse("setup");
188 <        $self->newparse("setup_tools");
189 <        $self->addarchtags("setup_tools");
190 <        $self->addarchtags("setup");
191 <        $self->addtag("init","project",\&Project_Start,$self,
192 <            \&Project_text,$self,"", $self );
193 <        $self->addurltags("download");
194 <        $self->addtag("download","download",\&Download_Start,$self,
195 <                                                "", $self, "",$self);
196 <        $self->addtag("download","use",\&Use_download_Start,$self,
197 <                                                "", $self, "",$self);
198 <        $self->addurltags("setup");
199 <        $self->addtag("setup_tools","use",\&Use_Start,$self, "", $self, "",$self);
200 <        $self->addtag("setup","structure",\&Structure_Start,$self,
201 <                         "", $self, "",$self);
185 > sub projectcachename
186 >   {
187 >   my $self=shift;
188 >   return ($self->location()."/".$self->{admindir}."/".$ENV{SCRAM_ARCH}."/ProjectCache.db");
189 >   }
190 >
191 > sub _tbupdate
192 >   {
193 >   # Update toolbox relative to new RequirementsDoc:
194 >   my $self=shift;
195 >   @_?$self->{tbupdate}=shift
196 >      :$self->{tbupdate};
197 >   }
198 >
199 > sub _newcache {
200 >        my $self=shift;
201 >        my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
202 >        $self->{cache}=URL::URLcache->new($loc);
203 >        return $self->{cache};
204 > }
205  
206 <        # data init
207 <        $self->{admindir}=".SCRAM";
206 > sub _newobjectstore {
207 >        my $self=shift;
208 >        my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
209 >        $self->{dbstore}=ObjectUtilities::ObjectStore->new($loc);
210 >        return $self->{dbstore};
211   }
212  
213 < sub basearea {
213 > sub objectstore {
214          my $self=shift;
215  
87        my $area;
216          if ( @_ ) {
217 <          $area=shift;
90 <          $self->config()->store($area,"BaseArea");
217 >            $self->{dbstore}=shift;
218          }
219 <        else {
220 <          ($area)=$self->config()->restore("BaseArea");
219 >        if ( ! defined $self->{dbstore} ) {
220 >          my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
221 >          if ( -e $loc ) {
222 >            $self->{dbstore}=ObjectUtilities::ObjectStore->new($loc);
223 >          }
224 >          else {
225 >            $self->{dbstore}=undef;
226 >          }
227          }
228 <        return $area;
228 >        return $self->{dbstore}
229   }
230  
231 < sub freebase {
231 > sub name {
232          my $self=shift;
233 <        $self->config()->delete("BaseArea");
233 >        @_?$self->{name}=shift
234 >          :$self->{name};
235   }
236  
237 < sub defaultdirname {
237 > sub version {
238          my $self=shift;
239 <        my $name=$self->name();
240 <        my $vers=$self->version();
107 <        $vers=~s/^$name\_//;
108 <        $name=$name."_".$vers;
109 <        return $name;
239 >        @_?$self->{version}=shift
240 >          :$self->{version};
241   }
242  
112
243   sub setup {
244          my $self=shift;
245 +        my $location=shift;
246 +        my $areaname;
247 +
248 +        # -- check we have a project name and version
249 +        my $name=$self->name();
250 +        my $vers=$self->version();
251 +        
252 +        if ( ( ! defined $name ) && ( ! defined $version )) {
253 +          $self->error("Set ConfigArea name and version before setup");
254 +        }
255  
256 <        # --- find out the location - default is cwd
117 <        my $location=$self->option("ConfigArea_location");
256 >        # -- check arguments and set location
257          if ( ! defined $location ) {
258 <                $location=cwd();
258 >          $self->error("ConfigArea: Cannot setup new area without a location");
259          }
260 <        elsif ( $location!~/^\// ) {
261 <                $location=cwd()."/".$location;
260 >        if ( @_ ) {
261 >          $areaname=shift;
262          }
263 <
264 <        # --- find area directory name , default name projectname_version
265 <        my $name=$self->option("ConfigArea_name");
266 <        if ( ! defined $name ) {
128 <          $name=$self->defaultdirname();
263 >        if ( (! defined $areaname) || ( $areaname eq "" ) ) {
264 >          # -- make up a name from the project name and version
265 >          $vers=~s/^$name\_//;
266 >          $areaname=$name."_".$vers;
267          }
268 <        $self->location($location."/".$name);
268 >        my $arealoc=$location."/".$areaname;
269 >        my $workloc=$arealoc."/".$self->{admindir};
270 >        $self->verbose("Building at $arealoc");
271 >        $self->location($arealoc);
272  
273 <        # make a new store handler
274 <        $self->_setupstore();
273 >        # -- create top level structure and work area
274 >        AddDir::adddir($workloc);
275  
276 <        # --- download everything first
277 <        $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");
276 >        # -- add a cache
277 >        $self->_newcache();
278  
279 <        # --- store self in original database
280 <        $self->parentconfig()->store($self,"ConfigArea",$self->name(),
147 <                                                        $self->version());
148 < }
279 >        # -- add an Objectstore
280 >        $self->_newobjectstore();
281  
282 < sub structure {
283 <        my $self=shift;
152 <        my $vr=shift;
153 <        return $self->{structures}{$vr};
154 < }
282 >        # -- Save Environment File
283 >        $self->_SaveEnvFile();
284  
156 sub structurelist {
157        my $self=shift;
158        return ( keys %{$self->{structures}} );
285   }
286  
287 < sub _setupstore {
287 > sub configurationdir {
288          my $self=shift;
289 <
290 <        # --- make a new ConfigStore at the location and add it to the db list
165 <        my $ad=Configuration::ConfigStore->new($self->location().
166 <                                "/".$self->{admindir}, $self->arch());
167 <
168 <        $self->parentconfig($self->config());
169 < #        $self->config(Configuration::ConfigureStore->new());
170 < #        $self->config()->db("local",$ad);
171 < #        $self->config()->db("parent",$self->parentconfig());
172 < #        $self->config()->policy("cache","local");
173 <        $self->config($ad);
174 <        $self->config()->basedoc($self->parentconfig()->basedoc());
175 < }
176 <
177 < sub bootstrapfromlocation {
178 <        my $self=shift;
179 <        
180 <        if ( ! defined $self->location(@_) ) {
181 <          $self->error("Unable to locate the top of local configuration area");
289 >        if ( @_ ) {
290 >          $self->{configurationdir}=shift;
291          }
292 <        print "Found top ".$self->location()."\n";
184 <        $self->_setupstore();
185 <        $self->restore($self->location()."/".$self->{admindir}.
186 <                                                "/ConfigArea.dat");
292 >        return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
293   }
294  
295 < sub parentconfig {
295 > sub sourcedir {
296          my $self=shift;
297 <        @_?$self->{parentconfig}=shift
298 <          :$self->{parentconfig};
297 >        if ( @_ ) {
298 >          $self->{sourcedir}=shift;
299 >        }
300 >        return (defined $self->{sourcedir})?$self->{sourcedir}:undef;
301   }
302  
303 < sub store {
303 > sub toolbox {
304          my $self=shift;
305 <        my $location=shift;
306 <
307 <        my $fh=$self->openfile(">".$location);
308 <        $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();
305 >        if ( ! defined $self->{toolbox} ) {
306 >          $self->{toolbox}=BuildSystem::ToolBox->new($self, $ENV{SCRAM_ARCH});
307 >        }
308 >        return $self->{toolbox};
309   }
310  
311 < sub satellite {
311 > sub toolboxversion {
312          my $self=shift;
313 <        my $newarea=$self->copy(@_);
314 <        $newarea->_makesatellites();
315 <        return $newarea;
313 >        if ( @_ ) {
314 >          $self->{toolboxversion}=shift;
315 >        }
316 >        return (defined $self->{toolboxversion})?$self->{toolboxversion}:undef;
317   }
318  
319 < sub copy {
319 > sub requirementsdoc {
320          my $self=shift;
218        use File::Basename;
219        # create the area
220
221        my $destination;
321          if ( @_ ) {
322 <         $destination=shift;
322 >          $self->{reqdoc}=shift;
323 >        }
324 >        if ( defined $self->{reqdoc} ) {
325 >          return $self->location()."/".$self->{reqdoc};
326          }
327          else {
328 <          my($location,$name)=$self->_defaultoptions();
227 <          $destination=$location."/".$name
328 >          return undef;
329          }
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;
330   }
331  
332 < sub restore {
332 > sub scramversion {
333          my $self=shift;
334 <        my $location=shift;
335 <
336 <        my $fh=$self->openfile("<".$location);
337 <        my $varhash={};
338 <        $self->restorevars($fh,$varhash);
339 <        if ( ! defined $self->location() ) {
340 <          $self->location($$varhash{"location"});
341 <        }
342 <        $self->_setupstore();
343 <        $self->url($$varhash{"url"});
344 <        $self->name($$varhash{"name"});
345 <        $self->version($$varhash{"version"});
346 <        $fh->close();
347 <
260 <        $self->_restorestructures();
334 >        if ( ! defined $self->{scramversion} ) {
335 >          my $filename=$self->location()."/".$self->configurationdir()."/".
336 >                                                        "scram_version";
337 >          if ( -f $filename ) {
338 >            use FileHandle;
339 >            $fh=FileHandle->new();
340 >            open ($fh, "<".$filename);
341 >            my $version=<$fh>;
342 >            chomp $version;
343 >            $self->{scramversion}=$version;
344 >            undef $fh;
345 >          }
346 >        }
347 >        return $self->{scramversion};
348   }
349  
350 < sub name {
351 <        my $self=shift;
352 <
353 <        @_?$self->{name}=shift
354 <          :$self->{name};
355 < }
350 > sub sitename
351 >   {
352 >   ###############################################################
353 >   # sitename()                                                  #
354 >   ###############################################################
355 >   # modified : Mon Dec  3 15:45:35 2001 / SFA                   #
356 >   # params   :                                                  #
357 >   #          :                                                  #
358 >   #          :                                                  #
359 >   #          :                                                  #
360 >   # function : Read the site name from config/site/sitename and #
361 >   #          : export it.                                       #
362 >   #          :                                                  #
363 >   #          :                                                  #
364 >   ###############################################################
365 >   my $self = shift;
366 >   my $sitefile = $self->location()."/".$self->configurationdir()."/site/sitename";
367 >
368 >   $self->{sitename} = 'CERN'; # Use CERN as the default site name
369 >
370 >   use FileHandle;
371 >   my $sitefh = FileHandle->new();
372 >
373 >   # Be verbose and print file we're going to read:
374 >   $self->verbose(">> Going to try to get sitename from: ".$sitefile." ");
375 >  
376 >   # See if we can read from the file. If not, just
377 >   # use default site name:
378 >   open($sitefh,"<".$sitefile) ||
379 >      do
380 >         {
381 >         $self->verbose(">> Unable to read a site name definition file. Using \'CERN\' as the site name.");
382 >         return $self->{sitename};
383 >         };
384 >  
385 >   $sitename = <$sitefh>;
386 >   chomp($sitename);
387 >   $self->{sitename} = $sitename;
388 >  
389 >   # Close the file (be tidy!);
390 >   close($sitefile);
391 >   # Return:
392 >   return $self->{sitename};
393 >   }
394 >
395 > sub admindir()
396 >   {
397 >   my $self=shift;
398 >  
399 >   @_ ? $self->{admindir} = shift
400 >      : $self->{admindir};
401 >   }
402  
403 < sub version {
403 > sub bootstrapfromlocation {
404          my $self=shift;
405  
406 <        @_?$self->{version}=shift
407 <          :$self->{version};
406 >        my $rv=0;
407 >        
408 >        my $location;
409 >        if ( ! defined ($location=$self->searchlocation(@_)) ) {
410 >         $rv=1;
411 >         $self->verbose("Unable to locate the top of local configuration area");
412 >        }
413 >        else {
414 >         $self->location($location);
415 >         $self->verbose("Found top ".$self->location());
416 >         $self->_LoadEnvFile();
417 >        }
418 >        return $rv;
419   }
420  
421   sub location {
# Line 289 | Line 433 | sub location {
433  
434   sub searchlocation {
435          my $self=shift;
436 <
436 >        
437          #start search in current directory if not specified
438          my $thispath;
439 <        @_?$thispath=shift
440 <          :$thispath=cwd();
441 <
439 >        if ( @_ ) {
440 >          $thispath=shift
441 >        }
442 >        else {
443 >          $thispath=cwd();
444 >        }
445 >        
446          my $rv=0;
447  
448 +        # chop off any files - we only want dirs
449 +        if ( -f $thispath ) {
450 +          $thispath=~s/(.*)\/.*/$1/;
451 +        }
452          Sloop:{
453          do {
454 < #         print "Searching $thispath\n";
454 >          $self->verbose("Searching $thispath");
455            if ( -e "$thispath/".$self->{admindir} ) {
456 < #           print "Found\n";
456 >            $self->verbose("Found\n");
457              $rv=1;
458              last Sloop;
459            }
460          } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
461 <
461 >      
462          return $rv?$thispath:undef;
463   }
464  
465 < sub meta {
465 > sub archname {
466          my $self=shift;
467 <
468 <        my $string=$self->name()." ".$self->version()." located at :\n  ".
469 <                $self->location;
467 >        if ( @_ ) {
468 >          $self->{archname}=shift;
469 >        }
470 >        return $self->{archname};
471   }
472  
473 < sub configitem {
473 > sub archdir {
474          my $self=shift;
475 <        
476 <        return ($self->config()->find("ConfigItem",@_));
475 >        if ( @_ ) {
476 >          $self->{archdir}=shift;
477 >        }
478 >        if ( ! defined $self->{archdir} ) {
479 >         if ( defined $self->{archname} ) {
480 >          $self->{archdir}=$self->location()."/".$self->{admindir}."/".
481 >                                                        $self->{archname};
482 >         }
483 >         else {
484 >          $self->error("ConfigArea : cannot create arch directory - ".
485 >                                                "architecture name not set")
486 >         }
487 >        }
488 >        return $self->{archdir};
489   }
490  
491 < sub addconfigitem {
491 > sub satellite {
492          my $self=shift;
328        my $url=shift;
493  
494 <        my $docref=$self->activatedoc($url);
495 <        # Set up the document
496 <        $docref->setup();
497 <        $docref->save();
498 < #       $self->config()->storepolicy("local");
499 < }
494 >        # -- create the sat object
495 >        my $sat=Configuration::ConfigArea->new();
496 >        $sat->name($self->name());
497 >        $sat->version($self->version());
498 >        $sat->requirementsdoc($self->{reqdoc});
499 >        $sat->configurationdir($self->configurationdir());
500 >        $sat->sourcedir($self->sourcedir());
501 >        $sat->toolboxversion($self->toolboxversion());
502 >        $sat->setup(@_);
503 >
504 >        # -- copy across the cache and ObjectStore
505 >        # -- make sure we dont try building new caches in release areas
506 >        my $rcache=$self->cache();
507 >        if ( defined $rcache ) {
508 >          copy($rcache->location(),$sat->cache()->location());
509 >        }
510 >
511 >        # -- make sure we dont try building new objectstores in release areas
512 >        my $rostore=$self->objectstore();
513 >        if ( defined $rostore ) {
514 >          copy($rostore->location(),$sat->objectstore()->location());
515 >        }
516  
517 < sub downloadtotop {
518 <        my $self=shift;
519 <        my $url=shift;
520 <        my $dir=shift;
517 >        # and make sure in reinitialises
518 >        undef ($sat->{cache});
519 >
520 >        # -- link it to this area
521 >        $sat->linkarea($self);
522          
523 <        # only download once
524 <        if ( ! -e $self->location()."/".$dir ) {
344 <          $self->{urlhandler}->download($url,$self->location()."/".$dir);
345 <        }
346 < }
523 >        # -- save it
524 >        $sat->save();
525  
526 < sub _makesatellites {
349 <        my $self=shift;
350 <        foreach $st ( values %{$self->{structures}} ) {
351 <           $st->setupsatellite()
352 <        }
526 >        return $sat;
527   }
528  
529 < sub _storestructures {
529 > sub copy {
530          my $self=shift;
531 <        foreach $struct ( values %{$self->{structures}} ) {
358 <          $self->config()->store($struct, "Structures", $struct->name());
359 <        }
360 < }
531 >        my $destination=shift;
532  
533 < sub _restorestructures {
534 <        my $self=shift;
535 <        my @strs=$self->config()->find("Structures");
365 <        foreach $struct ( @strs ) {
366 <          $struct->parent($self);
367 <          $self->{structures}{$struct->name()}=$struct;
368 <        }
533 >        # copy across the admin dir
534 >        my $temp=$self->location()."/".$self->{admindir};
535 >        AddDir::copydir($temp,"$destination/".$self->{admindir});
536   }
537  
538 < sub _defaultoptions {
538 > sub align {
539          my $self=shift;
540 <        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 <        }
540 >        use File::Copy;
541  
542 <        # --- find area directory name , default name projectname_version
543 <        $name=$self->option("ConfigArea_name");
544 <        if ( ! defined $name ) {
545 <          $name=$self->defaultdirname();
546 <        }
547 <        return ($location,$name);
542 >        $self->_LoadEnvFile();
543 >        my $Envfile=$self->location()."/".$self->{admindir}."/Environment";
544 >        my $tmpEnvfile=$Envfile.".bak";
545 >        my $rel=$self->{ENV}{RELEASETOP};
546 >        my $local=$self->location();
547 >
548 >        rename( $Envfile, $tmpEnvfile );
549 >        use FileHandle;
550 >        my $fh=FileHandle->new();
551 >        my $fout=FileHandle->new();
552 >        open ( $fh, "<".$tmpEnvfile ) or
553 >                $self->error("Cannot find Environment file. Area Corrupted? ("
554 >                                .$self->location().")\n $!");
555 >        open ( $fout, ">".$Envfile ) or
556 >                $self->error("Cannot find Environment file. Area Corrupted? ("
557 >                                .$self->location().")\n $!");
558 >        while ( <$fh> ) {
559 >          $_=~s/\Q$rel\L/$local/g;
560 >          print $fout $_;
561 >        }
562 >        undef $fh;
563 >        undef $fout;
564   }
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');
565  
566 <        $self->name($$hashref{'name'});
567 <        $self->version($$hashref{'version'});
566 > sub copysetup {
567 >        my $self=shift;
568 >        my $dest=shift;
569 >        my $rv=1;
570 >        # copy across the admin dir
571 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
572 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
573 >        if ( $temp ne $temp2 ) {
574 >         if ( -d $temp ) {
575 >          AddDir::copydir($temp,$temp2);
576 >          $rv=0;
577 >         }
578 >        }
579 >        return $rv;
580   }
581  
582 <
407 < sub Project_text {
582 > sub copyurlcache {
583          my $self=shift;
584 <        my $name=shift;
585 <        my $string=shift;
586 <
587 <        print $string;
584 >        my $dest=shift;
585 >        my $rv=1;
586 >        # copy across the admin dir
587 >        my $temp=$self->location()."/".$self->{admindir}."/cache";
588 >        my $temp2=$dest."/".$self->{admindir}."/cache";
589 >        if ( $temp ne $temp2 ) {
590 >         if ( -d $temp ) {
591 >          AddDir::copydir($temp,$temp2);
592 >          $rv=0;
593 >         }
594 >        }
595 >        return $rv;
596 > }
597 >
598 > sub copywithskip {
599 >        my $self=shift;
600 >        my $dest=shift;
601 >        my ($filetoskip)=@_;            
602 >        my $rv=1;
603 >        # copy across the admin dir
604 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
605 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
606 >        if ( $temp ne $temp2 ) {
607 >         if ( -d $temp ) {
608 >          AddDir::copydirwithskip($temp,$temp2,$filetoskip);
609 >          $rv=0;
610 >         }
611 >        }
612 >        return $rv;
613   }
614  
615 < # ---- download parse
416 <
417 < sub Download_Start {
615 > sub copyenv {
616          my $self=shift;
617 <        my $name=shift;
618 <        my $hashref=shift;
619 <
620 <        $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");
617 >        my $hashref=shift;
618 >        
619 >        foreach $elem ( keys %{$self->{ENV}} ) {
620 >           $$hashref{$elem}=$self->{ENV}{$elem};
621          }
428        print "Downloading .... ".$$hashref{'url'}."\n";
429        $self->downloadtotop($$hashref{'url'},$$hashref{'location'});
622   }
623  
624 < sub Use_download_Start {
624 > sub arch {
625          my $self=shift;
626 <        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'});
626 >        return $ENV{SCRAM_ARCH};
627   }
628  
629 < # --- setup parse
443 <
444 < sub Structure_Start {
629 > sub linkto {
630          my $self=shift;
631 <        my $name=shift;
447 <        my $hashref=shift;
631 >        my $location=shift;
632  
633 <        $self->checktag($name,$hashref,'name');
634 <        if ( !(( exists $$hashref{'type'}) || ( exists $$hashref{'url'})) ) {
635 <            $self->parseerror("No url or type given in <$name> tag");
636 <        }
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();
633 >        if ( -d $location ) {
634 >        my $area=Configuration::ConfigArea->new();
635 >        $area->bootstrapfromlocation($location);
636 >        $self->linkarea($area);
637          }
638          else {
639 <             $self->parseerror("Multiply defined Structure - ".
640 <                                                        $$hashref{'name'});
639 >          $self->error("ConfigArea : Unable to link to non existing directory ".
640 >                         $location);
641          }
642   }
643  
644 < sub Use_Start {
644 > sub unlinkarea {
645          my $self=shift;
646 <        my $name=shift;
647 <        my $hashref=shift;
646 >        undef $self->{linkarea};
647 >        $self->{linkarea}=undef;
648 >        $self->save();
649 > }
650 >
651 > sub linkarea {
652 >        my $self=shift;
653 >        my $area=shift;
654 >        if ( defined $area ) {
655 >          $self->{linkarea}=$area;
656 >        }
657 >        return (defined $self->{linkarea} && $self->{linkarea} ne "")?
658 >                        $self->{linkarea}:undef;
659 > }
660 >
661 > sub save {
662 >        my $self=shift;
663 >        $self->_SaveEnvFile();
664 > }
665 >
666 > sub reqdoc()
667 >   {
668 >   my $self=shift;
669 >   my ($path)=@_;
670 >   return $path."/".$self->{reqdoc};
671 >   }
672 >
673 > sub creationtime()
674 >   {
675 >   my $self=shift;
676 >   my ($location)= @_;
677 >   $location||=$self->location();
678 >   my $requirementsdoc = $self->reqdoc($location);
679 >   my ($mode, $time) = (stat($requirementsdoc))[2, 9];
680 >   my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
681 >
682 >   ($sec < 10) ? ($sec = "0".$sec) : $sec;
683 >   ($min < 10) ? ($min = "0".$min) : $min;
684 >
685 >   $year += 1900;
686 >   my $months =
687 >      {
688 >      0 => "Jan", 1 => "Feb",
689 >      2 => "Mar", 3 => "Apr",
690 >      4 => "May", 5 => "Jun",
691 >      6 => "Jul", 7 => "Aug",
692 >      8 => "Sept", 9 => "Oct",
693 >      10 => "Nov", 11 => "Dec" };
694 >  
695 >   my $days = { 1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat", 7 => "Sun"};
696 >  
697 >   # Return the timestamp (as string) of the requirementsdoc:
698 >   return $days->{$wday}."-".$mday."-".$months->{$mon}."-".$year." ".$hour.":".$min.":".$sec;
699 >   }
700 >
701 > # ---- support routines
702 >
703 > sub _SaveEnvFile
704 >   {
705 >   my $self=shift;
706 >   my $filemode = 0644;
707 >  
708 >   use FileHandle;
709 >   my $fh=FileHandle->new();
710 >   open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
711 >          "Environment" ) or
712 >          $self->error("Cannot Open Environment file to Save ("
713 >                       .$self->location().")\n $!");
714          
715 <        $self->checktag($name,$hashref,'url');
716 <        $self->addconfigitem($$hashref{'url'});
717 < }
718 <
715 >   print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
716 >   print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
717 >   print $fh "SCRAM_CONFIGDIR=".$self->configurationdir()."\n";
718 >   print $fh "SCRAM_SOURCEDIR=".$self->sourcedir()."\n";
719 >   print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n";
720 >   print $fh "SCRAM_TOOLBOXVERSION=".$self->{toolboxversion}."\n";
721 >
722 >   if ( defined $self->linkarea() )
723 >      {
724 >      my $area=$self->linkarea()->location();
725 >      if ( $area ne "" )
726 >         {
727 >         print $fh "RELEASETOP=".$area."\n";
728 >         }
729 >      }
730 >  
731 >   undef $fh;
732 >  
733 >   # Repeat the exercise to save as XML:
734 >   my $fh=FileHandle->new();
735 >   open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
736 >          "Environment.xml" ) or
737 >          $self->error("Cannot Open Environment.xml file to Save ("
738 >                       .$self->location().")\n $!");
739 >   print $fh "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
740 >   print $fh "<doc type=\"Configuration::ProjectEnvironment\" version=\"1.0\">\n";
741 >   print $fh " <environment SCRAM_PROJECTNAME=\"".$self->name()."\"/>\n";
742 >   print $fh " <environment SCRAM_PROJECTVERSION=\"".$self->version()."\"/>\n";
743 >   print $fh " <environment SCRAM_CONFIGDIR=\"".$self->configurationdir()."\"/>\n";
744 >   print $fh " <environment SCRAM_SOURCEDIR=\"".$self->sourcedir()."\"/>\n";
745 >   print $fh " <environment SCRAM_ProjReqsDoc=\"".$self->{reqdoc}."\"/>\n";
746 >   print $fh " <environment SCRAM_TOOLBOXVERSION=\"".$self->{toolboxversion}."\"/>\n";
747 >
748 >   if ( defined $self->linkarea() )
749 >      {
750 >      my $area=$self->linkarea()->location();
751 >      if ( $area ne "" )
752 >         {
753 >         print $fh " <environment RELEASETOP=\"".$area."\"/>\n";
754 >         }
755 >      }
756 >  
757 >   print $fh "</doc>\n";
758 >   undef $fh;
759 >  
760 >   # Set the default permissions (-rw-r--r--):
761 >   chmod $filemode, $self->location()."/".$self->{admindir}."/Environment";
762 >   chmod $filemode, $self->location()."/".$self->{admindir}."/Environment.xml";
763 >   }
764 >
765 > sub _LoadEnvFile
766 >   {
767 >   my $self=shift;
768 >
769 >   use FileHandle;
770 >   my $fh=FileHandle->new();
771 >   open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
772 >          "Environment" ) or
773 >          $self->error("Cannot find Environment file. Area Corrupted? ("
774 >                       .$self->location().")\n $!");
775 >   while ( <$fh> )
776 >      {
777 >      chomp;
778 >      next if /^#/;
779 >      next if /^\s*$/ ;
780 >      ($name, $value)=split /=/;
781 >      eval "\$self->{ENV}{${name}}=\"$value\"";
782 >      }
783 >   undef $fh;
784 >        
785 >   # -- set internal variables appropriately
786 >   if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} )
787 >      {
788 >      $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
789 >      }
790 >   if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} )
791 >      {
792 >      $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
793 >      }
794 >   if ( defined $self->{ENV}{"SCRAM_CONFIGDIR"} )
795 >      {
796 >      $self->configurationdir($self->{ENV}{"SCRAM_CONFIGDIR"});
797 >      }
798 >   if ( defined $self->{ENV}{"SCRAM_SOURCEDIR"} )
799 >      {
800 >      $self->sourcedir($self->{ENV}{"SCRAM_SOURCEDIR"});
801 >      }
802 >   if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} )
803 >      {
804 >      $self->requirementsdoc($self->{ENV}{"SCRAM_ProjReqsDoc"});
805 >      }
806 >   if ( defined $self->{ENV}{"SCRAM_TOOLBOXVERSION"} )
807 >      {
808 >      if ($self->{ENV}{"SCRAM_TOOLBOXVERSION"} eq '')
809 >         {
810 >         $self->toolboxversion("STANDALONE");
811 >         }
812 >      else
813 >         {
814 >         $self->toolboxversion($self->{ENV}{"SCRAM_TOOLBOXVERSION"});
815 >         }
816 >      }
817 >  
818 >   if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
819 >        ($self->{ENV}{"RELEASETOP"} ne $self->location()))
820 >      {
821 >      $self->linkto($self->{ENV}{"RELEASETOP"});
822 >      }
823 >   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines