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.16 by williamc, Thu Sep 21 13:52:07 2000 UTC vs.
Revision 1.26 by sashby, Wed Feb 2 18:57:01 2005 UTC

# Line 37 | Line 37
37   # save()                        : save changes permanently
38   # linkto(location)              : link the current area to that at location
39   # unlinkarea()                  : destroy link (autosave)
40 < # linkarea([ConfigArea])        : get/set a link from the current area to the apec Area Object
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 < #                                 if called with temp - will set as undef
46 < #                                 if it dosnt already exist - otherwise will
47 < #                                 attempt to create it.
44 > # objectstore()         : return the objectStore object of the area
45   # - temporary
46   # align()                       : adjust hard paths to suit local loaction
47  
# Line 66 | Line 63 | sub new {
63          $self->{admindir}=".SCRAM";
64          $self->{cachedir}="cache";
65          $self->{dbdir}="ObjectDB";
66 +        $self->{tbupdate}=0;
67          undef $self->{linkarea};
68  
69          return $self;
# Line 74 | Line 72 | sub new {
72   sub cache {
73          my $self=shift;
74  
77        my $exist=0;
75          if ( @_ ) {
76 <          my $cache=shift;
80 <          if ( $cache!~/^</ ) {
81 <            $self->{cache}=$cache;
82 <          }
83 <          $exist=1;
76 >           $self->{cache}=shift;
77          }
78 <        elsif ( ! defined $self->{cache} ) {
78 >        if ( ! defined $self->{cache} ) {
79            my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
80 <          if ( ! $exist ) {
80 >          if ( -e $loc  ) {
81              $self->{cache}=URL::URLcache->new($loc);
82            }
83 +          else {
84 +            $self->{cache}=undef;
85 +          }
86          }
87          return $self->{cache};
88   }
89  
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 +        my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
121 +        $self->{cache}=URL::URLcache->new($loc);
122 +        return $self->{cache};
123 + }
124 +
125 + sub _newobjectstore {
126 +        my $self=shift;
127 +        my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
128 +        $self->{dbstore}=ObjectUtilities::ObjectStore->new($loc);
129 +        return $self->{dbstore};
130 + }
131 +
132   sub objectstore {
133          my $self=shift;
134  
97        my $exist="";
135          if ( @_ ) {
136 <          my $db=shift;
100 <          if ( $db!~/^</ ) {
101 <            $self->{dbstore}=cache;
102 <          }
103 <          $exist="<";
136 >            $self->{dbstore}=shift;
137          }
138 <        elsif ( ! defined $self->{dbstore} ) {
138 >        if ( ! defined $self->{dbstore} ) {
139            my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
140 <          $self->{dbstore}=ObjectUtilities::ObjectStore->new($exist.$loc);
140 >          if ( -e $loc ) {
141 >            $self->{dbstore}=ObjectUtilities::ObjectStore->new($loc);
142 >          }
143 >          else {
144 >            $self->{dbstore}=undef;
145 >          }
146          }
147          return $self->{dbstore}
148   }
# Line 129 | Line 167 | sub setup {
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          }
# Line 154 | Line 193 | sub setup {
193          AddDir::adddir($workloc);
194  
195          # -- add a cache
196 <        $self->cache();
196 >        $self->_newcache();
197 >
198 >        # -- add an Objectstore
199 >        $self->_newobjectstore();
200  
201          # -- Save Environment File
202          $self->_SaveEnvFile();
# Line 169 | Line 211 | sub configurationdir {
211          return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
212   }
213  
214 + sub sourcedir {
215 +        my $self=shift;
216 +        if ( @_ ) {
217 +          $self->{sourcedir}=shift;
218 +        }
219 +        return (defined $self->{sourcedir})?$self->{sourcedir}:undef;
220 + }
221 +
222   sub toolbox {
223          my $self=shift;
224          if ( ! defined $self->{toolbox} ) {
225 <          $self->{toolbox}=BuildSystem::ToolBox->new($self);
225 >          $self->{toolbox}=BuildSystem::ToolBox->new($self, $ENV{SCRAM_ARCH});
226          }
227          return $self->{toolbox};
228   }
229  
230 + sub toolboxversion {
231 +        my $self=shift;
232 +        if ( @_ ) {
233 +          $self->{toolboxversion}=shift;
234 +        }
235 +        return (defined $self->{toolboxversion})?$self->{toolboxversion}:undef;
236 + }
237 +
238   sub requirementsdoc {
239          my $self=shift;
240          if ( @_ ) {
# Line 208 | Line 266 | sub scramversion {
266          return $self->{scramversion};
267   }
268  
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 +
315   sub bootstrapfromlocation {
316          my $self=shift;
317  
# Line 221 | Line 325 | sub bootstrapfromlocation {
325          else {
326           $self->location($location);
327           $self->verbose("Found top ".$self->location());
224         my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat";
328           $self->_LoadEnvFile();
329          }
330          return $rv;
# Line 242 | Line 345 | sub location {
345  
346   sub searchlocation {
347          my $self=shift;
348 <
348 >        
349          #start search in current directory if not specified
350          my $thispath;
351          if ( @_ ) {
# Line 251 | Line 354 | sub searchlocation {
354          else {
355            $thispath=cwd();
356          }
357 <
357 >        
358          my $rv=0;
359  
360          # chop off any files - we only want dirs
# Line 267 | Line 370 | sub searchlocation {
370              last Sloop;
371            }
372          } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
373 <
373 >      
374          return $rv?$thispath:undef;
375   }
376  
# Line 306 | Line 409 | sub satellite {
409          $sat->version($self->version());
410          $sat->requirementsdoc($self->{reqdoc});
411          $sat->configurationdir($self->configurationdir());
412 +        $sat->sourcedir($self->sourcedir());
413 +        $sat->toolboxversion($self->toolboxversion());
414          $sat->setup(@_);
415  
416          # -- copy across the cache and ObjectStore
417          # -- make sure we dont try building new caches in release areas
418 <        my $rcache=$self->cache("<");
418 >        my $rcache=$self->cache();
419          if ( defined $rcache ) {
420            copy($rcache->location(),$sat->cache()->location());
421          }
422  
423          # -- make sure we dont try building new objectstores in release areas
424 <        my $rostore=$self->objectstore("<");
424 >        my $rostore=$self->objectstore();
425          if ( defined $rostore ) {
426            copy($rostore->location(),$sat->objectstore()->location());
427          }
# Line 372 | Line 477 | sub align {
477  
478   sub copysetup {
479          my $self=shift;
480 <        my $dest=shift;
376 <
480 >        my $dest=shift;
481          my $rv=1;
482          # copy across the admin dir
483          my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
# Line 387 | Line 491 | sub copysetup {
491          return $rv;
492   }
493  
494 + sub copyurlcache {
495 +        my $self=shift;
496 +        my $dest=shift;
497 +        my $rv=1;
498 +        # copy across the admin dir
499 +        my $temp=$self->location()."/".$self->{admindir}."/cache";
500 +        my $temp2=$dest."/".$self->{admindir}."/cache";
501 +        if ( $temp ne $temp2 ) {
502 +         if ( -d $temp ) {
503 +          AddDir::copydir($temp,$temp2);
504 +          $rv=0;
505 +         }
506 +        }
507 +        return $rv;
508 + }
509 +
510 + sub copywithskip {
511 +        my $self=shift;
512 +        my $dest=shift;
513 +        my ($filetoskip)=@_;            
514 +        my $rv=1;
515 +        # copy across the admin dir
516 +        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
517 +        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
518 +        if ( $temp ne $temp2 ) {
519 +         if ( -d $temp ) {
520 +          AddDir::copydirwithskip($temp,$temp2,$filetoskip);
521 +          $rv=0;
522 +         }
523 +        }
524 +        return $rv;
525 + }
526 +
527   sub copyenv {
528          my $self=shift;
529          my $hashref=shift;
# Line 404 | Line 541 | sub arch {
541   sub linkto {
542          my $self=shift;
543          my $location=shift;
544 +
545          if ( -d $location ) {
546          my $area=Configuration::ConfigArea->new();
547          $area->bootstrapfromlocation($location);
# Line 439 | Line 577 | sub save {
577  
578   # ---- support routines
579  
580 < sub _SaveEnvFile {
581 <        my $self=shift;
582 <        use FileHandle;
583 <        my $fh=FileHandle->new();
584 <        open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
585 <                "Environment" ) or
586 <                $self->error("Cannot Open Environment file to Save ("
587 <                                .$self->location().")\n $!");
580 > sub _SaveEnvFile
581 >   {
582 >   my $self=shift;
583 >   my $filemode = 0644;
584 >  
585 >   use FileHandle;
586 >   my $fh=FileHandle->new();
587 >   open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
588 >          "Environment" ) or
589 >          $self->error("Cannot Open Environment file to Save ("
590 >                       .$self->location().")\n $!");
591          
592 <        print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
593 <        print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
594 <        print $fh "projconfigdir=".$self->configurationdir()."\n";
595 <        print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n";
596 <        if ( defined $self->linkarea() ) {
597 <          my $area=$self->linkarea()->location();
598 <          if ( $area ne "" ) {
599 <          print $fh "RELEASETOP=".$area."\n";
600 <          }
601 <        }
602 <        undef $fh;
603 < }
604 <
605 <
606 < sub _LoadEnvFile {
607 <        my $self=shift;
608 <
609 <        use FileHandle;
610 <        my $fh=FileHandle->new();
611 <        open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
612 <                "Environment" ) or
613 <                $self->error("Cannot find Environment file. Area Corrupted? ("
614 <                                .$self->location().")\n $!");
615 <        while ( <$fh> ) {
616 <           chomp;
617 <           next if /^#/;
618 <           next if /^\s*$/ ;
619 <           ($name, $value)=split /=/;
620 <           eval "\$self->{ENV}{${name}}=\"$value\"";
621 <        }
622 <        undef $fh;
592 >   print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
593 >   print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
594 >   print $fh "SCRAM_CONFIGDIR=".$self->configurationdir()."\n";
595 >   print $fh "SCRAM_SOURCEDIR=".$self->sourcedir()."\n";
596 >   print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n";
597 >   print $fh "SCRAM_TOOLBOXVERSION=".$self->{toolboxversion}."\n";
598 >
599 >   if ( defined $self->linkarea() )
600 >      {
601 >      my $area=$self->linkarea()->location();
602 >      if ( $area ne "" )
603 >         {
604 >         print $fh "RELEASETOP=".$area."\n";
605 >         }
606 >      }
607 >  
608 >   undef $fh;
609 >  
610 >   # Set the default permissions (-rw-r--r--):
611 >   chmod $filemode, $self->location()."/".$self->{admindir}."/Environment";
612 >   }
613 >
614 > sub _LoadEnvFile
615 >   {
616 >   my $self=shift;
617 >
618 >   use FileHandle;
619 >   my $fh=FileHandle->new();
620 >   open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
621 >          "Environment" ) or
622 >          $self->error("Cannot find Environment file. Area Corrupted? ("
623 >                       .$self->location().")\n $!");
624 >   while ( <$fh> )
625 >      {
626 >      chomp;
627 >      next if /^#/;
628 >      next if /^\s*$/ ;
629 >      ($name, $value)=split /=/;
630 >      eval "\$self->{ENV}{${name}}=\"$value\"";
631 >      }
632 >   undef $fh;
633          
634 <        # -- set internal variables appropriately
635 <        if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} ) {
636 <          $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
637 <        }
638 <        if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} ) {
639 <          $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
640 <        }
641 <        if ( defined $self->{ENV}{"projconfigdir"} ) {
642 <          $self->configurationdir($self->{ENV}{projconfigdir});
643 <        }
644 <        if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} ) {
645 <          $self->requirementsdoc($self->{ENV}{SCRAM_ProjReqsDoc});
646 <        }
647 <        if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
648 <                        ($self->{ENV}{"RELEASETOP"} ne $self->location())) {
649 <          $self->linkto($self->{ENV}{"RELEASETOP"});
650 <        }
651 <        else {
652 <          $self->{ENV}{"RELEASETOP"}=$self->location();
653 <        }
654 < }
634 >   # -- set internal variables appropriately
635 >   if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} )
636 >      {
637 >      $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
638 >      }
639 >   if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} )
640 >      {
641 >      $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
642 >      }
643 >   if ( defined $self->{ENV}{"SCRAM_CONFIGDIR"} )
644 >      {
645 >      $self->configurationdir($self->{ENV}{"SCRAM_CONFIGDIR"});
646 >      }
647 >   if ( defined $self->{ENV}{"SCRAM_SOURCEDIR"} )
648 >      {
649 >      $self->sourcedir($self->{ENV}{"SCRAM_SOURCEDIR"});
650 >      }
651 >   if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} )
652 >      {
653 >      $self->requirementsdoc($self->{ENV}{"SCRAM_ProjReqsDoc"});
654 >      }
655 >   if ( defined $self->{ENV}{"SCRAM_TOOLBOXVERSION"} )
656 >      {
657 >      $self->toolboxversion($self->{ENV}{"SCRAM_TOOLBOXVERSION"});
658 >      }
659 >  
660 >   if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
661 >        ($self->{ENV}{"RELEASETOP"} ne $self->location()))
662 >      {
663 >      $self->linkto($self->{ENV}{"RELEASETOP"});
664 >      }
665 >   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines