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 |
|
# --------- |
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 |
39 |
< |
# linkarea(oref) : link area with another |
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 |
+ |
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; |
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->addtag("setup_tools","use",\&Use_Start,$self, "", $self, "",$self); |
77 |
> |
$self->addtag("setup","structure",\&Structure_Start,$self, |
78 |
> |
"", $self, "",$self); |
79 |
> |
|
80 |
> |
# data init |
81 |
> |
$self->{admindir}=".SCRAM"; |
82 |
> |
} |
83 |
> |
|
84 |
> |
sub basearea { |
85 |
> |
my $self=shift; |
86 |
> |
|
87 |
> |
my $area; |
88 |
> |
if ( @_ ) { |
89 |
> |
$area=shift; |
90 |
> |
$self->config()->store($area,"BaseArea"); |
91 |
> |
} |
92 |
> |
else { |
93 |
> |
($area)=$self->config()->restore("BaseArea"); |
94 |
> |
} |
95 |
> |
return $area; |
96 |
|
} |
97 |
|
|
98 |
+ |
sub freebase { |
99 |
+ |
my $self=shift; |
100 |
+ |
$self->config()->delete("BaseArea"); |
101 |
+ |
} |
102 |
|
|
103 |
|
sub defaultdirname { |
104 |
|
my $self=shift; |
105 |
< |
my $name=$self->name(); |
106 |
< |
my $vers=$self->version(); |
107 |
< |
$vers=~s/^$name_//; |
108 |
< |
$name=$name."_".$vers; |
109 |
< |
return $name; |
63 |
< |
|
105 |
> |
my $name=$self->name(); |
106 |
> |
my $vers=$self->version(); |
107 |
> |
$vers=~s/^$name\_//; |
108 |
> |
$name=$name."_".$vers; |
109 |
> |
return $name; |
110 |
|
} |
111 |
|
|
112 |
+ |
|
113 |
|
sub setup { |
114 |
|
my $self=shift; |
115 |
|
|
116 |
|
# --- find out the location - default is cwd |
117 |
< |
my $location=$self->option("area_location"); |
117 |
> |
my $location=$self->option("ConfigArea_location"); |
118 |
|
if ( ! defined $location ) { |
119 |
|
$location=cwd(); |
120 |
|
} |
123 |
|
} |
124 |
|
|
125 |
|
# --- find area directory name , default name projectname_version |
126 |
< |
my $name=$self->option("area_name"); |
126 |
> |
my $name=$self->option("ConfigArea_name"); |
127 |
|
if ( ! defined $name ) { |
128 |
|
$name=$self->defaultdirname(); |
129 |
|
} |
133 |
|
$self->_setupstore(); |
134 |
|
|
135 |
|
# --- download everything first |
89 |
– |
# FIX-ME --- cacheing is broken |
136 |
|
$self->parse("download"); |
137 |
|
|
138 |
|
# --- and parse the setup file |
139 |
|
$self->parse("setup"); |
140 |
+ |
$self->parse("setup_tools"); |
141 |
|
|
142 |
|
# --- store bootstrap info |
143 |
< |
$self->store($self->location()."/.SCRAM/ConfigArea.dat"); |
143 |
> |
$self->store($self->location()."/".$self->{admindir}."/ConfigArea.dat"); |
144 |
|
|
145 |
|
# --- store self in original database |
146 |
|
$self->parentconfig()->store($self,"ConfigArea",$self->name(), |
147 |
|
$self->version()); |
148 |
|
} |
149 |
|
|
150 |
+ |
sub structure { |
151 |
+ |
my $self=shift; |
152 |
+ |
my $vr=shift; |
153 |
+ |
return $self->{structures}{$vr}; |
154 |
+ |
} |
155 |
+ |
|
156 |
+ |
sub structurelist { |
157 |
+ |
my $self=shift; |
158 |
+ |
return ( keys %{$self->{structures}} ); |
159 |
+ |
} |
160 |
+ |
|
161 |
|
sub _setupstore { |
162 |
|
my $self=shift; |
163 |
|
|
164 |
< |
# --- make a new ActiveStore at the location and add it to the db list |
165 |
< |
my $ad=ActiveDoc::ActiveConfig->new($self->location()."/\.SCRAM"); |
164 |
> |
# --- make a new ConfigStore at the location and add it to the db list |
165 |
> |
my $ad=Configuration::ConfigStore->new($self->location(). |
166 |
> |
"/".$self->{admindir}, $self->arch()); |
167 |
|
|
168 |
|
$self->parentconfig($self->config()); |
169 |
|
# $self->config(Configuration::ConfigureStore->new()); |
182 |
|
} |
183 |
|
print "Found top ".$self->location()."\n"; |
184 |
|
$self->_setupstore(); |
185 |
< |
$self->restore($self->location()."/.SCRAM/ConfigArea.dat"); |
185 |
> |
$self->restore($self->location()."/".$self->{admindir}. |
186 |
> |
"/ConfigArea.dat"); |
187 |
|
} |
188 |
|
|
189 |
|
sub parentconfig { |
202 |
|
$self->savevar($fh,"name", $self->name()); |
203 |
|
$self->savevar($fh,"version", $self->version()); |
204 |
|
$fh->close(); |
205 |
+ |
|
206 |
+ |
$self->_storestructures(); |
207 |
+ |
} |
208 |
+ |
|
209 |
+ |
sub satellite { |
210 |
+ |
my $self=shift; |
211 |
+ |
my $newarea=$self->copy(@_); |
212 |
+ |
$newarea->_makesatellites(); |
213 |
+ |
return $newarea; |
214 |
|
} |
215 |
|
|
216 |
|
sub copy { |
217 |
|
my $self=shift; |
149 |
– |
my $destination=shift; |
218 |
|
use File::Basename; |
219 |
|
# create the area |
220 |
|
|
221 |
< |
AddDir::adddir(dirname($destination)); |
221 |
> |
my $destination; |
222 |
> |
if ( @_ ) { |
223 |
> |
$destination=shift; |
224 |
> |
} |
225 |
> |
else { |
226 |
> |
my($location,$name)=$self->_defaultoptions(); |
227 |
> |
$destination=$location."/".$name |
228 |
> |
} |
229 |
> |
#AddDir::adddir(dirname($destination)."/".$self->{admindir}); |
230 |
> |
#AddDir::adddir($destination."/".$self->{admindir}); |
231 |
|
|
232 |
< |
$temp=$self->location(); |
233 |
< |
my @cpcmd=(qw(cp -r), "$temp", "$destination"); |
234 |
< |
print "@cpcmd"."\n"; |
158 |
< |
# File::Copy::copy("$self->location()", "$destination") or |
159 |
< |
system(@cpcmd) == 0 or |
160 |
< |
$self->error("Cannot copy ".$self->location(). |
161 |
< |
" to $destination ".$!); |
162 |
< |
|
232 |
> |
# copy across the admin dir |
233 |
> |
$temp=$self->location()."/".$self->{admindir}; |
234 |
> |
AddDir::copydir($temp,"$destination/".$self->{admindir}); |
235 |
|
# create a new object based on the new area |
236 |
|
my $newarea=ref($self)->new($self->parentconfig()); |
237 |
|
$newarea->bootstrapfromlocation($destination); |
238 |
|
# save it with the new location info |
239 |
< |
$newarea->store($self->location()."/.SCRAM/ConfigArea.dat"); |
239 |
> |
$newarea->store($self->location()."/".$self->{admindir}. |
240 |
> |
"/ConfigArea.dat"); |
241 |
> |
return $newarea; |
242 |
|
} |
243 |
|
|
244 |
|
sub restore { |
256 |
|
$self->name($$varhash{"name"}); |
257 |
|
$self->version($$varhash{"version"}); |
258 |
|
$fh->close(); |
259 |
+ |
|
260 |
+ |
$self->_restorestructures(); |
261 |
|
} |
262 |
|
|
263 |
|
sub name { |
300 |
|
Sloop:{ |
301 |
|
do { |
302 |
|
# print "Searching $thispath\n"; |
303 |
< |
if ( -e "$thispath/.SCRAM" ) { |
303 |
> |
if ( -e "$thispath/".$self->{admindir} ) { |
304 |
|
# print "Found\n"; |
305 |
|
$rv=1; |
306 |
|
last Sloop; |
330 |
|
my $docref=$self->activatedoc($url); |
331 |
|
# Set up the document |
332 |
|
$docref->setup(); |
333 |
+ |
$docref->save(); |
334 |
|
# $self->config()->storepolicy("local"); |
335 |
|
} |
336 |
|
|
337 |
+ |
sub downloadtotop { |
338 |
+ |
my $self=shift; |
339 |
+ |
my $url=shift; |
340 |
+ |
my $dir=shift; |
341 |
+ |
|
342 |
+ |
# only download once |
343 |
+ |
if ( ! -e $self->location()."/".$dir ) { |
344 |
+ |
$self->{urlhandler}->download($url,$self->location()."/".$dir); |
345 |
+ |
} |
346 |
+ |
} |
347 |
+ |
|
348 |
+ |
sub _makesatellites { |
349 |
+ |
my $self=shift; |
350 |
+ |
foreach $st ( values %{$self->{structures}} ) { |
351 |
+ |
$st->setupsatellite() |
352 |
+ |
} |
353 |
+ |
} |
354 |
+ |
|
355 |
+ |
sub _storestructures { |
356 |
+ |
my $self=shift; |
357 |
+ |
foreach $struct ( values %{$self->{structures}} ) { |
358 |
+ |
$self->config()->store($struct, "Structures", $struct->name()); |
359 |
+ |
} |
360 |
+ |
} |
361 |
+ |
|
362 |
+ |
sub _restorestructures { |
363 |
+ |
my $self=shift; |
364 |
+ |
my @strs=$self->config()->find("Structures"); |
365 |
+ |
foreach $struct ( @strs ) { |
366 |
+ |
$struct->parent($self); |
367 |
+ |
$self->{structures}{$struct->name()}=$struct; |
368 |
+ |
} |
369 |
+ |
} |
370 |
+ |
|
371 |
+ |
sub _defaultoptions { |
372 |
+ |
my $self=shift; |
373 |
+ |
my $name; |
374 |
+ |
my $location; |
375 |
+ |
|
376 |
+ |
# --- find out the location - default is cwd |
377 |
+ |
$location=$self->option("ConfigArea_location"); |
378 |
+ |
if ( ! defined $location ) { |
379 |
+ |
$location=cwd(); |
380 |
+ |
} |
381 |
+ |
elsif ( $location!~/^\// ) { |
382 |
+ |
$location=cwd()."/".$location; |
383 |
+ |
} |
384 |
+ |
|
385 |
+ |
# --- find area directory name , default name projectname_version |
386 |
+ |
$name=$self->option("ConfigArea_name"); |
387 |
+ |
if ( ! defined $name ) { |
388 |
+ |
$name=$self->defaultdirname(); |
389 |
+ |
} |
390 |
+ |
return ($location,$name); |
391 |
+ |
} |
392 |
|
# -------------- Tags --------------------------------- |
393 |
|
# -- init parse |
394 |
|
sub Project_Start { |
414 |
|
|
415 |
|
# ---- download parse |
416 |
|
|
417 |
+ |
sub Download_Start { |
418 |
+ |
my $self=shift; |
419 |
+ |
my $name=shift; |
420 |
+ |
my $hashref=shift; |
421 |
+ |
|
422 |
+ |
$self->checktag($name,$hashref,'url'); |
423 |
+ |
$self->checktag($name,$hashref,'location'); |
424 |
+ |
if ( $$hashref{'location'}!~/^\w/ ) { |
425 |
+ |
$self->parseerror("location must start with an". |
426 |
+ |
" alphanumeric character"); |
427 |
+ |
} |
428 |
+ |
print "Downloading .... ".$$hashref{'url'}."\n"; |
429 |
+ |
$self->downloadtotop($$hashref{'url'},$$hashref{'location'}); |
430 |
+ |
} |
431 |
+ |
|
432 |
|
sub Use_download_Start { |
433 |
|
my $self=shift; |
434 |
|
my $name=shift; |
441 |
|
|
442 |
|
# --- setup parse |
443 |
|
|
444 |
+ |
sub Structure_Start { |
445 |
+ |
my $self=shift; |
446 |
+ |
my $name=shift; |
447 |
+ |
my $hashref=shift; |
448 |
+ |
|
449 |
+ |
$self->checktag($name,$hashref,'name'); |
450 |
+ |
if ( !(( exists $$hashref{'type'}) || ( exists $$hashref{'url'})) ) { |
451 |
+ |
$self->parseerror("No url or type given in <$name> tag"); |
452 |
+ |
} |
453 |
+ |
if ( ! exists $self->{structures}{$$hashref{'name'}} ) { |
454 |
+ |
if ( exists $$hashref{'type'}) { |
455 |
+ |
# create a new object of the specified type |
456 |
+ |
eval "require $$hashref{'type'} "; |
457 |
+ |
if ( $@ ) { |
458 |
+ |
$self->parseerror("Unable to instantiate type=". |
459 |
+ |
$$hashref{'type'}." in <$name> .".$@); |
460 |
+ |
} |
461 |
+ |
$self->{structures}{$$hashref{'name'}}= |
462 |
+ |
$$hashref{'type'}->new($self->config()); |
463 |
+ |
$self->{structures}{$$hashref{'name'}}->name($$hashref{'name'}); |
464 |
+ |
$self->{structures}{$$hashref{'name'}}->parent($self); |
465 |
+ |
$self->{structures}{$$hashref{'name'}}->vars($hashref); |
466 |
+ |
$self->{structures}{$$hashref{'name'}}->arch($self->arch()); |
467 |
+ |
} |
468 |
+ |
else { # its an activedoc |
469 |
+ |
$self->{structures}{$$hashref{'name'}}= |
470 |
+ |
$self->activatedoc($$hashref{'url'}); |
471 |
+ |
} |
472 |
+ |
$self->{structures}{$$hashref{'name'}}->setupbase(); |
473 |
+ |
} |
474 |
+ |
else { |
475 |
+ |
$self->parseerror("Multiply defined Structure - ". |
476 |
+ |
$$hashref{'name'}); |
477 |
+ |
} |
478 |
+ |
} |
479 |
+ |
|
480 |
|
sub Use_Start { |
481 |
|
my $self=shift; |
482 |
|
my $name=shift; |