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.13 by williamc, Mon Mar 13 10:23:19 2000 UTC vs.
Revision 1.13.2.6 by williamc, Tue May 16 14:03:02 2000 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   # -----------
# Line 14 | Line 14
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 < # storeconfigobject(confiItemobj) : store a ready made ConfigItem in the local
27 < #                                       area
28 < # configitem(@keys)             : return a list of fig items that match
29 < #                                 the keys - all if left blank
30 < # parentstore()                 : set/return the parent ObjectStore
31 < # basearea(ConfigArea)          : Set/Get the base area
32 < # freebase()                    : Remove any link to a base area
33 < # bootstrapfromlocation([location]): bootstrap the object based on location.
34 < #                                 no location specified - cwd used
17 > # new()                         : A new ConfigArea object
18 > # location([dir])               : set/return the location of the work area
19 > # bootstrapfromlocation([location]) : bootstrap the object based on location.
20 > #                                     no location specified - cwd used
21 > #                                     return 0 if succesful 1 otherwise
22 > # requirementsdoc()             : get set the requirements doc
23   # searchlocation([startdir])    : returns the location directory. search starts
24   #                                 from cwd if not specified
25   # defaultdirname()              : return the default directory name string
26 < # copy(location)                : make a copy of the current area at the
27 < #                                 specified location - defaults to cwd/default
28 < #                                 if not specified . ConfigArea_name,
29 < #                                 ConfigArea_location also override .
30 < #                                 Return an object representing the area
31 < # satellite()                   : make a satellite area based on $self
32 < # arch([archobj])               : Set/get the architecture object
33 < # structure(name)               : return the object corresponding to the
34 < #                                 structure name
35 < # structurelist()               : return list of structure objectS
36 < # downloadtotop(dir,url)        : download the url to a dir in the config area
49 < #                                
26 > # scramversion()                : return the scram version associated with
27 > #                                 area
28 > # configurationdir()            : return the location of the project
29 > #                                 configuration directory
30 > # copy(location)                : copy a configuration
31 > # copysetup(location)           : copy the architecture specific tool setup
32 > #                                 returns 0 if successful, 1 otherwise
33 > # copyenv($ref)                 : copy the areas environment into the hashref
34 > # toolbox()                     : return the areas toolbox object
35 > # - temporary
36 > # align()                       : adjust hard paths to suit local loaction
37  
38   package Configuration::ConfigArea;
52 use ActiveDoc::ActiveDoc;
39   require 5.004;
40   use Utilities::AddDir;
41 < use ObjectUtilities::ObjectStore;
56 < use Configuration::ConfigStore;
57 < use Configuration::ActiveDoc_arch;
41 > use Utilities::Verbose;
42   use Cwd;
43 < @ISA=qw(Configuration::ActiveDoc_arch ObjectUtilities::StorableObject);
43 > @ISA=qw(Utilities::Verbose);
44  
45 < sub init {
46 <        my $self=shift;
47 <
48 <        $self->newparse("init");
65 <        $self->newparse("download");
66 <        $self->newparse("setup");
67 <        $self->newparse("setup_tools");
68 <        $self->addarchtags("setup_tools");
69 <        $self->addarchtags("setup");
70 <        $self->addtag("init","project",\&Project_Start,$self,
71 <            \&Project_text,$self,"", $self );
72 <        $self->addurltags("download");
73 <        $self->addtag("download","download",\&Download_Start,$self,
74 <                                                "", $self, "",$self);
75 <        $self->addtag("download","use",\&Use_download_Start,$self,
76 <                                                "", $self, "",$self);
77 <        $self->addurltags("setup");
78 <        $self->addurltags("setup_tools");
79 <        $self->addtag("setup_tools","use",\&Use_Start,$self, "", $self, "",$self);
80 <        $self->addtag("setup","structure",\&Structure_Start,$self,
81 <                         "", $self, "",$self);
45 > sub new {
46 >        my $class=shift;
47 >        my $self={};
48 >        bless $self, $class;
49  
50          # data init
51 <        $self->{admindir}=".SCRAM";
51 >        $self->{admindir}=".SCRAM";
52 >
53 >        return $self;
54   }
55  
56 < sub basearea {
56 > sub configurationdir {
57          my $self=shift;
89
90        my $area;
58          if ( @_ ) {
59 <          $area=shift;
93 <          $self->config()->store($area,"BaseArea");
59 >          $self->{configurationdir}=shift;
60          }
61 <        else {
62 <          ($area)=$self->config()->find("BaseArea");
61 >        if ( ! defined $self->{configurationdir} ) {
62 >          $self->_LoadEnvFile();
63 >          $self->{configurationdir}=$self->{ENV}{projconfigdir};
64          }
65 <        return $area;
65 >        return $self->{configurationdir};
66   }
67  
68 < sub freebase {
68 > sub toolbox {
69          my $self=shift;
70 <        $self->config()->delete("BaseArea");
71 < }
105 <
106 < sub defaultdirname {
107 <        my $self=shift;
108 <        my $name=$self->name();
109 <        my $vers=$self->version();
110 <        $vers=~s/^$name\_//;
111 <        $name=$name."_".$vers;
112 <        return $name;
113 < }
114 <
115 <
116 < sub setup {
117 <        my $self=shift;
118 <
119 <        # --- find out the location - default is cwd
120 <        my $location=$self->option("ConfigArea_location");
121 <        if ( ! defined $location ) {
122 <                $location=cwd();
70 >        if ( ! defined $self->{toolbox} ) {
71 >          $self->{toolbox}=BuildSystem::ToolBox->new($self);
72          }
73 <        elsif ( $location!~/^\// ) {
125 <                $location=cwd()."/".$location;
126 <        }
127 <
128 <        # --- find area directory name , default name projectname_version
129 <        my $name=$self->option("ConfigArea_name");
130 <        if ( ! defined $name ) {
131 <          $name=$self->defaultdirname();
132 <        }
133 <        $self->location($location."/".$name);
134 <
135 <        # make a new store handler
136 <        $self->_setupstore();
137 <
138 <        # --- download everything first
139 <        $self->parse("download");
140 <        
141 <        # --- and parse the setup file
142 <        $self->parse("setup");
143 <        $self->parse("setup_tools");
144 <        
145 <        # --- store bootstrap info
146 <        $self->store($self->location()."/".$self->{admindir}."/ConfigArea.dat");
147 <
148 <        # --- store self in original database
149 <        $self->parentconfig()->store($self,"ConfigArea",$self->name(),
150 <                                                        $self->version());
73 >        return $self->{toolbox};
74   }
75  
76 < sub structure {
76 > sub requirementsdoc {
77          my $self=shift;
78 <        my $vr=shift;
79 <        return $self->{structures}{$vr};
80 < }
81 <
82 < sub structurelist {
83 <        my $self=shift;
84 <        return ( keys %{$self->{structures}} );
85 < }
86 <
87 < sub _setupstore {
88 <        my $self=shift;
89 <
90 <        # --- make a new ConfigStore at the location and add it to the db list
91 <        my $ad=Configuration::ConfigStore->new($self->location().
92 <                                "/".$self->{admindir}, $self->arch());
93 <
94 <        $self->parentconfig($self->config());
95 < #        $self->config(Configuration::ConfigureStore->new());
96 < #        $self->config()->db("local",$ad);
97 < #        $self->config()->db("parent",$self->parentconfig());
98 < #        $self->config()->policy("cache","local");
99 <        $self->config($ad);
100 <        $self->config()->basedoc($self->parentconfig()->basedoc());
101 < }
179 <
180 < sub bootstrapfromlocation {
181 <        my $self=shift;
182 <        
183 <        if ( ! defined $self->location(@_) ) {
184 <          $self->error("Unable to locate the top of local configuration area");
185 <        }
186 <        $self->verbose("Found top ".$self->location());
187 <        $self->_setupstore();
188 <        my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat";
189 <        if ( -e $infofile ) {
190 <             $self->restore($infofile);
191 <        }
192 <        else {
193 <             $self->error("Area corrupted - cannot find $infofile");
78 >        if ( @_ ) {
79 >          $self->{reqdoc}=shift;
80 >        }
81 >        if ( ! defined $self->{reqdoc} ) {
82 >          $self->_LoadEnvFile();
83 >          $self->{reqdoc}=$self->{ENV}{SCRAM_ProjReqsDoc};
84 >        }
85 >        return $self->{reqdoc};
86 > }
87 >
88 > sub scramversion {
89 >        my $self=shift;
90 >        if ( ! defined $self->{scramversion} ) {
91 >          my $filename=$self->location()."/".$self->configurationdir()."/".
92 >                                                        "scram_version";
93 >          if ( -f $filename ) {
94 >            use FileHandle;
95 >            $fh=FileHandle->new();
96 >            open ($fh, "<".$filename);
97 >            my $version=<$fh>;
98 >            chomp $version;
99 >            $self->{scramversion}=$version;
100 >            undef $fh;
101 >          }
102          }
103 +        return $self->{scramversion};
104   }
105  
106 < sub parentconfig {
198 <        my $self=shift;
199 <        @_?$self->{parentconfig}=shift
200 <          :$self->{parentconfig};
201 < }
202 <
203 < sub store {
204 <        my $self=shift;
205 <        my $location=shift;
206 <
207 <        my $fh=$self->openfile(">".$location);
208 <        $self->savevar($fh,"location", $self->location());
209 <        $self->savevar($fh,"url", $self->url());
210 <        $self->savevar($fh,"name", $self->name());
211 <        $self->savevar($fh,"version", $self->version());
212 <        $fh->close();
213 <
214 <        $self->_storestructures();
215 < }
216 <
217 < sub satellite {
218 <        my $self=shift;
219 <        my $newarea=$self->copy(@_);
220 <        $newarea->_makesatellites();
221 <        return $newarea;
222 < }
223 <
224 < sub copy {
106 > sub bootstrapfromlocation {
107          my $self=shift;
226        use File::Basename;
227        # create the area
108  
109 <        my $destination;
110 <        if ( @_ ) {
111 <         $destination=shift;
109 >        my $rv=0;
110 >        
111 >        my $location;
112 >        if ( ! defined ($location=$self->searchlocation(@_)) ) {
113 >         $rv=1;
114 >         $self->verbose("Unable to locate the top of local configuration area");
115          }
116          else {
117 <          my($location,$name)=$self->_defaultoptions();
118 <          $destination=$location."/".$name
117 >         $self->location($location);
118 >         $self->verbose("Found top ".$self->location());
119 >         my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat";
120 >         $self->_LoadEnvFile();
121          }
122 <        #AddDir::adddir(dirname($destination)."/".$self->{admindir});
238 <        #AddDir::adddir($destination."/".$self->{admindir});
239 <        
240 <        # copy across the admin dir
241 <        $temp=$self->location()."/".$self->{admindir};
242 <        AddDir::copydir($temp,"$destination/".$self->{admindir});
243 <        # create a new object based on the new area
244 <        my $newarea=ref($self)->new($self->parentconfig());
245 <        $newarea->bootstrapfromlocation($destination);
246 <        # save it with the new location info
247 <        $newarea->store($self->location()."/".$self->{admindir}.
248 <                                                        "/ConfigArea.dat");
249 <        return $newarea;
250 < }
251 <
252 < sub restore {
253 <        my $self=shift;
254 <        my $location=shift;
255 <
256 <        my $fh=$self->openfile("<".$location);
257 <        my $varhash={};
258 <        $self->restorevars($fh,$varhash);
259 <        if ( ! defined $self->location() ) {
260 <          $self->location($$varhash{"location"});
261 <        }
262 <        $self->_setupstore();
263 <        $self->url($$varhash{"url"});
264 <        $self->name($$varhash{"name"});
265 <        $self->version($$varhash{"version"});
266 <        $fh->close();
267 <
268 <        $self->_restorestructures();
269 < }
270 <
271 < sub name {
272 <        my $self=shift;
273 <
274 <        @_?$self->{name}=shift
275 <          :$self->{name};
276 < }
277 <
278 < sub version {
279 <        my $self=shift;
280 <
281 <        @_?$self->{version}=shift
282 <          :$self->{version};
122 >        return $rv;
123   }
124  
125   sub location {
# Line 300 | Line 140 | sub searchlocation {
140  
141          #start search in current directory if not specified
142          my $thispath;
143 <        @_?$thispath=shift
144 <          :$thispath=cwd();
143 >        if ( @_ ) {
144 >          $thispath=shift
145 >        }
146 >        else {
147 >          $thispath=cwd();
148 >        }
149  
150          my $rv=0;
151  
152 +        # chop off any files - we only want dirs
153 +        if ( -f $thispath ) {
154 +          $thispath=~s/(.*)\/.*/$1/;
155 +        }
156          Sloop:{
157          do {
158 < #         print "Searching $thispath\n";
158 >          $self->verbose("Searching $thispath");
159            if ( -e "$thispath/".$self->{admindir} ) {
160 < #           print "Found\n";
160 >            $self->verbose("Found\n");
161              $rv=1;
162              last Sloop;
163            }
# Line 318 | Line 166 | sub searchlocation {
166          return $rv?$thispath:undef;
167   }
168  
169 < sub meta {
322 <        my $self=shift;
323 <
324 <        my $string=$self->name()." ".$self->version()." located at :\n  ".
325 <                $self->location;
326 < }
327 <
328 < sub configitem {
329 <        my $self=shift;
330 <        
331 <        return ($self->config()->find("ConfigItem",@_));
332 < }
333 <
334 < sub addconfigitem {
169 > sub copy {
170          my $self=shift;
171 <        my $url=shift;
171 >        my $destination=shift;
172  
173 <        my $docref=$self->activatedoc($url);
174 <        # Set up the document
175 <        $docref->setup();
341 <        $docref->save();
342 < #       $self->config()->storepolicy("local");
173 >        # copy across the admin dir
174 >        my $temp=$self->location()."/".$self->{admindir};
175 >        AddDir::copydir($temp,"$destination/".$self->{admindir});
176   }
177  
178 < sub storeconfigobject {
178 > sub align {
179          my $self=shift;
180 <        my $obj=shift;
348 <        $obj->save($self->config());
349 < }
180 >        use File::Copy;
181  
182 < sub downloadtotop {
183 <        my $self=shift;
184 <        my $url=shift;
185 <        my $dir=shift;
186 <        
187 <        # only download once
188 <        if ( ! -e $self->location()."/".$dir ) {
189 <          $self->{urlhandler}->download($url,$self->location()."/".$dir);
190 <        }
182 >        $self->_LoadEnvFile();
183 >        my $Envfile=$self->location()."/".$self->{admindir}."/Environment";
184 >        my $tmpEnvfile=$Envfile.".bak";
185 >        my $rel=$self->{ENV}{RELEASETOP};
186 >        my $local=$self->location();
187 >
188 >        rename( $Envfile, $tmpEnvfile );
189 >        use FileHandle;
190 >        my $fh=FileHandle->new();
191 >        my $fout=FileHandle->new();
192 >        open ( $fh, "<".$tmpEnvfile ) or
193 >                $self->error("Cannot find Environment file. Area Corrupted? ("
194 >                                .$self->location().")\n $!");
195 >        open ( $fout, ">".$Envfile ) or
196 >                $self->error("Cannot find Environment file. Area Corrupted? ("
197 >                                .$self->location().")\n $!");
198 >        while ( <$fh> ) {
199 >          $_=~s/\Q$rel\L/$local/g;
200 >          print $fout $_;
201 >        }
202 >        undef $fh;
203 >        undef $fout;
204   }
205  
206 < sub _makesatellites {
206 > sub copysetup {
207          my $self=shift;
208 <        foreach $st ( values %{$self->{structures}} ) {
365 <           $st->setupsatellite()
366 <        }
367 < }
368 <
369 < sub _storestructures {
370 <        my $self=shift;
371 <        foreach $struct ( values %{$self->{structures}} ) {
372 <          $self->config()->store($struct, "Structures", $struct->name());
373 <        }
374 < }
208 >        my $dest=shift;
209  
210 < sub _restorestructures {
211 <        my $self=shift;
212 <        my @strs=$self->config()->find("Structures");
213 <        foreach $struct ( @strs ) {
214 <          $struct->parent($self);
215 <          $self->{structures}{$struct->name()}=$struct;
210 >        my $rv=1;
211 >        # copy across the admin dir
212 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
213 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
214 >        if ( $temp ne $temp2 ) {
215 >         if ( -d $temp ) {
216 >          AddDir::copydir($temp,$temp2);
217 >          $rv=0;
218 >         }
219          }
220 +        return $rv;
221   }
222  
223 < sub _defaultoptions {
386 <        my $self=shift;
387 <        my $name;
388 <        my $location;
389 <
390 <        # --- find out the location - default is cwd
391 <        $location=$self->option("ConfigArea_location");
392 <        if ( ! defined $location ) {
393 <                $location=cwd();
394 <        }
395 <        elsif ( $location!~/^\// ) {
396 <                $location=cwd()."/".$location;
397 <        }
398 <
399 <        # --- find area directory name , default name projectname_version
400 <        $name=$self->option("ConfigArea_name");
401 <        if ( ! defined $name ) {
402 <          $name=$self->defaultdirname();
403 <        }
404 <        return ($location,$name);
405 < }
406 < # -------------- Tags ---------------------------------
407 < # -- init parse
408 < sub Project_Start {
223 > sub copyenv {
224          my $self=shift;
410        my $name=shift;
225          my $hashref=shift;
226 <
227 <        $self->checktag($name,$hashref,'name');
228 <        $self->checktag($name,$hashref,'version');
415 <
416 <        $self->name($$hashref{'name'});
417 <        $self->version($$hashref{'version'});
418 < }
419 <
420 <
421 < sub Project_text {
422 <        my $self=shift;
423 <        my $name=shift;
424 <        my $string=shift;
425 <
426 <        print $string;
427 < }
428 <
429 < # ---- download parse
430 <
431 < sub Download_Start {
432 <        my $self=shift;
433 <        my $name=shift;
434 <        my $hashref=shift;
435 <
436 <        $self->checktag($name,$hashref,'url');
437 <        $self->checktag($name,$hashref,'location');
438 <        if ( $$hashref{'location'}!~/^\w/ ) {
439 <          $self->parseerror("location must start with an".
440 <                " alphanumeric character");
226 >        
227 >        foreach $elem ( keys %{$self->{ENV}} ) {
228 >           $$hashref{$elem}=$self->{ENV}{$elem};
229          }
442        print "Downloading .... ".$$hashref{'url'}."\n";
443        $self->downloadtotop($$hashref{'url'},$$hashref{'location'});
230   }
231  
232 < sub Use_download_Start {
232 > sub arch {
233          my $self=shift;
234 <        my $name=shift;
449 <        my $hashref=shift;
450 <
451 <        $self->checktag($name,$hashref,'url');
452 <        print "Downloading .... ".$$hashref{'url'}."\n";
453 <        $self->getfile($$hashref{'url'});
234 >        return $ENV{SCRAM_ARCH};
235   }
236  
237 < # --- setup parse
238 <
458 < sub Structure_Start {
237 > # ---- support routines
238 > sub _LoadEnvFile {
239          my $self=shift;
460        my $name=shift;
461        my $hashref=shift;
240  
241 <        $self->checktag($name,$hashref,'name');
242 <        if ( !(( exists $$hashref{'type'}) || ( exists $$hashref{'url'})) ) {
243 <            $self->parseerror("No url or type given in <$name> tag");
244 <        }
245 <        if ( ! exists $self->{structures}{$$hashref{'name'}} ) {
246 <          if ( exists $$hashref{'type'}) {
247 <            # create a new object of the specified type
248 <            eval "require $$hashref{'type'} ";
249 <            if  ( $@ ) {
250 <                $self->parseerror("Unable to instantiate type=".
251 <                        $$hashref{'type'}." in <$name> .".$@);
252 <            }
253 <            $self->{structures}{$$hashref{'name'}}=
254 <                $$hashref{'type'}->new($self->config());
477 <            $self->{structures}{$$hashref{'name'}}->name($$hashref{'name'});
478 <            $self->{structures}{$$hashref{'name'}}->parent($self);
479 <            $self->{structures}{$$hashref{'name'}}->vars($hashref);
480 <            $self->{structures}{$$hashref{'name'}}->arch($self->arch());
481 <          }
482 <          else { # its an activedoc
483 <                $self->{structures}{$$hashref{'name'}}=
484 <                                $self->activatedoc($$hashref{'url'});
485 <          }
486 <          $self->{structures}{$$hashref{'name'}}->setupbase();
487 <        }
488 <        else {
489 <             $self->parseerror("Multiply defined Structure - ".
490 <                                                        $$hashref{'name'});
491 <        }
492 < }
493 <
494 < sub Use_Start {
495 <        my $self=shift;
496 <        my $name=shift;
497 <        my $hashref=shift;
498 <        
499 <        $self->checktag($name,$hashref,'url');
500 <        $self->addconfigitem($$hashref{'url'});
241 >        use FileHandle;
242 >        my $fh=FileHandle->new();
243 >        open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
244 >                "Environment" ) or
245 >                $self->error("Cannot find Environment file. Area Corrupted? ("
246 >                                .$self->location().")\n $!");
247 >        while ( <$fh> ) {
248 >           chomp;
249 >           next if /^#/;
250 >           next if /^\s*$/ ;
251 >           ($name, $value)=split /=/;
252 >           eval "\$self->{ENV}{${name}}=\"$value\"";
253 >        }
254 >        undef $fh;
255   }
502

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines