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.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 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->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 );
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\_//;
109 +        $name=$name."_".$vers;
110 +        return $name;
111 + }
112 +
113 +
114   sub setup {
115          my $self=shift;
116  
117 <        # --- find out the location
118 <        my $location=$self->requestoption("area_location",
119 <                "Please Enter the location of the directory");
117 >        # --- find out the location - default is cwd
118 >        my $location=$self->option("ConfigArea_location");
119 >        if ( ! defined $location ) {
120 >                $location=cwd();
121 >        }
122 >        elsif ( $location!~/^\// ) {
123 >                $location=cwd()."/".$location;
124 >        }
125  
126          # --- find area directory name , default name projectname_version
127 <        my $name=$self->option("area_name");
52 <        my $vers=$self->version;
127 >        my $name=$self->option("ConfigArea_name");
128          if ( ! defined $name ) {
129 <          $name=$self->name();
55 <          $vers=~s/^$name_//;
56 <          $name=$name."_".$vers;
129 >          $name=$self->defaultdirname();
130          }
131          $self->location($location."/".$name);
132  
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
133          # make a new store handler
134 <        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());
134 >        $self->_setupstore();
135  
136          # --- download everything first
72 # 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");
145 +
146 +        # --- store self in original database
147 +        $self->parentconfig()->store($self,"ConfigArea",$self->name(),
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}, $self->arch());
168 +
169 +        $self->parentconfig($self->config());
170 + #        $self->config(Configuration::ConfigureStore->new());
171 + #        $self->config()->db("local",$ad);
172 + #        $self->config()->db("parent",$self->parentconfig());
173 + #        $self->config()->policy("cache","local");
174 +        $self->config($ad);
175 +        $self->config()->basedoc($self->parentconfig()->basedoc());
176 + }
177 +
178 + sub bootstrapfromlocation {
179 +        my $self=shift;
180 +        
181 +        if ( ! defined $self->location(@_) ) {
182 +          $self->error("Unable to locate the top of local configuration area");
183 +        }
184 +        $self->verbose("Found top ".$self->location());
185 +        $self->_setupstore();
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 {
196 +        my $self=shift;
197 +        @_?$self->{parentconfig}=shift
198 +          :$self->{parentconfig};
199   }
200  
201   sub store {
# Line 81 | Line 203 | sub store {
203          my $location=shift;
204  
205          my $fh=$self->openfile(">".$location);
206 <        print $fh $self->location()."\n";
206 >        $self->savevar($fh,"location", $self->location());
207 >        $self->savevar($fh,"url", $self->url());
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;
224 +        use File::Basename;
225 +        # create the area
226 +
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 +        # 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}.
246 +                                                        "/ConfigArea.dat");
247 +        return $newarea;
248   }
249  
250   sub restore {
251          my $self=shift;
252 +        my $location=shift;
253  
254          my $fh=$self->openfile("<".$location);
255 <        $self->{location}=<$fh>;
256 <        chomp $self->{location};
255 >        my $varhash={};
256 >        $self->restorevars($fh,$varhash);
257 >        if ( ! defined $self->location() ) {
258 >          $self->location($$varhash{"location"});
259 >        }
260 >        $self->_setupstore();
261 >        $self->url($$varhash{"url"});
262 >        $self->name($$varhash{"name"});
263 >        $self->version($$varhash{"version"});
264          $fh->close();
265  
266 +        $self->_restorestructures();
267   }
268  
269   sub name {
# Line 112 | Line 283 | sub version {
283   sub location {
284          my $self=shift;
285  
286 <        @_?$self->{location}=shift
287 <          :$self->{location};
286 >        if ( @_ ) {
287 >          $self->{location}=shift;
288 >        }
289 >        elsif ( ! defined $self->{location} ) {
290 >          # try and find the release location
291 >          $self->{location}=$self->searchlocation();
292 >        }
293 >        return  $self->{location};
294 > }
295 >
296 > sub searchlocation {
297 >        my $self=shift;
298 >
299 >        #start search in current directory if not specified
300 >        my $thispath;
301 >        @_?$thispath=shift
302 >          :$thispath=cwd();
303 >
304 >        my $rv=0;
305 >
306 >        Sloop:{
307 >        do {
308 > #         print "Searching $thispath\n";
309 >          if ( -e "$thispath/".$self->{admindir} ) {
310 > #           print "Found\n";
311 >            $rv=1;
312 >            last Sloop;
313 >          }
314 >        } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
315 >
316 >        return $rv?$thispath:undef;
317   }
318  
319   sub meta {
# Line 125 | Line 325 | sub meta {
325  
326   sub configitem {
327          my $self=shift;
128        my $location=shift;
328          
329 <        $self->config()->find("ConfigItem",@_);
329 >        return ($self->config()->find("ConfigItem",@_));
330   }
331  
332   sub addconfigitem {
# Line 137 | Line 336 | sub addconfigitem {
336          my $docref=$self->activatedoc($url);
337          # Set up the document
338          $docref->setup();
339 <        $self->config()->storepolicy("local");
340 <        $docref->save();
339 >        $docref->save();
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 166 | 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 178 | 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