18 |
|
# addconfigitem(url) : add a new item to the area |
19 |
|
# 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 |
24 |
+ |
# searchlocation([startdir]) : returns the location directory. search starts |
25 |
+ |
# from cwd if not specified |
26 |
+ |
# defaultdirname() : return the default directory name string |
27 |
+ |
# copy(location) : make a copy of the current area at the |
28 |
+ |
# specified location - return an object |
29 |
+ |
# representing the area |
30 |
+ |
# linkarea(oref) : link area with another |
31 |
|
|
32 |
|
package Configuration::ConfigArea; |
33 |
|
use ActiveDoc::ActiveDoc; |
34 |
|
require 5.004; |
35 |
|
use Utilities::AddDir; |
36 |
|
use ObjectUtilities::ObjectStore; |
37 |
+ |
use Cwd; |
38 |
|
@ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject); |
39 |
|
|
40 |
|
sub init { |
41 |
|
my $self=shift; |
42 |
+ |
|
43 |
|
$self->newparse("init"); |
44 |
|
$self->newparse("download"); |
45 |
|
$self->newparse("setup"); |
46 |
|
$self->addtag("init","project",\&Project_Start,$self, |
47 |
< |
\&Project_text,$self,"", $self ); |
47 |
> |
\&Project_text,$self,"", $self ); |
48 |
|
$self->addurltags("download"); |
49 |
|
$self->addtag("download","use",\&Use_download_Start,$self, |
50 |
|
"", $self, "",$self); |
52 |
|
$self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self); |
53 |
|
} |
54 |
|
|
55 |
+ |
|
56 |
+ |
sub defaultdirname { |
57 |
+ |
my $self=shift; |
58 |
+ |
my $name=$self->name(); |
59 |
+ |
my $vers=$self->version(); |
60 |
+ |
$vers=~s/^$name_//; |
61 |
+ |
$name=$name."_".$vers; |
62 |
+ |
return $name; |
63 |
+ |
|
64 |
+ |
} |
65 |
+ |
|
66 |
|
sub setup { |
67 |
|
my $self=shift; |
68 |
|
|
69 |
< |
# --- find out the location |
70 |
< |
my $location=$self->requestoption("area_location", |
71 |
< |
"Please Enter the location of the directory"); |
69 |
> |
# --- find out the location - default is cwd |
70 |
> |
my $location=$self->option("area_location"); |
71 |
> |
if ( ! defined $location ) { |
72 |
> |
$location=cwd(); |
73 |
> |
} |
74 |
> |
elsif ( $location!~/^\// ) { |
75 |
> |
$location=cwd()."/".$location; |
76 |
> |
} |
77 |
|
|
78 |
|
# --- find area directory name , default name projectname_version |
79 |
|
my $name=$self->option("area_name"); |
52 |
– |
my $vers=$self->version; |
80 |
|
if ( ! defined $name ) { |
81 |
< |
$name=$self->name(); |
55 |
< |
$vers=~s/^$name_//; |
56 |
< |
$name=$name."_".$vers; |
81 |
> |
$name=$self->defaultdirname(); |
82 |
|
} |
83 |
|
$self->location($location."/".$name); |
84 |
|
|
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 |
– |
|
85 |
|
# make a new store handler |
86 |
< |
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()); |
86 |
> |
$self->_setupstore(); |
87 |
|
|
88 |
|
# --- download everything first |
89 |
|
# FIX-ME --- cacheing is broken |
91 |
|
|
92 |
|
# --- and parse the setup file |
93 |
|
$self->parse("setup"); |
94 |
+ |
|
95 |
+ |
# --- store bootstrap info |
96 |
+ |
$self->store($self->location()."/.SCRAM/ConfigArea.dat"); |
97 |
+ |
|
98 |
+ |
# --- store self in original database |
99 |
+ |
$self->parentconfig()->store($self,"ConfigArea",$self->name(), |
100 |
+ |
$self->version()); |
101 |
+ |
} |
102 |
+ |
|
103 |
+ |
sub _setupstore { |
104 |
+ |
my $self=shift; |
105 |
+ |
|
106 |
+ |
# --- make a new ActiveStore at the location and add it to the db list |
107 |
+ |
my $ad=ActiveDoc::ActiveConfig->new($self->location()."/\.SCRAM"); |
108 |
+ |
|
109 |
+ |
$self->parentconfig($self->config()); |
110 |
+ |
# $self->config(Configuration::ConfigureStore->new()); |
111 |
+ |
# $self->config()->db("local",$ad); |
112 |
+ |
# $self->config()->db("parent",$self->parentconfig()); |
113 |
+ |
# $self->config()->policy("cache","local"); |
114 |
+ |
$self->config($ad); |
115 |
+ |
$self->config()->basedoc($self->parentconfig()->basedoc()); |
116 |
+ |
} |
117 |
+ |
|
118 |
+ |
sub bootstrapfromlocation { |
119 |
+ |
my $self=shift; |
120 |
+ |
|
121 |
+ |
if ( ! defined $self->location(@_) ) { |
122 |
+ |
$self->error("Unable to locate the top of local configuration area"); |
123 |
+ |
} |
124 |
+ |
print "Found top ".$self->location()."\n"; |
125 |
+ |
$self->_setupstore(); |
126 |
+ |
$self->restore($self->location()."/.SCRAM/ConfigArea.dat"); |
127 |
+ |
} |
128 |
+ |
|
129 |
+ |
sub parentconfig { |
130 |
+ |
my $self=shift; |
131 |
+ |
@_?$self->{parentconfig}=shift |
132 |
+ |
:$self->{parentconfig}; |
133 |
|
} |
134 |
|
|
135 |
|
sub store { |
137 |
|
my $location=shift; |
138 |
|
|
139 |
|
my $fh=$self->openfile(">".$location); |
140 |
< |
print $fh $self->location()."\n"; |
140 |
> |
$self->savevar($fh,"location", $self->location()); |
141 |
> |
$self->savevar($fh,"url", $self->url()); |
142 |
> |
$self->savevar($fh,"name", $self->name()); |
143 |
> |
$self->savevar($fh,"version", $self->version()); |
144 |
|
$fh->close(); |
145 |
|
} |
146 |
|
|
147 |
+ |
sub copy { |
148 |
+ |
my $self=shift; |
149 |
+ |
my $destination=shift; |
150 |
+ |
use File::Basename; |
151 |
+ |
# create the area |
152 |
+ |
|
153 |
+ |
AddDir::adddir(dirname($destination)); |
154 |
+ |
|
155 |
+ |
$temp=$self->location(); |
156 |
+ |
my @cpcmd=(qw(cp -r), "$temp", "$destination"); |
157 |
+ |
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 |
+ |
|
163 |
+ |
# create a new object based on the new area |
164 |
+ |
my $newarea=ref($self)->new($self->parentconfig()); |
165 |
+ |
$newarea->bootstrapfromlocation($destination); |
166 |
+ |
# save it with the new location info |
167 |
+ |
$newarea->store($self->location()."/.SCRAM/ConfigArea.dat"); |
168 |
+ |
} |
169 |
+ |
|
170 |
|
sub restore { |
171 |
|
my $self=shift; |
172 |
+ |
my $location=shift; |
173 |
|
|
174 |
|
my $fh=$self->openfile("<".$location); |
175 |
< |
$self->{location}=<$fh>; |
176 |
< |
chomp $self->{location}; |
175 |
> |
my $varhash={}; |
176 |
> |
$self->restorevars($fh,$varhash); |
177 |
> |
if ( ! defined $self->location() ) { |
178 |
> |
$self->location($$varhash{"location"}); |
179 |
> |
} |
180 |
> |
$self->_setupstore(); |
181 |
> |
$self->url($$varhash{"url"}); |
182 |
> |
$self->name($$varhash{"name"}); |
183 |
> |
$self->version($$varhash{"version"}); |
184 |
|
$fh->close(); |
95 |
– |
|
185 |
|
} |
186 |
|
|
187 |
|
sub name { |
201 |
|
sub location { |
202 |
|
my $self=shift; |
203 |
|
|
204 |
< |
@_?$self->{location}=shift |
205 |
< |
:$self->{location}; |
204 |
> |
if ( @_ ) { |
205 |
> |
$self->{location}=shift; |
206 |
> |
} |
207 |
> |
elsif ( ! defined $self->{location} ) { |
208 |
> |
# try and find the release location |
209 |
> |
$self->{location}=$self->searchlocation(); |
210 |
> |
} |
211 |
> |
return $self->{location}; |
212 |
> |
} |
213 |
> |
|
214 |
> |
sub searchlocation { |
215 |
> |
my $self=shift; |
216 |
> |
|
217 |
> |
#start search in current directory if not specified |
218 |
> |
my $thispath; |
219 |
> |
@_?$thispath=shift |
220 |
> |
:$thispath=cwd(); |
221 |
> |
|
222 |
> |
my $rv=0; |
223 |
> |
|
224 |
> |
Sloop:{ |
225 |
> |
do { |
226 |
> |
# print "Searching $thispath\n"; |
227 |
> |
if ( -e "$thispath/.SCRAM" ) { |
228 |
> |
# print "Found\n"; |
229 |
> |
$rv=1; |
230 |
> |
last Sloop; |
231 |
> |
} |
232 |
> |
} while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) }; |
233 |
> |
|
234 |
> |
return $rv?$thispath:undef; |
235 |
|
} |
236 |
|
|
237 |
|
sub meta { |
243 |
|
|
244 |
|
sub configitem { |
245 |
|
my $self=shift; |
128 |
– |
my $location=shift; |
246 |
|
|
247 |
< |
$self->config()->find("ConfigItem",@_); |
247 |
> |
return ($self->config()->find("ConfigItem",@_)); |
248 |
|
} |
249 |
|
|
250 |
|
sub addconfigitem { |
254 |
|
my $docref=$self->activatedoc($url); |
255 |
|
# Set up the document |
256 |
|
$docref->setup(); |
257 |
< |
$self->config()->storepolicy("local"); |
141 |
< |
$docref->save(); |
257 |
> |
# $self->config()->storepolicy("local"); |
258 |
|
} |
259 |
|
|
260 |
|
# -------------- Tags --------------------------------- |