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 |
|
|
27 |
|
package Configuration::ConfigArea; |
28 |
|
use ActiveDoc::ActiveDoc; |
33 |
|
|
34 |
|
sub init { |
35 |
|
my $self=shift; |
36 |
+ |
|
37 |
|
$self->newparse("init"); |
38 |
|
$self->newparse("download"); |
39 |
|
$self->newparse("setup"); |
63 |
|
} |
64 |
|
$self->location($location."/".$name); |
65 |
|
|
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 |
– |
|
66 |
|
# make a new store handler |
67 |
< |
my $parentconfig=$self->config; |
65 |
< |
$self->config(Configuration::ConfigureStore); |
66 |
< |
$self->config()->db("local",$ad); |
67 |
< |
$self->config()->db("parent",$parentconfig); |
68 |
< |
$self->config()->policy("cache","local"); |
69 |
< |
$self->config()->basedoc($parentconfig->basedoc()); |
67 |
> |
$self->_setupstore(); |
68 |
|
|
69 |
|
# --- download everything first |
70 |
|
# FIX-ME --- cacheing is broken |
71 |
< |
# $self->parse("download"); |
71 |
> |
$self->parse("download"); |
72 |
|
|
73 |
|
# --- and parse the setup file |
74 |
|
$self->parse("setup"); |
75 |
+ |
|
76 |
+ |
# --- store bootstrap info |
77 |
+ |
$self->store($self->location()."/.SCRAM/ConfigArea.dat"); |
78 |
+ |
|
79 |
+ |
# --- store self in original database |
80 |
+ |
$self->parentconfig()->store($self,"ConfigArea",$self->name(), |
81 |
+ |
$self->version()); |
82 |
+ |
} |
83 |
+ |
|
84 |
+ |
sub _setupstore { |
85 |
+ |
my $self=shift; |
86 |
+ |
|
87 |
+ |
# --- make a new ActiveStore at the location and add it to the db list |
88 |
+ |
my $ad=ActiveDoc::ActiveConfig->new($self->location()."/\.SCRAM"); |
89 |
+ |
|
90 |
+ |
$self->parentconfig($self->config()); |
91 |
+ |
# $self->config(Configuration::ConfigureStore->new()); |
92 |
+ |
# $self->config()->db("local",$ad); |
93 |
+ |
# $self->config()->db("parent",$self->parentconfig()); |
94 |
+ |
# $self->config()->policy("cache","local"); |
95 |
+ |
$self->config($ad); |
96 |
+ |
$self->config()->basedoc($self->parentconfig()->basedoc()); |
97 |
+ |
} |
98 |
+ |
|
99 |
+ |
sub bootstrapfromlocation { |
100 |
+ |
my $self=shift; |
101 |
+ |
|
102 |
+ |
if ( ! defined $self->location(@_) ) { |
103 |
+ |
$self->error("Unable to locate the top of local configuration area"); |
104 |
+ |
} |
105 |
+ |
$self->_setupstore(); |
106 |
+ |
$self->restore($self->location()."/.SCRAM/ConfigArea.dat"); |
107 |
+ |
} |
108 |
+ |
|
109 |
+ |
sub parentconfig { |
110 |
+ |
my $self=shift; |
111 |
+ |
@_?$self->{parentconfig}=shift |
112 |
+ |
:$self->{parentconfig}; |
113 |
|
} |
114 |
|
|
115 |
|
sub store { |
117 |
|
my $location=shift; |
118 |
|
|
119 |
|
my $fh=$self->openfile(">".$location); |
120 |
< |
print $fh $self->location()."\n"; |
120 |
> |
$self->savevar($fh,"location", $self->location()); |
121 |
> |
$self->savevar($fh,"url", $self->url()); |
122 |
> |
$self->savevar($fh,"name", $self->name()); |
123 |
> |
$self->savevar($fh,"version", $self->version()); |
124 |
|
$fh->close(); |
125 |
|
} |
126 |
|
|
127 |
|
sub restore { |
128 |
|
my $self=shift; |
129 |
+ |
my $location=shift; |
130 |
|
|
131 |
|
my $fh=$self->openfile("<".$location); |
132 |
< |
$self->{location}=<$fh>; |
133 |
< |
chomp $self->{location}; |
132 |
> |
my $varhash={}; |
133 |
> |
$self->restorevars($fh,$varhash); |
134 |
> |
if ( ! defined $self->location() ) { |
135 |
> |
$self->location($$varhash{"location"}); |
136 |
> |
} |
137 |
> |
$self->_setupstore(); |
138 |
> |
$self->url($$varhash{"url"}); |
139 |
> |
$self->name($$varhash{"name"}); |
140 |
> |
$self->version($$varhash{"version"}); |
141 |
|
$fh->close(); |
95 |
– |
|
142 |
|
} |
143 |
|
|
144 |
|
sub name { |
158 |
|
sub location { |
159 |
|
my $self=shift; |
160 |
|
|
161 |
< |
@_?$self->{location}=shift |
162 |
< |
:$self->{location}; |
161 |
> |
if ( @_ ) { |
162 |
> |
$self->{location}=shift |
163 |
> |
} |
164 |
> |
elsif ( ! defined $self->{location} ) { |
165 |
> |
# try and find the release location |
166 |
> |
$self->searchlocation(); |
167 |
> |
} |
168 |
> |
return $self->{location}; |
169 |
> |
} |
170 |
> |
|
171 |
> |
sub searchlocation { |
172 |
> |
my $self=shift; |
173 |
> |
use Cwd; |
174 |
> |
|
175 |
> |
#start search in current directory if not specified |
176 |
> |
my $thispath; |
177 |
> |
@_?$thispath=shift |
178 |
> |
:$thispath=cwd; |
179 |
> |
|
180 |
> |
my $rv=0; |
181 |
> |
|
182 |
> |
do { |
183 |
> |
if ( -e "$thispath/.SCRAM" ) { |
184 |
> |
$rv=1; |
185 |
> |
} |
186 |
> |
} while ( ( $thispath=~s/(.*)\/.*/$1/ )=~/./ ); |
187 |
> |
|
188 |
> |
return $rv?$thispath:undef; |
189 |
|
} |
190 |
|
|
191 |
|
sub meta { |
197 |
|
|
198 |
|
sub configitem { |
199 |
|
my $self=shift; |
128 |
– |
my $location=shift; |
200 |
|
|
201 |
< |
$self->config()->find("ConfigItem",@_); |
201 |
> |
return ($self->config()->find("ConfigItem",@_)); |
202 |
|
} |
203 |
|
|
204 |
|
sub addconfigitem { |
208 |
|
my $docref=$self->activatedoc($url); |
209 |
|
# Set up the document |
210 |
|
$docref->setup(); |
211 |
< |
$self->config()->savepolicy("local"); |
211 |
> |
# $self->config()->storepolicy("local"); |
212 |
|
$docref->save(); |
213 |
|
} |
214 |
|
|