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.3 by williamc, Fri Jan 21 08:59:34 2000 UTC vs.
Revision 1.34 by muzaffar, Fri Dec 14 09:03:54 2007 UTC

# Line 1 | Line 1
1 < #
2 < # ConfigArea.pm
3 < #
4 < # Originally Written by Christopher Williams
5 < #
6 < # Description
7 < #
8 < # Interface
9 < # ---------
10 < # new(ActiveConfig)             : A new ConfigArea object
11 < # setup()                       : setup the configuration area
12 < # location([dir])               : set/return the location of the area
13 < # version([version])            : set/return the version of the area
14 < # name([name])                  : set/return the name of the area
15 < # store(location)               : store data in file location
16 < # restore(location)             : restore data from file location
17 < # meta()                        : return a description string of the area
18 < # addconfigitem(url)            : add a new item to the area
19 < # configitem(@keys)             : return a list of fig items that match
20 < #                                 the keys - all if left blank
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;
23 use ActiveDoc::ActiveDoc;
130   require 5.004;
131 + use URL::URLcache;
132   use Utilities::AddDir;
133 + use Utilities::Verbose;
134   use ObjectUtilities::ObjectStore;
135 < @ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject);
135 > use Cwd;
136 > @ISA=qw(Utilities::Verbose);
137  
138 < sub init {
139 <        my $self=shift;
140 <        $self->newparse("init");
141 <        $self->newparse("download");
142 <        $self->newparse("setup");
143 <        $self->addtag("init","project",\&Project_Start,$self,
144 <        \&Project_text,$self,"", $self );
145 <        $self->addurltags("download");
146 <        $self->addtag("download","use",\&Use_download_Start,$self,
147 <                                                "", $self, "",$self);
148 <        $self->addurltags("setup");
149 <        $self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self);
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 setup {
153 > sub cache {
154          my $self=shift;
155  
156 <        # --- find out the location
157 <        my $location=$self->requestoption("area_location",
158 <                "Please Enter the location of the directory");
159 <
160 <        # --- find area directory name , default name projectname_version
161 <        my $name=$self->option("area_name");
162 <        my $vers=$self->version;
163 <        if ( ! defined $name ) {
164 <          $name=$self->name();
165 <          $vers=~s/^$name_//;
166 <          $name=$name."_".$vers;
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 <        $self->location($location."/".$name);
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 <        # make a new store handler
180 <        my $parentconfig=$self->_setupstore();
179 > sub toolcachename
180 >   {
181 >   my $self=shift;
182 >   return ($self->location()."/".$self->{admindir}."/".$ENV{SCRAM_ARCH}."/ToolCache.db");
183 >   }
184  
185 <        # --- download everything first
186 < # FIX-ME --- cacheing is broken
187 <        $self->parse("download");
188 <        
189 <        # --- and parse the setup file
190 <        $self->parse("setup");
191 <        
192 <        # --- store self in original database
193 <        $parentconfig->store($self,"ConfigArea",$self->name(),
194 <                                                        $self->version());
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 > 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 _setupstore {
213 > sub objectstore {
214          my $self=shift;
215  
216 <        # --- make a new ActiveStore at the location and add it to the db list
217 <        my $ad=ActiveDoc::ActiveConfig->new($self->location()."/\.SCRAM");
216 >        if ( @_ ) {
217 >            $self->{dbstore}=shift;
218 >        }
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 $self->{dbstore}
229 > }
230  
231 <        my $parentconfig=$self->config();
232 <        $self->config(Configuration::ConfigureStore->new());
233 <        $self->config()->db("local",$ad);
234 <        $self->config()->db("parent",$parentconfig);
86 <        $self->config()->policy("cache","local");
87 <        $self->config()->basedoc($parentconfig->basedoc());
88 <        return $parentconfig;
231 > sub symlinks {
232 >        my $self=shift;
233 >        if (@_) {$self->{symlinks}=shift;}
234 >        return $self->{symlinks};
235   }
236  
237 < sub store {
237 > sub name {
238 >        my $self=shift;
239 >        @_?$self->{name}=shift
240 >          :$self->{name};
241 > }
242 >
243 > sub version {
244 >        my $self=shift;
245 >        @_?$self->{version}=shift
246 >          :$self->{version};
247 > }
248 >
249 > sub setup {
250          my $self=shift;
251          my $location=shift;
252 +        my $areaname;
253 +        my $symlinks=0;
254 +
255 +        # -- check we have a project name and version
256 +        my $name=$self->name();
257 +        my $vers=$self->version();
258 +        
259 +        if ( ( ! defined $name ) && ( ! defined $version )) {
260 +          $self->error("Set ConfigArea name and version before setup");
261 +        }
262 +
263 +        # -- check arguments and set location
264 +        if ( ! defined $location ) {
265 +          $self->error("ConfigArea: Cannot setup new area without a location");
266 +        }
267 +        if ( @_ ) {
268 +          $areaname=shift;
269 +        }
270 +        if ( @_ ) {
271 +          $symlinks=shift || 0;
272 +        }
273 +        if ( (! defined $areaname) || ( $areaname eq "" ) ) {
274 +          # -- make up a name from the project name and version
275 +          $vers=~s/^$name\_//;
276 +          $areaname=$name."_".$vers;
277 +        }
278 +        my $arealoc=$location."/".$areaname;
279 +        my $workloc=$arealoc."/".$self->{admindir};
280 +        $self->verbose("Building at $arealoc");
281 +        $self->location($arealoc);
282 +        $self->symlinks($symlinks);
283 +
284 +        # -- create top level structure and work area
285 +        AddDir::adddir($workloc);
286 +
287 +        # -- add a cache
288 +        $self->_newcache();
289 +
290 +        # -- add an Objectstore
291 +        $self->_newobjectstore();
292 +
293 +        # -- Save Environment File
294 +        $self->_SaveEnvFile();
295  
95        my $fh=$self->openfile(">".$location);
96        print $fh $self->location()."\n";
97        $fh->close();
296   }
297  
298 < sub restore {
298 > sub configurationdir {
299          my $self=shift;
300 +        if ( @_ ) {
301 +          $self->{configurationdir}=shift;
302 +        }
303 +        return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
304 + }
305  
306 <        my $fh=$self->openfile("<".$location);
307 <        $self->{location}=<$fh>;
308 <        chomp $self->{location};
309 <        $fh->close();
306 > sub sourcedir {
307 >        my $self=shift;
308 >        if ( @_ ) {
309 >          $self->{sourcedir}=shift;
310 >        }
311 >        return (defined $self->{sourcedir})?$self->{sourcedir}:undef;
312 > }
313  
314 + sub toolbox {
315 +        my $self=shift;
316 +        if ( ! defined $self->{toolbox} ) {
317 +          $self->{toolbox}=BuildSystem::ToolBox->new($self, $ENV{SCRAM_ARCH});
318 +        }
319 +        return $self->{toolbox};
320   }
321  
322 < sub name {
322 > sub toolboxversion {
323          my $self=shift;
324 +        if ( @_ ) {
325 +          $self->{toolboxversion}=shift;
326 +        }
327 +        return (defined $self->{toolboxversion})?$self->{toolboxversion}:undef;
328 + }
329  
330 <        @_?$self->{name}=shift
331 <          :$self->{name};
330 > sub requirementsdoc {
331 >        my $self=shift;
332 >        if ( @_ ) {
333 >          $self->{reqdoc}=shift;
334 >        }
335 >        if ( defined $self->{reqdoc} ) {
336 >          return $self->location()."/".$self->{reqdoc};
337 >        }
338 >        else {
339 >          return undef;
340 >        }
341   }
342  
343 < sub version {
343 > sub scramversion {
344 >        my $self=shift;
345 >        if ( ! defined $self->{scramversion} ) {
346 >          my $filename=$self->location()."/".$self->configurationdir()."/".
347 >                                                        "scram_version";
348 >          if ( -f $filename ) {
349 >            use FileHandle;
350 >            $fh=FileHandle->new();
351 >            open ($fh, "<".$filename);
352 >            my $version=<$fh>;
353 >            chomp $version;
354 >            $self->{scramversion}=$version;
355 >            undef $fh;
356 >          }
357 >        }
358 >        return $self->{scramversion};
359 > }
360 >
361 > sub sitename
362 >   {
363 >   ###############################################################
364 >   # sitename()                                                  #
365 >   ###############################################################
366 >   # modified : Mon Dec  3 15:45:35 2001 / SFA                   #
367 >   # params   :                                                  #
368 >   #          :                                                  #
369 >   #          :                                                  #
370 >   #          :                                                  #
371 >   # function : Read the site name from config/site/sitename and #
372 >   #          : export it.                                       #
373 >   #          :                                                  #
374 >   #          :                                                  #
375 >   ###############################################################
376 >   my $self = shift;
377 >   my $sitefile = $self->location()."/".$self->configurationdir()."/site/sitename";
378 >
379 >   $self->{sitename} = 'CERN'; # Use CERN as the default site name
380 >
381 >   use FileHandle;
382 >   my $sitefh = FileHandle->new();
383 >
384 >   # Be verbose and print file we're going to read:
385 >   $self->verbose(">> Going to try to get sitename from: ".$sitefile." ");
386 >  
387 >   # See if we can read from the file. If not, just
388 >   # use default site name:
389 >   open($sitefh,"<".$sitefile) ||
390 >      do
391 >         {
392 >         $self->verbose(">> Unable to read a site name definition file. Using \'CERN\' as the site name.");
393 >         return $self->{sitename};
394 >         };
395 >  
396 >   $sitename = <$sitefh>;
397 >   chomp($sitename);
398 >   $self->{sitename} = $sitename;
399 >  
400 >   # Close the file (be tidy!);
401 >   close($sitefile);
402 >   # Return:
403 >   return $self->{sitename};
404 >   }
405 >
406 > sub admindir()
407 >   {
408 >   my $self=shift;
409 >  
410 >   @_ ? $self->{admindir} = shift
411 >      : $self->{admindir};
412 >   }
413 >
414 > sub bootstrapfromlocation {
415          my $self=shift;
416  
417 <        @_?$self->{version}=shift
418 <          :$self->{version};
417 >        my $rv=0;
418 >        
419 >        my $location;
420 >        if ( ! defined ($location=$self->searchlocation(@_)) ) {
421 >         $rv=1;
422 >         $self->verbose("Unable to locate the top of local configuration area");
423 >        }
424 >        else {
425 >         $self->location($location);
426 >         $self->verbose("Found top ".$self->location());
427 >         $self->_LoadEnvFile();
428 >        }
429 >        return $rv;
430   }
431  
432   sub location {
433          my $self=shift;
434  
435 <        @_?$self->{location}=shift
436 <          :$self->{location};
435 >        if ( @_ ) {
436 >          $self->{location}=shift;
437 >        }
438 >        elsif ( ! defined $self->{location} ) {
439 >          # try and find the release location
440 >          $self->{location}=$self->searchlocation();
441 >        }
442 >        return  $self->{location};
443   }
444  
445 < sub meta {
445 > sub searchlocation {
446          my $self=shift;
447 +        
448 +        #start search in current directory if not specified
449 +        my $thispath;
450 +        if ( @_ ) {
451 +          $thispath=shift
452 +        }
453 +        else {
454 +          $thispath=cwd();
455 +        }
456 +        
457 +        my $rv=0;
458  
459 <        my $string=$self->name()." ".$self->version()." located at :\n  ".
460 <                $self->location;
459 >        # chop off any files - we only want dirs
460 >        if ( -f $thispath ) {
461 >          $thispath=~s/(.*)\/.*/$1/;
462 >        }
463 >        Sloop:{
464 >        do {
465 >          $self->verbose("Searching $thispath");
466 >          if ( -e "$thispath/".$self->{admindir} ) {
467 >            $self->verbose("Found\n");
468 >            $rv=1;
469 >            last Sloop;
470 >          }
471 >        } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
472 >      
473 >        return $rv?$thispath:undef;
474   }
475  
476 < sub configitem {
476 > sub archname {
477          my $self=shift;
478 <        my $location=shift;
478 >        if ( @_ ) {
479 >          $self->{archname}=shift;
480 >        }
481 >        return $self->{archname};
482 > }
483 >
484 > sub archdir {
485 >        my $self=shift;
486 >        if ( @_ ) {
487 >          $self->{archdir}=shift;
488 >        }
489 >        if ( ! defined $self->{archdir} ) {
490 >         if ( defined $self->{archname} ) {
491 >          $self->{archdir}=$self->location()."/".$self->{admindir}."/".
492 >                                                        $self->{archname};
493 >         }
494 >         else {
495 >          $self->error("ConfigArea : cannot create arch directory - ".
496 >                                                "architecture name not set")
497 >         }
498 >        }
499 >        return $self->{archdir};
500 > }
501 >
502 > sub satellite {
503 >        my $self=shift;
504 >
505 >        # -- create the sat object
506 >        my $sat=Configuration::ConfigArea->new();
507 >        $sat->name($self->name());
508 >        $sat->version($self->version());
509 >        $sat->requirementsdoc($self->{reqdoc});
510 >        $sat->configurationdir($self->configurationdir());
511 >        $sat->sourcedir($self->sourcedir());
512 >        $sat->toolboxversion($self->toolboxversion());
513 >        $sat->setup(@_);
514 >
515 >        # -- copy across the cache and ObjectStore
516 >        # -- make sure we dont try building new caches in release areas
517 >        my $rcache=$self->cache();
518 >        if ( defined $rcache ) {
519 >          copy($rcache->location(),$sat->cache()->location());
520 >        }
521 >
522 >        # -- make sure we dont try building new objectstores in release areas
523 >        my $rostore=$self->objectstore();
524 >        if ( defined $rostore ) {
525 >          copy($rostore->location(),$sat->objectstore()->location());
526 >        }
527 >
528 >        # and make sure in reinitialises
529 >        undef ($sat->{cache});
530 >
531 >        # -- link it to this area
532 >        $sat->linkarea($self);
533          
534 <        $self->config()->find("ConfigItem",@_);
534 >        # -- save it
535 >        $sat->save();
536 >
537 >        return $sat;
538   }
539  
540 < sub addconfigitem {
540 > sub copy {
541          my $self=shift;
542 <        my $url=shift;
542 >        my $destination=shift;
543  
544 <        my $docref=$self->activatedoc($url);
545 <        # Set up the document
546 <        $docref->setup();
152 <        $self->config()->storepolicy("local");
153 <        $docref->save();
544 >        # copy across the admin dir
545 >        my $temp=$self->location()."/".$self->{admindir};
546 >        AddDir::copydir($temp,"$destination/".$self->{admindir});
547   }
548  
549 < # -------------- Tags ---------------------------------
157 < # -- init parse
158 < sub Project_Start {
549 > sub align {
550          my $self=shift;
551 <        my $name=shift;
161 <        my $hashref=shift;
551 >        use File::Copy;
552  
553 <        $self->checktag($name,$hashref,'name');
554 <        $self->checktag($name,$hashref,'version');
553 >        $self->_LoadEnvFile();
554 >        my $Envfile=$self->location()."/".$self->{admindir}."/Environment";
555 >        my $tmpEnvfile=$Envfile.".bak";
556 >        my $rel=$self->{ENV}{RELEASETOP};
557 >        my $local=$self->location();
558  
559 <        $self->name($$hashref{'name'});
560 <        $self->version($$hashref{'version'});
559 >        rename( $Envfile, $tmpEnvfile );
560 >        use FileHandle;
561 >        my $fh=FileHandle->new();
562 >        my $fout=FileHandle->new();
563 >        open ( $fh, "<".$tmpEnvfile ) or
564 >                $self->error("Cannot find Environment file. Area Corrupted? ("
565 >                                .$self->location().")\n $!");
566 >        open ( $fout, ">".$Envfile ) or
567 >                $self->error("Cannot find Environment file. Area Corrupted? ("
568 >                                .$self->location().")\n $!");
569 >        while ( <$fh> ) {
570 >          $_=~s/\Q$rel\L/$local/g;
571 >          print $fout $_;
572 >        }
573 >        undef $fh;
574 >        undef $fout;
575   }
576  
577 + sub copysetup {
578 +        my $self=shift;
579 +        my $dest=shift;
580 +        my $rv=1;
581 +        # copy across the admin dir
582 +        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
583 +        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
584 +        if ( $temp ne $temp2 ) {
585 +         if ( -d $temp ) {
586 +          AddDir::copydir($temp,$temp2);
587 +          $rv=0;
588 +         }
589 +        }
590 +        return $rv;
591 + }
592  
593 < sub Project_text {
593 > sub copyurlcache {
594          my $self=shift;
595 <        my $name=shift;
596 <        my $string=shift;
595 >        my $dest=shift;
596 >        my $rv=1;
597 >        # copy across the admin dir
598 >        my $temp=$self->location()."/".$self->{admindir}."/cache";
599 >        my $temp2=$dest."/".$self->{admindir}."/cache";
600 >        if ( $temp ne $temp2 ) {
601 >         if ( -d $temp ) {
602 >          AddDir::copydir($temp,$temp2);
603 >          $rv=0;
604 >         }
605 >        }
606 >        return $rv;
607 > }
608  
609 <        print $string;
609 > sub copywithskip {
610 >        my $self=shift;
611 >        my $dest=shift;
612 >        my $filetoskip=shift || [];            
613 >        my $rv=1;
614 >        # copy across the admin dir
615 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
616 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
617 >        if ( $temp ne $temp2 ) {
618 >         if ( -d $temp ) {
619 >          my $fs=[];
620 >          foreach my $f (@$filetoskip) {push @$fs,"${temp}/${f}";}
621 >          AddDir::copydirwithskip($temp,$temp2,$fs);
622 >          $rv=0;
623 >         }
624 >        }
625 >        return $rv;
626   }
627  
628 < # ---- download parse
628 > sub copyenv {
629 >        my $self=shift;
630 >        my $hashref=shift;
631 >        
632 >        foreach $elem ( keys %{$self->{ENV}} ) {
633 >           $$hashref{$elem}=$self->{ENV}{$elem};
634 >        }
635 > }
636  
637 < sub Use_download_Start {
637 > sub arch {
638          my $self=shift;
639 <        my $name=shift;
640 <        my $hashref=shift;
639 >        return $ENV{SCRAM_ARCH};
640 > }
641 >
642 > sub linkto {
643 >        my $self=shift;
644 >        my $location=shift;
645  
646 <        $self->checktag($name,$hashref,'url');
647 <        print "Downloading .... ".$$hashref{'url'}."\n";
648 <        $self->getfile($$hashref{'url'});
646 >        if ( -d $location ) {
647 >        my $area=Configuration::ConfigArea->new();
648 >        $area->bootstrapfromlocation($location);
649 >        $self->linkarea($area);
650 >        }
651 >        else {
652 >          $self->error("ConfigArea : Unable to link to non existing directory ".
653 >                         $location);
654 >        }
655   }
656  
657 < # --- setup parse
657 > sub unlinkarea {
658 >        my $self=shift;
659 >        undef $self->{linkarea};
660 >        $self->{linkarea}=undef;
661 >        $self->save();
662 > }
663  
664 < sub Use_Start {
664 > sub linkarea {
665          my $self=shift;
666 <        my $name=shift;
667 <        my $hashref=shift;
668 <        
669 <        $self->checktag($name,$hashref,'url');
670 <        $self->addconfigitem($$hashref{'url'});
666 >        my $area=shift;
667 >        if ( defined $area ) {
668 >          $self->{linkarea}=$area;
669 >        }
670 >        return (defined $self->{linkarea} && $self->{linkarea} ne "")?
671 >                        $self->{linkarea}:undef;
672   }
673  
674 + sub save {
675 +        my $self=shift;
676 +        $self->_SaveEnvFile();
677 + }
678 +
679 + sub reqdoc()
680 +   {
681 +   my $self=shift;
682 +   my ($path)=@_;
683 +   return $path."/".$self->{reqdoc};
684 +   }
685 +
686 + sub creationtime()
687 +   {
688 +   my $self=shift;
689 +   my ($location)= @_;
690 +   $location||=$self->location();
691 +   my $requirementsdoc = $self->reqdoc($location);
692 +   my ($mode, $time) = (stat($requirementsdoc))[2, 9];
693 +   my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
694 +
695 +   ($sec < 10) ? ($sec = "0".$sec) : $sec;
696 +   ($min < 10) ? ($min = "0".$min) : $min;
697 +
698 +   $year += 1900;
699 +   my $months =
700 +      {
701 +      0 => "Jan", 1 => "Feb",
702 +      2 => "Mar", 3 => "Apr",
703 +      4 => "May", 5 => "Jun",
704 +      6 => "Jul", 7 => "Aug",
705 +      8 => "Sept", 9 => "Oct",
706 +      10 => "Nov", 11 => "Dec" };
707 +  
708 +   my $days = { 1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat", 7 => "Sun"};
709 +  
710 +   # Return the timestamp (as string) of the requirementsdoc:
711 +   return $days->{$wday}."-".$mday."-".$months->{$mon}."-".$year." ".$hour.":".$min.":".$sec;
712 +   }
713 +
714 + # ---- support routines
715 +
716 + sub _SaveEnvFile
717 +   {
718 +   my $self=shift;
719 +   my $filemode = 0644;
720 +  
721 +   use FileHandle;
722 +   my $fh=FileHandle->new();
723 +   open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
724 +          "Environment" ) or
725 +          $self->error("Cannot Open Environment file to Save ("
726 +                       .$self->location().")\n $!");
727 +        
728 +   print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
729 +   print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
730 +   print $fh "SCRAM_CONFIGDIR=".$self->configurationdir()."\n";
731 +   print $fh "SCRAM_SOURCEDIR=".$self->sourcedir()."\n";
732 +   print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n";
733 +   print $fh "SCRAM_TOOLBOXVERSION=".$self->{toolboxversion}."\n";
734 +   print $fh "SCRAM_SYMLINKS=",$self->{symlinks},"\n";
735 +
736 +   if ( defined $self->linkarea() )
737 +      {
738 +      my $area=$self->linkarea()->location();
739 +      if ( $area ne "" )
740 +         {
741 +         print $fh "RELEASETOP=".$area."\n";
742 +         }
743 +      }
744 +  
745 +   undef $fh;
746 +  
747 +   # Repeat the exercise to save as XML:
748 +   my $fh=FileHandle->new();
749 +   open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
750 +          "Environment.xml" ) or
751 +          $self->error("Cannot Open Environment.xml file to Save ("
752 +                       .$self->location().")\n $!");
753 +   print $fh "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
754 +   print $fh "<doc type=\"Configuration::ProjectEnvironment\" version=\"1.0\">\n";
755 +   print $fh " <environment SCRAM_PROJECTNAME=\"".$self->name()."\"/>\n";
756 +   print $fh " <environment SCRAM_PROJECTVERSION=\"".$self->version()."\"/>\n";
757 +   print $fh " <environment SCRAM_CONFIGDIR=\"".$self->configurationdir()."\"/>\n";
758 +   print $fh " <environment SCRAM_SOURCEDIR=\"".$self->sourcedir()."\"/>\n";
759 +   print $fh " <environment SCRAM_ProjReqsDoc=\"".$self->{reqdoc}."\"/>\n";
760 +   print $fh " <environment SCRAM_TOOLBOXVERSION=\"".$self->{toolboxversion}."\"/>\n";
761 +   print $fh "<environment SCRAM_SYMLINKS=\"",$self->{symlinks},"\"/>\n";
762 +
763 +   if ( defined $self->linkarea() )
764 +      {
765 +      my $area=$self->linkarea()->location();
766 +      if ( $area ne "" )
767 +         {
768 +         print $fh " <environment RELEASETOP=\"".$area."\"/>\n";
769 +         }
770 +      }
771 +  
772 +   print $fh "</doc>\n";
773 +   undef $fh;
774 +  
775 +   # Set the default permissions (-rw-r--r--):
776 +   chmod $filemode, $self->location()."/".$self->{admindir}."/Environment";
777 +   chmod $filemode, $self->location()."/".$self->{admindir}."/Environment.xml";
778 +   }
779 +
780 + sub _LoadEnvFile
781 +   {
782 +   my $self=shift;
783 +
784 +   use FileHandle;
785 +   my $fh=FileHandle->new();
786 +   open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
787 +          "Environment" ) or
788 +          $self->error("Cannot find Environment file. Area Corrupted? ("
789 +                       .$self->location().")\n $!");
790 +   while ( <$fh> )
791 +      {
792 +      chomp;
793 +      next if /^#/;
794 +      next if /^\s*$/ ;
795 +      ($name, $value)=split /=/;
796 +      eval "\$self->{ENV}{${name}}=\"$value\"";
797 +      }
798 +   undef $fh;
799 +        
800 +   # -- set internal variables appropriately
801 +   if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} )
802 +      {
803 +      $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
804 +      }
805 +   if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} )
806 +      {
807 +      $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
808 +      }
809 +   if ( defined $self->{ENV}{"SCRAM_CONFIGDIR"} )
810 +      {
811 +      $self->configurationdir($self->{ENV}{"SCRAM_CONFIGDIR"});
812 +      }
813 +   if ( defined $self->{ENV}{"SCRAM_SOURCEDIR"} )
814 +      {
815 +      $self->sourcedir($self->{ENV}{"SCRAM_SOURCEDIR"});
816 +      }
817 +   if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} )
818 +      {
819 +      $self->requirementsdoc($self->{ENV}{"SCRAM_ProjReqsDoc"});
820 +      }
821 +   if ( defined $self->{ENV}{"SCRAM_TOOLBOXVERSION"} )
822 +      {
823 +      if ($self->{ENV}{"SCRAM_TOOLBOXVERSION"} eq '')
824 +         {
825 +         $self->toolboxversion("STANDALONE");
826 +         }
827 +      else
828 +         {
829 +         $self->toolboxversion($self->{ENV}{"SCRAM_TOOLBOXVERSION"});
830 +         }
831 +      }
832 +  
833 +   if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
834 +        ($self->{ENV}{"RELEASETOP"} ne $self->location()))
835 +      {
836 +      $self->linkto($self->{ENV}{"RELEASETOP"});
837 +      }
838 +   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines