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.12 by williamc, Thu Mar 2 16:02:41 2000 UTC

# Line 4 | Line 4
4   # Originally Written by Christopher Williams
5   #
6   # Description
7 + # -----------
8 + # creates and manages a configuration area
9 + #
10 + # Options
11 + # -------
12 + # ConfigArea_location
13 + # ConfigArea_name
14   #
15   # Interface
16   # ---------
# Line 19 | Line 26
26   # configitem(@keys)             : return a list of fig items that match
27   #                                 the keys - all if left blank
28   # parentstore()                 : set/return the parent ObjectStore
29 + # basearea(ConfigArea)          : Set/Get the base area
30 + # freebase()                    : Remove any link to a base area
31   # bootstrapfromlocation([location]): bootstrap the object based on location.
32   #                                 no location specified - cwd used
33   # searchlocation([startdir])    : returns the location directory. search starts
34   #                                 from cwd if not specified
35   # defaultdirname()              : return the default directory name string
36   # copy(location)                : make a copy of the current area at the
37 < #                                 specified location - return an object
38 < #                                 representing the area
37 > #                                 specified location - defaults to cwd/default
38 > #                                 if not specified . ConfigArea_name,
39 > #                                 ConfigArea_location also override .
40 > #                                 Return an object representing the area
41 > # satellite()                   : make a satellite area based on $self
42 > # arch([archobj])               : Set/get the architecture object
43 > # structure(name)               : return the object corresponding to the
44 > #                                 structure name
45 > # structurelist()               : return list of structure objectS
46 > # downloadtotop(dir,url)        : download the url to a dir in the config area
47 > #                                
48  
49   package Configuration::ConfigArea;
50   use ActiveDoc::ActiveDoc;
# Line 34 | Line 52 | require 5.004;
52   use Utilities::AddDir;
53   use ObjectUtilities::ObjectStore;
54   use Configuration::ConfigStore;
55 + use Configuration::ActiveDoc_arch;
56   use Cwd;
57 < @ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject);
57 > @ISA=qw(Configuration::ActiveDoc_arch ObjectUtilities::StorableObject);
58  
59   sub init {
60          my $self=shift;
# Line 43 | Line 62 | sub init {
62          $self->newparse("init");
63          $self->newparse("download");
64          $self->newparse("setup");
65 +        $self->newparse("setup_tools");
66 +        $self->addarchtags("setup_tools");
67 +        $self->addarchtags("setup");
68          $self->addtag("init","project",\&Project_Start,$self,
69              \&Project_text,$self,"", $self );
70          $self->addurltags("download");
71 +        $self->addtag("download","download",\&Download_Start,$self,
72 +                                                "", $self, "",$self);
73          $self->addtag("download","use",\&Use_download_Start,$self,
74                                                  "", $self, "",$self);
75          $self->addurltags("setup");
76 <        $self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self);
76 >        $self->addurltags("setup_tools");
77 >        $self->addtag("setup_tools","use",\&Use_Start,$self, "", $self, "",$self);
78 >        $self->addtag("setup","structure",\&Structure_Start,$self,
79 >                         "", $self, "",$self);
80  
81          # data init
82          $self->{admindir}=".SCRAM";
83   }
84  
85 + sub basearea {
86 +        my $self=shift;
87 +
88 +        my $area;
89 +        if ( @_ ) {
90 +          $area=shift;
91 +          $self->config()->store($area,"BaseArea");
92 +        }
93 +        else {
94 +          ($area)=$self->config()->find("BaseArea");
95 +        }
96 +        return $area;
97 + }
98 +
99 + sub freebase {
100 +        my $self=shift;
101 +        $self->config()->delete("BaseArea");
102 + }
103  
104   sub defaultdirname {
105          my $self=shift;
106          my $name=$self->name();
107          my $vers=$self->version();
108 <        $vers=~s/^$name_//;
108 >        $vers=~s/^$name\_//;
109          $name=$name."_".$vers;
110          return $name;
66
111   }
112  
113 +
114   sub setup {
115          my $self=shift;
116  
117          # --- find out the location - default is cwd
118 <        my $location=$self->option("area_location");
118 >        my $location=$self->option("ConfigArea_location");
119          if ( ! defined $location ) {
120                  $location=cwd();
121          }
# Line 79 | Line 124 | sub setup {
124          }
125  
126          # --- find area directory name , default name projectname_version
127 <        my $name=$self->option("area_name");
127 >        my $name=$self->option("ConfigArea_name");
128          if ( ! defined $name ) {
129            $name=$self->defaultdirname();
130          }
# Line 89 | Line 134 | sub setup {
134          $self->_setupstore();
135  
136          # --- download everything first
92 # FIX-ME --- cacheing is broken
137          $self->parse("download");
138          
139          # --- and parse the setup file
140          $self->parse("setup");
141 +        $self->parse("setup_tools");
142          
143          # --- store bootstrap info
144          $self->store($self->location()."/".$self->{admindir}."/ConfigArea.dat");
# Line 103 | Line 148 | sub setup {
148                                                          $self->version());
149   }
150  
151 + sub structure {
152 +        my $self=shift;
153 +        my $vr=shift;
154 +        return $self->{structures}{$vr};
155 + }
156 +
157 + sub structurelist {
158 +        my $self=shift;
159 +        return ( keys %{$self->{structures}} );
160 + }
161 +
162   sub _setupstore {
163          my $self=shift;
164  
165          # --- make a new ConfigStore at the location and add it to the db list
166          my $ad=Configuration::ConfigStore->new($self->location().
167 <                                "/".$self->{admindir});
167 >                                "/".$self->{admindir}, $self->arch());
168  
169          $self->parentconfig($self->config());
170   #        $self->config(Configuration::ConfigureStore->new());
# Line 125 | Line 181 | sub bootstrapfromlocation {
181          if ( ! defined $self->location(@_) ) {
182            $self->error("Unable to locate the top of local configuration area");
183          }
184 <        print "Found top ".$self->location()."\n";
184 >        $self->verbose("Found top ".$self->location());
185          $self->_setupstore();
186 <        $self->restore($self->location()."/".$self->{admindir}.
187 <                                                "/ConfigArea.dat");
186 >        my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat";
187 >        if ( -e $infofile ) {
188 >             $self->restore($infofile);
189 >        }
190 >        else {
191 >             $self->error("Area corrupted - cannot find $infofile");
192 >        }
193   }
194  
195   sub parentconfig {
# Line 147 | Line 208 | sub store {
208          $self->savevar($fh,"name", $self->name());
209          $self->savevar($fh,"version", $self->version());
210          $fh->close();
211 +
212 +        $self->_storestructures();
213 + }
214 +
215 + sub satellite {
216 +        my $self=shift;
217 +        my $newarea=$self->copy(@_);
218 +        $newarea->_makesatellites();
219 +        return $newarea;
220   }
221  
222   sub copy {
223          my $self=shift;
154        my $destination=shift;
224          use File::Basename;
225          # create the area
226  
227 <        AddDir::adddir(dirname($destination));
227 >        my $destination;
228 >        if ( @_ ) {
229 >         $destination=shift;
230 >        }
231 >        else {
232 >          my($location,$name)=$self->_defaultoptions();
233 >          $destination=$location."/".$name
234 >        }
235 >        #AddDir::adddir(dirname($destination)."/".$self->{admindir});
236 >        #AddDir::adddir($destination."/".$self->{admindir});
237          
238 <        $temp=$self->location();
239 <        my @cpcmd=(qw(cp -r), "$temp", "$destination");
240 <        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 <
238 >        # copy across the admin dir
239 >        $temp=$self->location()."/".$self->{admindir};
240 >        AddDir::copydir($temp,"$destination/".$self->{admindir});
241          # create a new object based on the new area
242          my $newarea=ref($self)->new($self->parentconfig());
243          $newarea->bootstrapfromlocation($destination);
244          # save it with the new location info
245 <        $newarea->store($self->location()."/".$self->{admindir}."/ConfigArea.dat");
245 >        $newarea->store($self->location()."/".$self->{admindir}.
246 >                                                        "/ConfigArea.dat");
247 >        return $newarea;
248   }
249  
250   sub restore {
# Line 187 | Line 262 | sub restore {
262          $self->name($$varhash{"name"});
263          $self->version($$varhash{"version"});
264          $fh->close();
265 +
266 +        $self->_restorestructures();
267   }
268  
269   sub name {
# Line 211 | Line 288 | sub location {
288          }
289          elsif ( ! defined $self->{location} ) {
290            # try and find the release location
291 <          #$self->{location}=$self->searchlocation();
291 >          $self->{location}=$self->searchlocation();
292          }
293          return  $self->{location};
294   }
# Line 263 | Line 340 | sub addconfigitem {
340   #       $self->config()->storepolicy("local");
341   }
342  
343 + sub downloadtotop {
344 +        my $self=shift;
345 +        my $url=shift;
346 +        my $dir=shift;
347 +        
348 +        # only download once
349 +        if ( ! -e $self->location()."/".$dir ) {
350 +          $self->{urlhandler}->download($url,$self->location()."/".$dir);
351 +        }
352 + }
353 +
354 + sub _makesatellites {
355 +        my $self=shift;
356 +        foreach $st ( values %{$self->{structures}} ) {
357 +           $st->setupsatellite()
358 +        }
359 + }
360 +
361 + sub _storestructures {
362 +        my $self=shift;
363 +        foreach $struct ( values %{$self->{structures}} ) {
364 +          $self->config()->store($struct, "Structures", $struct->name());
365 +        }
366 + }
367 +
368 + sub _restorestructures {
369 +        my $self=shift;
370 +        my @strs=$self->config()->find("Structures");
371 +        foreach $struct ( @strs ) {
372 +          $struct->parent($self);
373 +          $self->{structures}{$struct->name()}=$struct;
374 +        }
375 + }
376 +
377 + sub _defaultoptions {
378 +        my $self=shift;
379 +        my $name;
380 +        my $location;
381 +
382 +        # --- find out the location - default is cwd
383 +        $location=$self->option("ConfigArea_location");
384 +        if ( ! defined $location ) {
385 +                $location=cwd();
386 +        }
387 +        elsif ( $location!~/^\// ) {
388 +                $location=cwd()."/".$location;
389 +        }
390 +
391 +        # --- find area directory name , default name projectname_version
392 +        $name=$self->option("ConfigArea_name");
393 +        if ( ! defined $name ) {
394 +          $name=$self->defaultdirname();
395 +        }
396 +        return ($location,$name);
397 + }
398   # -------------- Tags ---------------------------------
399   # -- init parse
400   sub Project_Start {
# Line 288 | Line 420 | sub Project_text {
420  
421   # ---- download parse
422  
423 + sub Download_Start {
424 +        my $self=shift;
425 +        my $name=shift;
426 +        my $hashref=shift;
427 +
428 +        $self->checktag($name,$hashref,'url');
429 +        $self->checktag($name,$hashref,'location');
430 +        if ( $$hashref{'location'}!~/^\w/ ) {
431 +          $self->parseerror("location must start with an".
432 +                " alphanumeric character");
433 +        }
434 +        print "Downloading .... ".$$hashref{'url'}."\n";
435 +        $self->downloadtotop($$hashref{'url'},$$hashref{'location'});
436 + }
437 +
438   sub Use_download_Start {
439          my $self=shift;
440          my $name=shift;
# Line 300 | Line 447 | sub Use_download_Start {
447  
448   # --- setup parse
449  
450 + sub Structure_Start {
451 +        my $self=shift;
452 +        my $name=shift;
453 +        my $hashref=shift;
454 +
455 +        $self->checktag($name,$hashref,'name');
456 +        if ( !(( exists $$hashref{'type'}) || ( exists $$hashref{'url'})) ) {
457 +            $self->parseerror("No url or type given in <$name> tag");
458 +        }
459 +        if ( ! exists $self->{structures}{$$hashref{'name'}} ) {
460 +          if ( exists $$hashref{'type'}) {
461 +            # create a new object of the specified type
462 +            eval "require $$hashref{'type'} ";
463 +            if  ( $@ ) {
464 +                $self->parseerror("Unable to instantiate type=".
465 +                        $$hashref{'type'}." in <$name> .".$@);
466 +            }
467 +            $self->{structures}{$$hashref{'name'}}=
468 +                $$hashref{'type'}->new($self->config());
469 +            $self->{structures}{$$hashref{'name'}}->name($$hashref{'name'});
470 +            $self->{structures}{$$hashref{'name'}}->parent($self);
471 +            $self->{structures}{$$hashref{'name'}}->vars($hashref);
472 +            $self->{structures}{$$hashref{'name'}}->arch($self->arch());
473 +          }
474 +          else { # its an activedoc
475 +                $self->{structures}{$$hashref{'name'}}=
476 +                                $self->activatedoc($$hashref{'url'});
477 +          }
478 +          $self->{structures}{$$hashref{'name'}}->setupbase();
479 +        }
480 +        else {
481 +             $self->parseerror("Multiply defined Structure - ".
482 +                                                        $$hashref{'name'});
483 +        }
484 + }
485 +
486   sub Use_Start {
487          my $self=shift;
488          my $name=shift;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines