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.2 by williamc, Thu Jan 20 19:05:47 2000 UTC vs.
Revision 1.9 by williamc, Wed Feb 23 13:24:13 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 18 | Line 25
25   # addconfigitem(url)            : add a new item to the area
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 - 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;
51   require 5.004;
52   use Utilities::AddDir;
53   use ObjectUtilities::ObjectStore;
54 < @ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject);
54 > use Configuration::ConfigStore;
55 > use Configuration::ActiveDoc_arch;
56 > use Cwd;
57 > @ISA=qw(Configuration::ActiveDoc_arch ObjectUtilities::StorableObject);
58  
59   sub init {
60          my $self=shift;
61 +
62          $self->newparse("init");
63          $self->newparse("download");
64          $self->newparse("setup");
65          $self->addtag("init","project",\&Project_Start,$self,
66 <        \&Project_text,$self,"", $self );
66 >            \&Project_text,$self,"", $self );
67          $self->addurltags("download");
68 +        $self->addtag("download","download",\&Download_Start,$self,
69 +                                                "", $self, "",$self);
70          $self->addtag("download","use",\&Use_download_Start,$self,
71                                                  "", $self, "",$self);
72          $self->addurltags("setup");
73          $self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self);
74 +        $self->addtag("setup","structure",\&Structure_Start,$self,
75 +                         "", $self, "",$self);
76 +
77 +        # data init
78 +        $self->{admindir}=".SCRAM";
79 + }
80 +
81 + sub basearea {
82 +        my $self=shift;
83 +
84 +        my $area;
85 +        if ( @_ ) {
86 +          $area=shift;
87 +          $self->config()->store($area,"BaseArea");
88 +        }
89 +        else {
90 +          ($area)=$self->config()->restore("BaseArea");
91 +        }
92 +        return $area;
93 + }
94 +
95 + sub freebase {
96 +        my $self=shift;
97 +        $self->config()->delete("BaseArea");
98   }
99  
100 + sub defaultdirname {
101 +        my $self=shift;
102 +        my $name=$self->name();
103 +        my $vers=$self->version();
104 +        $vers=~s/^$name\_//;
105 +        $name=$name."_".$vers;
106 +        return $name;
107 + }
108 +
109 +
110   sub setup {
111          my $self=shift;
112  
113 <        # --- find out the location
114 <        my $location=$self->requestoption("area_location",
115 <                "Please Enter the location of the directory");
113 >        # --- find out the location - default is cwd
114 >        my $location=$self->option("ConfigArea_location");
115 >        if ( ! defined $location ) {
116 >                $location=cwd();
117 >        }
118 >        elsif ( $location!~/^\// ) {
119 >                $location=cwd()."/".$location;
120 >        }
121  
122          # --- find area directory name , default name projectname_version
123 <        my $name=$self->option("area_name");
52 <        my $vers=$self->version;
123 >        my $name=$self->option("ConfigArea_name");
124          if ( ! defined $name ) {
125 <          $name=$self->name();
55 <          $vers=~s/^$name_//;
56 <          $name=$name."_".$vers;
125 >          $name=$self->defaultdirname();
126          }
127          $self->location($location."/".$name);
128  
60        # --- make a new ActiveStore at the location and add it to the db list
61        my $ad=ActiveDoc::ActiveConfig->new($self->location()."/\.SCRAM");
62
129          # make a new store handler
130 <        my $parentconfig=$self->config;
65 <        $self->config(Configuration::ConfigureStore->new());
66 <        $self->config()->db("local",$ad);
67 <        $self->config()->db("parent",$parentconfig);
68 <        $self->config()->policy("cache","local");
69 <        $self->config()->basedoc($parentconfig->basedoc());
130 >        $self->_setupstore();
131  
132          # --- download everything first
72 # FIX-ME --- cacheing is broken
133          $self->parse("download");
134          
135          # --- and parse the setup file
136          $self->parse("setup");
137 +        
138 +        # --- store bootstrap info
139 +        $self->store($self->location()."/".$self->{admindir}."/ConfigArea.dat");
140 +
141 +        # --- store self in original database
142 +        $self->parentconfig()->store($self,"ConfigArea",$self->name(),
143 +                                                        $self->version());
144 + }
145 +
146 + sub structure {
147 +        my $self=shift;
148 +        my $vr=shift;
149 +        return $self->{structures}{$vr};
150 + }
151 +
152 + sub structurelist {
153 +        my $self=shift;
154 +        return ( keys %{$self->{structures}} );
155 + }
156 +
157 + sub _setupstore {
158 +        my $self=shift;
159 +
160 +        # --- make a new ConfigStore at the location and add it to the db list
161 +        my $ad=Configuration::ConfigStore->new($self->location().
162 +                                "/".$self->{admindir}, $self->arch());
163 +
164 +        $self->parentconfig($self->config());
165 + #        $self->config(Configuration::ConfigureStore->new());
166 + #        $self->config()->db("local",$ad);
167 + #        $self->config()->db("parent",$self->parentconfig());
168 + #        $self->config()->policy("cache","local");
169 +        $self->config($ad);
170 +        $self->config()->basedoc($self->parentconfig()->basedoc());
171 + }
172 +
173 + sub bootstrapfromlocation {
174 +        my $self=shift;
175 +        
176 +        if ( ! defined $self->location(@_) ) {
177 +          $self->error("Unable to locate the top of local configuration area");
178 +        }
179 +        print "Found top ".$self->location()."\n";
180 +        $self->_setupstore();
181 +        $self->restore($self->location()."/".$self->{admindir}.
182 +                                                "/ConfigArea.dat");
183 + }
184 +
185 + sub parentconfig {
186 +        my $self=shift;
187 +        @_?$self->{parentconfig}=shift
188 +          :$self->{parentconfig};
189   }
190  
191   sub store {
# Line 81 | Line 193 | sub store {
193          my $location=shift;
194  
195          my $fh=$self->openfile(">".$location);
196 <        print $fh $self->location()."\n";
196 >        $self->savevar($fh,"location", $self->location());
197 >        $self->savevar($fh,"url", $self->url());
198 >        $self->savevar($fh,"name", $self->name());
199 >        $self->savevar($fh,"version", $self->version());
200          $fh->close();
201 +
202 +        $self->_storestructures();
203 + }
204 +
205 + sub satellite {
206 +        my $self=shift;
207 +        my $newarea=$self->copy(@_);
208 +        $newarea->_makesatellites();
209 +        return $newarea;
210 + }
211 +
212 + sub copy {
213 +        my $self=shift;
214 +        use File::Basename;
215 +        # create the area
216 +
217 +        my $destination;
218 +        if ( @_ ) {
219 +         $destination=shift;
220 +        }
221 +        else {
222 +          my($location,$name)=$self->_defaultoptions();
223 +          $destination=$location."/".$name
224 +        }
225 +        #AddDir::adddir(dirname($destination)."/".$self->{admindir});
226 +        #AddDir::adddir($destination."/".$self->{admindir});
227 +        
228 +        # copy across the admin dir
229 +        $temp=$self->location()."/".$self->{admindir};
230 +        AddDir::copydir($temp,"$destination/".$self->{admindir});
231 +        # create a new object based on the new area
232 +        my $newarea=ref($self)->new($self->parentconfig());
233 +        $newarea->bootstrapfromlocation($destination);
234 +        # save it with the new location info
235 +        $newarea->store($self->location()."/".$self->{admindir}.
236 +                                                        "/ConfigArea.dat");
237 +        return $newarea;
238   }
239  
240   sub restore {
241          my $self=shift;
242 +        my $location=shift;
243  
244          my $fh=$self->openfile("<".$location);
245 <        $self->{location}=<$fh>;
246 <        chomp $self->{location};
245 >        my $varhash={};
246 >        $self->restorevars($fh,$varhash);
247 >        if ( ! defined $self->location() ) {
248 >          $self->location($$varhash{"location"});
249 >        }
250 >        $self->_setupstore();
251 >        $self->url($$varhash{"url"});
252 >        $self->name($$varhash{"name"});
253 >        $self->version($$varhash{"version"});
254          $fh->close();
255  
256 +        $self->_restorestructures();
257   }
258  
259   sub name {
# Line 112 | Line 273 | sub version {
273   sub location {
274          my $self=shift;
275  
276 <        @_?$self->{location}=shift
277 <          :$self->{location};
276 >        if ( @_ ) {
277 >          $self->{location}=shift;
278 >        }
279 >        elsif ( ! defined $self->{location} ) {
280 >          # try and find the release location
281 >          $self->{location}=$self->searchlocation();
282 >        }
283 >        return  $self->{location};
284 > }
285 >
286 > sub searchlocation {
287 >        my $self=shift;
288 >
289 >        #start search in current directory if not specified
290 >        my $thispath;
291 >        @_?$thispath=shift
292 >          :$thispath=cwd();
293 >
294 >        my $rv=0;
295 >
296 >        Sloop:{
297 >        do {
298 > #         print "Searching $thispath\n";
299 >          if ( -e "$thispath/".$self->{admindir} ) {
300 > #           print "Found\n";
301 >            $rv=1;
302 >            last Sloop;
303 >          }
304 >        } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
305 >
306 >        return $rv?$thispath:undef;
307   }
308  
309   sub meta {
# Line 125 | Line 315 | sub meta {
315  
316   sub configitem {
317          my $self=shift;
128        my $location=shift;
318          
319 <        $self->config()->find("ConfigItem",@_);
319 >        return ($self->config()->find("ConfigItem",@_));
320   }
321  
322   sub addconfigitem {
# Line 137 | Line 326 | sub addconfigitem {
326          my $docref=$self->activatedoc($url);
327          # Set up the document
328          $docref->setup();
329 <        $self->config()->storepolicy("local");
330 <        $docref->save();
329 >        $docref->save();
330 > #       $self->config()->storepolicy("local");
331 > }
332 >
333 > sub downloadtotop {
334 >        my $self=shift;
335 >        my $url=shift;
336 >        my $dir=shift;
337 >        
338 >        # only download once
339 >        if ( ! -e $self->location()."/".$dir ) {
340 >          $self->{urlhandler}->download($url,$self->location()."/".$dir);
341 >        }
342 > }
343 >
344 > sub _makesatellites {
345 >        my $self=shift;
346 >        foreach $st ( values %{$self->{structures}} ) {
347 >           $st->setupsatellite()
348 >        }
349 > }
350 >
351 > sub _storestructures {
352 >        my $self=shift;
353 >        foreach $struct ( values %{$self->{structures}} ) {
354 >          $self->config()->store($struct, "Structures", $struct->name());
355 >        }
356   }
357  
358 + sub _restorestructures {
359 +        my $self=shift;
360 +        my @strs=$self->config()->find("Structures");
361 +        foreach $struct ( @strs ) {
362 +          $struct->parent($self);
363 +          $self->{structures}{$struct->name()}=$struct;
364 +        }
365 + }
366 +
367 + sub _defaultoptions {
368 +        my $self=shift;
369 +        my $name;
370 +        my $location;
371 +
372 +        # --- find out the location - default is cwd
373 +        $location=$self->option("ConfigArea_location");
374 +        if ( ! defined $location ) {
375 +                $location=cwd();
376 +        }
377 +        elsif ( $location!~/^\// ) {
378 +                $location=cwd()."/".$location;
379 +        }
380 +
381 +        # --- find area directory name , default name projectname_version
382 +        $name=$self->option("ConfigArea_name");
383 +        if ( ! defined $name ) {
384 +          $name=$self->defaultdirname();
385 +        }
386 +        return ($location,$name);
387 + }
388   # -------------- Tags ---------------------------------
389   # -- init parse
390   sub Project_Start {
# Line 166 | Line 410 | sub Project_text {
410  
411   # ---- download parse
412  
413 + sub Download_Start {
414 +        my $self=shift;
415 +        my $name=shift;
416 +        my $hashref=shift;
417 +
418 +        $self->checktag($name,$hashref,'url');
419 +        $self->checktag($name,$hashref,'location');
420 +        if ( $$hashref{'location'}!~/^\w/ ) {
421 +          $self->parseerror("location must start with an".
422 +                " alphanumeric character");
423 +        }
424 +        print "Downloading .... ".$$hashref{'url'}."\n";
425 +        $self->downloadtotop($$hashref{'url'},$$hashref{'location'});
426 + }
427 +
428   sub Use_download_Start {
429          my $self=shift;
430          my $name=shift;
# Line 178 | Line 437 | sub Use_download_Start {
437  
438   # --- setup parse
439  
440 + sub Structure_Start {
441 +        my $self=shift;
442 +        my $name=shift;
443 +        my $hashref=shift;
444 +
445 +        $self->checktag($name,$hashref,'name');
446 +        if ( !( exists $$hashref{'type'}) || ( exists $$hashref{'url'}) ) {
447 +            $self->parseerror("No url or type given in <$name> tag");
448 +        }
449 +        if ( ! exists $self->{structures}{$$hashref{'name'}} ) {
450 +          if ( exists $$hashref{'type'}) {
451 +            # create a new object of the specified type
452 +            eval "require $$hashref{'type'} ";
453 +            if  ( $@ ) {
454 +                $self->parseerror("Unable to instantiate type=".
455 +                        $$hashref{'type'}." in <$name> .".$@);
456 +            }
457 +            $self->{structures}{$$hashref{'name'}}=
458 +                $$hashref{'type'}->new($self->config());
459 +            $self->{structures}{$$hashref{'name'}}->name($$hashref{'name'});
460 +            $self->{structures}{$$hashref{'name'}}->parent($self);
461 +            $self->{structures}{$$hashref{'name'}}->vars($hashref);
462 +          }
463 +          else { # its an activedoc
464 +                $self->{structures}{$$hashref{'name'}}=
465 +                                $self->activatedoc($$hashref{'url'});
466 +          }
467 +          $self->{structures}{$$hashref{'name'}}->setupbase();
468 +        }
469 +        else {
470 +             $self->parseerror("Multiply defined Structure - ".
471 +                                                        $$hashref{'name'});
472 +        }
473 + }
474 +
475   sub Use_Start {
476          my $self=shift;
477          my $name=shift;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines