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.8 by williamc, Thu Feb 10 10:59:44 2000 UTC vs.
Revision 1.14 by williamc, Mon Aug 28 08:35:14 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 + # -----------
8 + # creates and manages a configuration area
9 + #
10 + # Notes
11 + # -------
12 + # Persistency - remember to call the save method to make changes persistent
13   #
14   # Interface
15   # ---------
16 < # new(ActiveConfig)             : A new ConfigArea object
17 < # setup()                       : setup the configuration area
18 < # location([dir])               : set/return the location of the area
19 < # version([version])            : set/return the version of the area
20 < # name([name])                  : set/return the name of the area
21 < # store(location)               : store data in file location
22 < # restore(location)             : restore data from file location
23 < # meta()                        : return a description string of the area
24 < # addconfigitem(url)            : add a new item to the area
25 < # configitem(@keys)             : return a list of fig items that match
20 < #                                 the keys - all if left blank
21 < # parentstore()                 : set/return the parent ObjectStore
22 < # bootstrapfromlocation([location]): bootstrap the object based on location.
23 < #                                 no location specified - cwd used
16 > # new()                         : A new ConfigArea object
17 > # name()                        : get/set project name
18 > # setup(dir[,areaname])         : setup a fresh area in dir
19 > # satellite(dir[,areaname])     : setup a satellite area in dir
20 > # version()                     : get/set project version
21 > # location([dir])               : set/return the location of the work area
22 > # bootstrapfromlocation([location]) : bootstrap the object based on location.
23 > #                                     no location specified - cwd used
24 > #                                     return 0 if succesful 1 otherwise
25 > # requirementsdoc()             : get set the requirements doc
26   # searchlocation([startdir])    : returns the location directory. search starts
27   #                                 from cwd if not specified
28 < # defaultdirname()              : return the default directory name string
29 < # copy(location)                : make a copy of the current area at the
30 < #                                 specified location - return an object
31 < #                                 representing the area
28 > # scramversion()                : return the scram version associated with
29 > #                                 area
30 > # configurationdir()            : return the location of the project
31 > #                                 configuration directory
32 > # copy(location)                : copy a configuration
33 > # copysetup(location)           : copy the architecture specific tool setup
34 > #                                 returns 0 if successful, 1 otherwise
35 > # copyenv($ref)                 : copy the areas environment into the hashref
36 > # toolbox()                     : return the areas toolbox object
37 > # save()                        : save changes permanently
38 > # linkto(location)              : link the current area to that at location
39 > # unlinkarea()                  : destroy link (autosave)
40 > # linkarea([ConfigArea])        : link the current area to the apec Area Object
41 > # archname()            : get/set a string to indicate architecture
42 > # archdir()             : return the location of the administration arch dep
43 > #                         directory
44 > # objectstore()         : return the objectStore object of the area
45 > # - temporary
46 > # align()                       : adjust hard paths to suit local loaction
47  
48   package Configuration::ConfigArea;
32 use ActiveDoc::ActiveDoc;
49   require 5.004;
50 + use URL::URLcache;
51   use Utilities::AddDir;
52 + use Utilities::Verbose;
53   use ObjectUtilities::ObjectStore;
36 use Configuration::ConfigStore;
54   use Cwd;
55 < @ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject);
39 <
40 < sub init {
41 <        my $self=shift;
55 > @ISA=qw(Utilities::Verbose);
56  
57 <        $self->newparse("init");
58 <        $self->newparse("download");
59 <        $self->newparse("setup");
60 <        $self->addtag("init","project",\&Project_Start,$self,
47 <            \&Project_text,$self,"", $self );
48 <        $self->addurltags("download");
49 <        $self->addtag("download","use",\&Use_download_Start,$self,
50 <                                                "", $self, "",$self);
51 <        $self->addurltags("setup");
52 <        $self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self);
57 > sub new {
58 >        my $class=shift;
59 >        my $self={};
60 >        bless $self, $class;
61  
62          # data init
63 <        $self->{admindir}=".SCRAM";
63 >        $self->{admindir}=".SCRAM";
64 >        $self->{cachedir}="cache";
65 >        $self->{dbdir}="ObjectDB";
66 >        undef $self->{linkarea};
67 >
68 >        return $self;
69   }
70  
71 + sub cache {
72 +        my $self=shift;
73 +        if ( @_ ) {
74 +          $self->{cache}=shift;
75 +        }
76 +        elsif ( ! defined $self->{cache} ) {
77 +          my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
78 +          $self->{cache}=URL::URLcache->new($loc);
79 +        }
80 +        return $self->{cache};
81 + }
82  
83 < sub defaultdirname {
83 > sub objectstore {
84          my $self=shift;
85 <        my $name=$self->name();
86 <        my $vers=$self->version();
87 <        $vers=~s/^$name_//;
88 <        $name=$name."_".$vers;
89 <        return $name;
85 >        if ( @_ ) {
86 >          $self->{dbstore}=shift;
87 >        }
88 >        elsif ( ! defined $self->{dbstore} ) {
89 >          my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
90 >          $self->{dbstore}=ObjectUtilities::ObjectStore->new($loc);
91 >        }
92 >        return $self->{dbstore}
93 > }
94 >
95 > sub name {
96 >        my $self=shift;
97 >        @_?$self->{name}=shift
98 >          :$self->{name};
99 > }
100  
101 + sub version {
102 +        my $self=shift;
103 +        @_?$self->{version}=shift
104 +          :$self->{version};
105   }
106  
107   sub setup {
108          my $self=shift;
109 +        my $location=shift;
110 +        my $areaname;
111  
112 <        # --- find out the location - default is cwd
113 <        my $location=$self->option("area_location");
112 >        # -- check we have a project name and version
113 >        my $name=$self->name();
114 >        my $vers=$self->version();
115 >        if ( ( ! defined $name ) && ( ! defined $version )) {
116 >          $self->error("Set ConfigArea name and version before setup");
117 >        }
118 >
119 >        # -- check arguments and set location
120          if ( ! defined $location ) {
121 <                $location=cwd();
121 >          $self->error("ConfigArea: Cannot setup new area without a location");
122          }
123 <        elsif ( $location!~/^\// ) {
124 <                $location=cwd()."/".$location;
123 >        if ( @_ ) {
124 >          $areaname=shift;
125          }
126 <
127 <        # --- find area directory name , default name projectname_version
128 <        my $name=$self->option("area_name");
129 <        if ( ! defined $name ) {
84 <          $name=$self->defaultdirname();
126 >        if ( (! defined $areaname) || ( $areaname eq "" ) ) {
127 >          # -- make up a name from the project name and version
128 >          $vers=~s/^$name\_//;
129 >          $areaname=$name."_".$vers;
130          }
131 <        $self->location($location."/".$name);
131 >        my $arealoc=$location."/".$areaname;
132 >        my $workloc=$arealoc."/".$self->{admindir};
133 >        $self->verbose("Building at $arealoc");
134 >        $self->location($arealoc);
135  
136 <        # make a new store handler
137 <        $self->_setupstore();
136 >        # -- create top level structure and work area
137 >        AddDir::adddir($workloc);
138  
139 <        # --- download everything first
140 < # FIX-ME --- cacheing is broken
93 <        $self->parse("download");
94 <        
95 <        # --- and parse the setup file
96 <        $self->parse("setup");
97 <        
98 <        # --- store bootstrap info
99 <        $self->store($self->location()."/".$self->{admindir}."/ConfigArea.dat");
100 <
101 <        # --- store self in original database
102 <        $self->parentconfig()->store($self,"ConfigArea",$self->name(),
103 <                                                        $self->version());
104 < }
139 >        # -- add a cache
140 >        $self->cache();
141  
142 < sub _setupstore {
143 <        my $self=shift;
108 <
109 <        # --- make a new ConfigStore at the location and add it to the db list
110 <        my $ad=Configuration::ConfigStore->new($self->location().
111 <                                "/".$self->{admindir});
142 >        # -- Save Environment File
143 >        $self->_SaveEnvFile();
144  
113        $self->parentconfig($self->config());
114 #        $self->config(Configuration::ConfigureStore->new());
115 #        $self->config()->db("local",$ad);
116 #        $self->config()->db("parent",$self->parentconfig());
117 #        $self->config()->policy("cache","local");
118        $self->config($ad);
119        $self->config()->basedoc($self->parentconfig()->basedoc());
145   }
146  
147 < sub bootstrapfromlocation {
147 > sub configurationdir {
148          my $self=shift;
149 <        
150 <        if ( ! defined $self->location(@_) ) {
126 <          $self->error("Unable to locate the top of local configuration area");
149 >        if ( @_ ) {
150 >          $self->{configurationdir}=shift;
151          }
152 <        print "Found top ".$self->location()."\n";
129 <        $self->_setupstore();
130 <        $self->restore($self->location()."/".$self->{admindir}.
131 <                                                "/ConfigArea.dat");
132 < }
133 <
134 < sub parentconfig {
135 <        my $self=shift;
136 <        @_?$self->{parentconfig}=shift
137 <          :$self->{parentconfig};
138 < }
139 <
140 < sub store {
141 <        my $self=shift;
142 <        my $location=shift;
143 <
144 <        my $fh=$self->openfile(">".$location);
145 <        $self->savevar($fh,"location", $self->location());
146 <        $self->savevar($fh,"url", $self->url());
147 <        $self->savevar($fh,"name", $self->name());
148 <        $self->savevar($fh,"version", $self->version());
149 <        $fh->close();
152 >        return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
153   }
154  
155 < sub copy {
155 > sub toolbox {
156          my $self=shift;
157 <        my $destination=shift;
158 <        use File::Basename;
159 <        # create the area
160 <
158 <        AddDir::adddir(dirname($destination));
159 <        
160 <        $temp=$self->location();
161 <        my @cpcmd=(qw(cp -r), "$temp", "$destination");
162 <        print "@cpcmd"."\n";
163 < #       File::Copy::copy("$self->location()", "$destination") or
164 <        system(@cpcmd) == 0 or
165 <                        $self->error("Cannot copy ".$self->location().
166 <                        " to $destination ".$!);
167 <
168 <        # create a new object based on the new area
169 <        my $newarea=ref($self)->new($self->parentconfig());
170 <        $newarea->bootstrapfromlocation($destination);
171 <        # save it with the new location info
172 <        $newarea->store($self->location()."/".$self->{admindir}."/ConfigArea.dat");
157 >        if ( ! defined $self->{toolbox} ) {
158 >          $self->{toolbox}=BuildSystem::ToolBox->new($self);
159 >        }
160 >        return $self->{toolbox};
161   }
162  
163 < sub restore {
163 > sub requirementsdoc {
164          my $self=shift;
165 <        my $location=shift;
166 <
167 <        my $fh=$self->openfile("<".$location);
168 <        my $varhash={};
169 <        $self->restorevars($fh,$varhash);
170 <        if ( ! defined $self->location() ) {
171 <          $self->location($$varhash{"location"});
172 <        }
173 <        $self->_setupstore();
186 <        $self->url($$varhash{"url"});
187 <        $self->name($$varhash{"name"});
188 <        $self->version($$varhash{"version"});
189 <        $fh->close();
165 >        if ( @_ ) {
166 >          $self->{reqdoc}=shift;
167 >        }
168 >        if ( defined $self->{reqdoc} ) {
169 >          return $self->location()."/".$self->{reqdoc};
170 >        }
171 >        else {
172 >          return undef;
173 >        }
174   }
175  
176 < sub name {
176 > sub scramversion {
177          my $self=shift;
178 <
179 <        @_?$self->{name}=shift
180 <          :$self->{name};
178 >        if ( ! defined $self->{scramversion} ) {
179 >          my $filename=$self->location()."/".$self->configurationdir()."/".
180 >                                                        "scram_version";
181 >          if ( -f $filename ) {
182 >            use FileHandle;
183 >            $fh=FileHandle->new();
184 >            open ($fh, "<".$filename);
185 >            my $version=<$fh>;
186 >            chomp $version;
187 >            $self->{scramversion}=$version;
188 >            undef $fh;
189 >          }
190 >        }
191 >        return $self->{scramversion};
192   }
193  
194 < sub version {
194 > sub bootstrapfromlocation {
195          my $self=shift;
196  
197 <        @_?$self->{version}=shift
198 <          :$self->{version};
197 >        my $rv=0;
198 >        
199 >        my $location;
200 >        if ( ! defined ($location=$self->searchlocation(@_)) ) {
201 >         $rv=1;
202 >         $self->verbose("Unable to locate the top of local configuration area");
203 >        }
204 >        else {
205 >         $self->location($location);
206 >         $self->verbose("Found top ".$self->location());
207 >         my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat";
208 >         $self->_LoadEnvFile();
209 >        }
210 >        return $rv;
211   }
212  
213   sub location {
# Line 211 | Line 218 | sub location {
218          }
219          elsif ( ! defined $self->{location} ) {
220            # try and find the release location
221 <          #$self->{location}=$self->searchlocation();
221 >          $self->{location}=$self->searchlocation();
222          }
223          return  $self->{location};
224   }
# Line 221 | Line 228 | sub searchlocation {
228  
229          #start search in current directory if not specified
230          my $thispath;
231 <        @_?$thispath=shift
232 <          :$thispath=cwd();
231 >        if ( @_ ) {
232 >          $thispath=shift
233 >        }
234 >        else {
235 >          $thispath=cwd();
236 >        }
237  
238          my $rv=0;
239  
240 +        # chop off any files - we only want dirs
241 +        if ( -f $thispath ) {
242 +          $thispath=~s/(.*)\/.*/$1/;
243 +        }
244          Sloop:{
245          do {
246 < #         print "Searching $thispath\n";
246 >          $self->verbose("Searching $thispath");
247            if ( -e "$thispath/".$self->{admindir} ) {
248 < #           print "Found\n";
248 >            $self->verbose("Found\n");
249              $rv=1;
250              last Sloop;
251            }
# Line 239 | Line 254 | sub searchlocation {
254          return $rv?$thispath:undef;
255   }
256  
257 < sub meta {
257 > sub archname {
258          my $self=shift;
259 +        if ( @_ ) {
260 +          $self->{archname}=shift;
261 +        }
262 +        return $self->{archname};
263 + }
264  
265 <        my $string=$self->name()." ".$self->version()." located at :\n  ".
266 <                $self->location;
265 > sub archdir {
266 >        my $self=shift;
267 >        if ( @_ ) {
268 >          $self->{archdir}=shift;
269 >        }
270 >        if ( ! defined $self->{archdir} ) {
271 >         if ( defined $self->{archname} ) {
272 >          $self->{archdir}=$self->location()."/".$self->{admindir}."/".
273 >                                                        $self->{archname};
274 >         }
275 >         else {
276 >          $self->error("ConfigArea : cannot create arch directory - ".
277 >                                                "architecture name not set")
278 >         }
279 >        }
280 >        return $self->{archdir};
281   }
282  
283 < sub configitem {
283 > sub satellite {
284          my $self=shift;
285 +
286 +        # -- create the sat object
287 +        my $sat=Configuration::ConfigArea->new();
288 +        $sat->name($self->name());
289 +        $sat->version($self->version());
290 +        $sat->requirementsdoc($self->{reqdoc});
291 +        $sat->configurationdir($self->configurationdir());
292 +        $sat->setup(@_);
293 +
294 +        # -- copy across the cache and ObjectStore
295 +        copy($self->cache()->location(),$sat->cache()->location());
296 +        copy($self->objectstore()->location(),$sat->objectstore()->location());
297 +
298 +        # and make sure in reinitialises
299 +        undef ($sat->{cache});
300 +
301 +        # -- link it to this area
302 +        $sat->linkarea($self);
303          
304 <        return ($self->config()->find("ConfigItem",@_));
304 >        # -- save it
305 >        $sat->save();
306 >
307 >        return $sat;
308   }
309  
310 < sub addconfigitem {
310 > sub copy {
311          my $self=shift;
312 <        my $url=shift;
312 >        my $destination=shift;
313  
314 <        my $docref=$self->activatedoc($url);
315 <        # Set up the document
316 <        $docref->setup();
317 <        $docref->save();
318 < #       $self->config()->storepolicy("local");
314 >        # copy across the admin dir
315 >        my $temp=$self->location()."/".$self->{admindir};
316 >        AddDir::copydir($temp,"$destination/".$self->{admindir});
317 > }
318 >
319 > sub align {
320 >        my $self=shift;
321 >        use File::Copy;
322 >
323 >        $self->_LoadEnvFile();
324 >        my $Envfile=$self->location()."/".$self->{admindir}."/Environment";
325 >        my $tmpEnvfile=$Envfile.".bak";
326 >        my $rel=$self->{ENV}{RELEASETOP};
327 >        my $local=$self->location();
328 >
329 >        rename( $Envfile, $tmpEnvfile );
330 >        use FileHandle;
331 >        my $fh=FileHandle->new();
332 >        my $fout=FileHandle->new();
333 >        open ( $fh, "<".$tmpEnvfile ) or
334 >                $self->error("Cannot find Environment file. Area Corrupted? ("
335 >                                .$self->location().")\n $!");
336 >        open ( $fout, ">".$Envfile ) or
337 >                $self->error("Cannot find Environment file. Area Corrupted? ("
338 >                                .$self->location().")\n $!");
339 >        while ( <$fh> ) {
340 >          $_=~s/\Q$rel\L/$local/g;
341 >          print $fout $_;
342 >        }
343 >        undef $fh;
344 >        undef $fout;
345   }
346  
347 < # -------------- Tags ---------------------------------
267 < # -- init parse
268 < sub Project_Start {
347 > sub copysetup {
348          my $self=shift;
349 <        my $name=shift;
271 <        my $hashref=shift;
349 >        my $dest=shift;
350  
351 <        $self->checktag($name,$hashref,'name');
352 <        $self->checktag($name,$hashref,'version');
353 <
354 <        $self->name($$hashref{'name'});
355 <        $self->version($$hashref{'version'});
351 >        my $rv=1;
352 >        # copy across the admin dir
353 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
354 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
355 >        if ( $temp ne $temp2 ) {
356 >         if ( -d $temp ) {
357 >          AddDir::copydir($temp,$temp2);
358 >          $rv=0;
359 >         }
360 >        }
361 >        return $rv;
362   }
363  
364 + sub copyenv {
365 +        my $self=shift;
366 +        my $hashref=shift;
367 +        
368 +        foreach $elem ( keys %{$self->{ENV}} ) {
369 +           $$hashref{$elem}=$self->{ENV}{$elem};
370 +        }
371 + }
372  
373 < sub Project_text {
373 > sub arch {
374          my $self=shift;
375 <        my $name=shift;
376 <        my $string=shift;
375 >        return $ENV{SCRAM_ARCH};
376 > }
377  
378 <        print $string;
378 > sub linkto {
379 >        my $self=shift;
380 >        my $location=shift;
381 >        if ( -d $location ) {
382 >        my $area=Configuration::ConfigArea->new();
383 >        $area->bootstrapfromlocation($location);
384 >        $self->linkarea($area);
385 >        }
386 >        else {
387 >          $self->error("ConfigArea : Unable to link to non existing directory ".
388 >                         $location);
389 >        }
390   }
391  
392 < # ---- download parse
392 > sub unlinkarea {
393 >        my $self=shift;
394 >        undef $self->{linkarea};
395 >        $self->{linkarea}=undef;
396 >        $self->save();
397 > }
398  
399 < sub Use_download_Start {
399 > sub linkarea {
400          my $self=shift;
401 <        my $name=shift;
402 <        my $hashref=shift;
401 >        my $area=shift;
402 >        if ( defined $area ) {
403 >          $self->{linkarea}=$area;
404 >        }
405 >        return (defined $self->{linkarea} && $self->{linkarea} ne "")?
406 >                        $self->{linkarea}:undef;
407 > }
408  
409 <        $self->checktag($name,$hashref,'url');
410 <        print "Downloading .... ".$$hashref{'url'}."\n";
411 <        $self->getfile($$hashref{'url'});
409 > sub save {
410 >        my $self=shift;
411 >        $self->_SaveEnvFile();
412   }
413  
414 < # --- setup parse
414 > # ---- support routines
415  
416 < sub Use_Start {
416 > sub _SaveEnvFile {
417          my $self=shift;
418 <        my $name=shift;
419 <        my $hashref=shift;
418 >        use FileHandle;
419 >        my $fh=FileHandle->new();
420 >        open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
421 >                "Environment" ) or
422 >                $self->error("Cannot Open Environment file to Save ("
423 >                                .$self->location().")\n $!");
424          
425 <        $self->checktag($name,$hashref,'url');
426 <        $self->addconfigitem($$hashref{'url'});
425 >        print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
426 >        print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
427 >        print $fh "projconfigdir=".$self->configurationdir()."\n";
428 >        print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n";
429 >        if ( defined $self->linkarea() ) {
430 >          my $area=$self->linkarea()->location();
431 >          if ( $area ne "" ) {
432 >          print $fh "RELEASETOP=".$area."\n";
433 >          }
434 >        }
435 >        undef $fh;
436   }
437  
438 +
439 + sub _LoadEnvFile {
440 +        my $self=shift;
441 +
442 +        use FileHandle;
443 +        my $fh=FileHandle->new();
444 +        open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
445 +                "Environment" ) or
446 +                $self->error("Cannot find Environment file. Area Corrupted? ("
447 +                                .$self->location().")\n $!");
448 +        while ( <$fh> ) {
449 +           chomp;
450 +           next if /^#/;
451 +           next if /^\s*$/ ;
452 +           ($name, $value)=split /=/;
453 +           eval "\$self->{ENV}{${name}}=\"$value\"";
454 +        }
455 +        undef $fh;
456 +        
457 +        # -- set internal variables appropriately
458 +        if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} ) {
459 +          $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
460 +        }
461 +        if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} ) {
462 +          $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
463 +        }
464 +        if ( defined $self->{ENV}{"projconfigdir"} ) {
465 +          $self->configurationdir($self->{ENV}{projconfigdir});
466 +        }
467 +        if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} ) {
468 +          $self->requirementsdoc($self->{ENV}{SCRAM_ProjReqsDoc});
469 +        }
470 +        if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
471 +                        ($self->{ENV}{"RELEASETOP"} ne $self->location())) {
472 +          $self->linkto($self->{ENV}{"RELEASETOP"});
473 +        }
474 +        else {
475 +          $self->{ENV}{"RELEASETOP"}=$self->location();
476 +        }
477 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines