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