1 |
|
# |
2 |
|
# ConfigArea.pm |
3 |
|
# |
4 |
< |
# Originally Written by Christopher Williams |
4 |
> |
# 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 |
|
# --------- |
17 |
< |
# new(ActiveConfig) : A new ConfigArea object |
18 |
< |
# setup() : setup the configuration area |
19 |
< |
# location([dir]) : set/return the location of the area |
20 |
< |
# version([version]) : set/return the version of the area |
21 |
< |
# name([name]) : set/return the name of the area |
15 |
< |
# store(location) : store data in file location |
16 |
< |
# restore(location) : restore data from file location |
17 |
< |
# meta() : return a description string of the area |
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 |
17 |
> |
# new() : A new ConfigArea object |
18 |
> |
# location([dir]) : set/return the location of the work area |
19 |
> |
# bootstrapfromlocation([location]) : bootstrap the object based on location. |
20 |
> |
# no location specified - cwd used |
21 |
> |
# return 0 if succesful 1 otherwise |
22 |
|
# searchlocation([startdir]) : returns the location directory. search starts |
23 |
|
# from cwd if not specified |
24 |
|
# defaultdirname() : return the default directory name string |
25 |
< |
# copy(location) : make a copy of the current area at the |
26 |
< |
# specified location - return an object |
27 |
< |
# representing the area |
25 |
> |
# scramversion() : return the scram version associated with |
26 |
> |
# area |
27 |
> |
# configurationdir() : return the location of the project |
28 |
> |
# configuration directory |
29 |
> |
# copy(location) : copy a configuration |
30 |
> |
# copysetup(location) : copy the architecture specific tool setup |
31 |
> |
# returns 0 if successful, 1 otherwise |
32 |
> |
# copyenv($ref) : copy the areas environment into the hashref |
33 |
|
|
34 |
|
package Configuration::ConfigArea; |
32 |
– |
use ActiveDoc::ActiveDoc; |
35 |
|
require 5.004; |
36 |
|
use Utilities::AddDir; |
37 |
< |
use ObjectUtilities::ObjectStore; |
37 |
> |
use Utilities::Verbose; |
38 |
|
use Cwd; |
39 |
< |
@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"); |
45 |
< |
$self->addtag("init","project",\&Project_Start,$self, |
46 |
< |
\&Project_text,$self,"", $self ); |
47 |
< |
$self->addurltags("download"); |
48 |
< |
$self->addtag("download","use",\&Use_download_Start,$self, |
49 |
< |
"", $self, "",$self); |
50 |
< |
$self->addurltags("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 |
< |
} |
39 |
> |
@ISA=qw(Utilities::Verbose); |
40 |
|
|
41 |
< |
sub setup { |
42 |
< |
my $self=shift; |
41 |
> |
sub new { |
42 |
> |
my $class=shift; |
43 |
> |
my $self={}; |
44 |
> |
bless $self, $class; |
45 |
|
|
46 |
< |
# --- find out the location |
47 |
< |
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"); |
76 |
< |
if ( ! defined $name ) { |
77 |
< |
$name=$self->defaultdirname(); |
78 |
< |
} |
79 |
< |
$self->location($location."/".$name); |
80 |
< |
|
81 |
< |
# make a new store handler |
82 |
< |
$self->_setupstore(); |
83 |
< |
|
84 |
< |
# --- download everything first |
85 |
< |
# FIX-ME --- cacheing is broken |
86 |
< |
$self->parse("download"); |
87 |
< |
|
88 |
< |
# --- and parse the setup file |
89 |
< |
$self->parse("setup"); |
90 |
< |
|
91 |
< |
# --- store bootstrap info |
92 |
< |
$self->store($self->location()."/.SCRAM/ConfigArea.dat"); |
46 |
> |
# data init |
47 |
> |
$self->{admindir}=".SCRAM"; |
48 |
|
|
49 |
< |
# --- store self in original database |
95 |
< |
$self->parentconfig()->store($self,"ConfigArea",$self->name(), |
96 |
< |
$self->version()); |
49 |
> |
return $self; |
50 |
|
} |
51 |
|
|
52 |
< |
sub _setupstore { |
100 |
< |
my $self=shift; |
101 |
< |
|
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 |
< |
$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 { |
52 |
> |
sub configurationdir { |
53 |
|
my $self=shift; |
54 |
< |
|
55 |
< |
if ( ! defined $self->location(@_) ) { |
118 |
< |
$self->error("Unable to locate the top of local configuration area"); |
54 |
> |
if ( @_ ) { |
55 |
> |
$self->{configurationdir}=shift; |
56 |
|
} |
57 |
< |
print "Found top ".$self->location()."\n"; |
58 |
< |
$self->_setupstore(); |
59 |
< |
$self->restore($self->location()."/.SCRAM/ConfigArea.dat"); |
60 |
< |
} |
61 |
< |
|
62 |
< |
sub parentconfig { |
63 |
< |
my $self=shift; |
64 |
< |
@_?$self->{parentconfig}=shift |
65 |
< |
:$self->{parentconfig}; |
66 |
< |
} |
67 |
< |
|
68 |
< |
sub store { |
69 |
< |
my $self=shift; |
70 |
< |
my $location=shift; |
71 |
< |
|
72 |
< |
my $fh=$self->openfile(">".$location); |
73 |
< |
$self->savevar($fh,"location", $self->location()); |
74 |
< |
$self->savevar($fh,"url", $self->url()); |
75 |
< |
$self->savevar($fh,"name", $self->name()); |
76 |
< |
$self->savevar($fh,"version", $self->version()); |
77 |
< |
$fh->close(); |
57 |
> |
if ( ! defined $self->{configurationdir} ) { |
58 |
> |
$self->_LoadEnvFile(); |
59 |
> |
$self->{configurationdir}=$self->{ENV}{projconfigdir}; |
60 |
> |
} |
61 |
> |
return $self->{configurationdir}; |
62 |
> |
} |
63 |
> |
|
64 |
> |
sub scramversion { |
65 |
> |
my $self=shift; |
66 |
> |
if ( ! defined $self->{scramversion} ) { |
67 |
> |
my $filename=$self->location()."/".$self->configurationdir()."/". |
68 |
> |
"scram_version"; |
69 |
> |
if ( -f $filename ) { |
70 |
> |
use FileHandle; |
71 |
> |
$fh=FileHandle->new(); |
72 |
> |
open ($fh, "<".$filename); |
73 |
> |
my $version=<$fh>; |
74 |
> |
chomp $version; |
75 |
> |
$self->{scramversion}=$version; |
76 |
> |
undef $fh; |
77 |
> |
} |
78 |
> |
} |
79 |
> |
return $self->{scramversion}; |
80 |
|
} |
81 |
|
|
82 |
< |
sub copy { |
82 |
> |
sub bootstrapfromlocation { |
83 |
|
my $self=shift; |
145 |
– |
my $destination=shift; |
146 |
– |
use File::Basename; |
147 |
– |
# create the area |
84 |
|
|
85 |
< |
AddDir::adddir(dirname($destination)); |
85 |
> |
my $rv=0; |
86 |
|
|
87 |
< |
my @cpcmd=(qw(cp -r), "$self->location()", "$destination"); |
88 |
< |
print "@cpcmd"; |
89 |
< |
# File::Copy::copy("$self->location()", "$destination") or |
90 |
< |
system(@cpcmd) or |
91 |
< |
$self->error("Cannot copy ".$self->location(). |
92 |
< |
" to $destination ".$!); |
93 |
< |
|
94 |
< |
# create a new object based on the new area |
95 |
< |
my $newarea=ref($self)->new($self->parentconfig()); |
96 |
< |
$newarea->bootstrapfromlocation($destination); |
97 |
< |
# save it with the new location info |
98 |
< |
$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 |
< |
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(); |
180 |
< |
} |
181 |
< |
|
182 |
< |
sub name { |
183 |
< |
my $self=shift; |
184 |
< |
|
185 |
< |
@_?$self->{name}=shift |
186 |
< |
:$self->{name}; |
187 |
< |
} |
188 |
< |
|
189 |
< |
sub version { |
190 |
< |
my $self=shift; |
191 |
< |
|
192 |
< |
@_?$self->{version}=shift |
193 |
< |
:$self->{version}; |
87 |
> |
my $location; |
88 |
> |
if ( ! defined ($location=$self->searchlocation(@_)) ) { |
89 |
> |
$rv=1; |
90 |
> |
$self->verbose("Unable to locate the top of local configuration area"); |
91 |
> |
} |
92 |
> |
else { |
93 |
> |
$self->location($location); |
94 |
> |
$self->verbose("Found top ".$self->location()); |
95 |
> |
my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat"; |
96 |
> |
$self->_LoadEnvFile(); |
97 |
> |
} |
98 |
> |
return $rv; |
99 |
|
} |
100 |
|
|
101 |
|
sub location { |
116 |
|
|
117 |
|
#start search in current directory if not specified |
118 |
|
my $thispath; |
119 |
< |
@_?$thispath=shift |
120 |
< |
:$thispath=cwd(); |
119 |
> |
if ( @_ ) { |
120 |
> |
$thispath=shift |
121 |
> |
} |
122 |
> |
else { |
123 |
> |
$thispath=cwd(); |
124 |
> |
} |
125 |
|
|
126 |
|
my $rv=0; |
127 |
|
|
128 |
+ |
print $thispath." --not shortened\n"; |
129 |
+ |
# chop off any files - we only want dirs |
130 |
+ |
if ( -f $thispath ) { |
131 |
+ |
$thispath=~s/(.*)\/.*/$1/; |
132 |
+ |
print $thispath." --shortened\n"; |
133 |
+ |
} |
134 |
|
Sloop:{ |
135 |
|
do { |
136 |
< |
# print "Searching $thispath\n"; |
137 |
< |
if ( -e "$thispath/.SCRAM" ) { |
138 |
< |
# print "Found\n"; |
136 |
> |
$self->verbose("Searching $thispath"); |
137 |
> |
if ( -e "$thispath/".$self->{admindir} ) { |
138 |
> |
$self->verbose("Found\n"); |
139 |
|
$rv=1; |
140 |
|
last Sloop; |
141 |
|
} |
144 |
|
return $rv?$thispath:undef; |
145 |
|
} |
146 |
|
|
147 |
< |
sub meta { |
147 |
> |
sub copy { |
148 |
|
my $self=shift; |
149 |
+ |
my $destination=shift; |
150 |
|
|
151 |
< |
my $string=$self->name()." ".$self->version()." located at :\n ". |
152 |
< |
$self->location; |
151 |
> |
# copy across the admin dir |
152 |
> |
my $temp=$self->location()."/".$self->{admindir}; |
153 |
> |
AddDir::copydir($temp,"$destination/".$self->{admindir}); |
154 |
|
} |
155 |
|
|
156 |
< |
sub configitem { |
156 |
> |
sub copysetup { |
157 |
|
my $self=shift; |
158 |
< |
|
242 |
< |
return ($self->config()->find("ConfigItem",@_)); |
243 |
< |
} |
158 |
> |
my $dest=shift; |
159 |
|
|
160 |
< |
sub addconfigitem { |
161 |
< |
my $self=shift; |
162 |
< |
my $url=shift; |
163 |
< |
|
164 |
< |
my $docref=$self->activatedoc($url); |
165 |
< |
# Set up the document |
166 |
< |
$docref->setup(); |
167 |
< |
# $self->config()->storepolicy("local"); |
168 |
< |
$docref->save(); |
160 |
> |
my $rv=1; |
161 |
> |
# copy across the admin dir |
162 |
> |
my $temp=$self->location()."/".$self->{admindir}."/".$self->arch(); |
163 |
> |
my $temp2=$dest."/".$self->{admindir}."/".$self->arch(); |
164 |
> |
if ( $temp ne $temp2 ) { |
165 |
> |
if ( -d $temp ) { |
166 |
> |
AddDir::copydir($temp,$temp2); |
167 |
> |
$rv=0; |
168 |
> |
} |
169 |
> |
} |
170 |
> |
return $rv; |
171 |
|
} |
172 |
|
|
173 |
< |
# -------------- Tags --------------------------------- |
257 |
< |
# -- init parse |
258 |
< |
sub Project_Start { |
173 |
> |
sub copyenv { |
174 |
|
my $self=shift; |
260 |
– |
my $name=shift; |
175 |
|
my $hashref=shift; |
176 |
< |
|
177 |
< |
$self->checktag($name,$hashref,'name'); |
178 |
< |
$self->checktag($name,$hashref,'version'); |
179 |
< |
|
266 |
< |
$self->name($$hashref{'name'}); |
267 |
< |
$self->version($$hashref{'version'}); |
268 |
< |
} |
269 |
< |
|
270 |
< |
|
271 |
< |
sub Project_text { |
272 |
< |
my $self=shift; |
273 |
< |
my $name=shift; |
274 |
< |
my $string=shift; |
275 |
< |
|
276 |
< |
print $string; |
176 |
> |
|
177 |
> |
foreach $elem ( keys %{$self->{ENV}} ) { |
178 |
> |
$$hashref{$elem}=$self->{ENV}{$elem}; |
179 |
> |
} |
180 |
|
} |
181 |
|
|
182 |
< |
# ---- download parse |
280 |
< |
|
281 |
< |
sub Use_download_Start { |
182 |
> |
sub arch { |
183 |
|
my $self=shift; |
184 |
< |
my $name=shift; |
284 |
< |
my $hashref=shift; |
285 |
< |
|
286 |
< |
$self->checktag($name,$hashref,'url'); |
287 |
< |
print "Downloading .... ".$$hashref{'url'}."\n"; |
288 |
< |
$self->getfile($$hashref{'url'}); |
184 |
> |
return $ENV{SCRAM_ARCH}; |
185 |
|
} |
186 |
|
|
187 |
< |
# --- setup parse |
188 |
< |
|
189 |
< |
sub Use_Start { |
190 |
< |
my $self=shift; |
191 |
< |
my $name=shift; |
192 |
< |
my $hashref=shift; |
193 |
< |
|
194 |
< |
$self->checktag($name,$hashref,'url'); |
195 |
< |
$self->addconfigitem($$hashref{'url'}); |
187 |
> |
# ---- support routines |
188 |
> |
sub _LoadEnvFile { |
189 |
> |
my $self=shift; |
190 |
> |
|
191 |
> |
use FileHandle; |
192 |
> |
my $fh=FileHandle->new(); |
193 |
> |
open ( $fh, "<".$self->location()."/".$self->{admindir}."/". |
194 |
> |
"Environment" ) or |
195 |
> |
$self->error("Cannot find Environment file. Area Corrupted? (" |
196 |
> |
.$self->location().")\n $!"); |
197 |
> |
while ( <$fh> ) { |
198 |
> |
chomp; |
199 |
> |
next if /^#/; |
200 |
> |
next if /^\s*$/ ; |
201 |
> |
($name, $value)=split /=/; |
202 |
> |
eval "\$self->{ENV}{${name}}=\"$value\""; |
203 |
> |
} |
204 |
> |
undef $fh; |
205 |
> |
} |
206 |
> |
|
207 |
> |
sub _savevar { |
208 |
> |
my $self=shift; |
209 |
> |
my $fh=shift; |
210 |
> |
my $name=shift; |
211 |
> |
my $val=shift; |
212 |
> |
print $fh "#".$name."\n"; |
213 |
> |
print $fh $val."\n"; |
214 |
> |
} |
215 |
> |
|
216 |
> |
sub _restorevars { |
217 |
> |
my $self=shift; |
218 |
> |
my $fh=shift; |
219 |
> |
my $varhash=shift; |
220 |
> |
|
221 |
> |
while ( <$fh>=~/^#(.*)/ ) { |
222 |
> |
$name=$1; |
223 |
> |
chomp $name; |
224 |
> |
$value=<$fh>; |
225 |
> |
chomp $value; |
226 |
> |
$$varhash{$name}=$value; |
227 |
> |
#print "Restoring ".$name."=".$value."\n"; |
228 |
> |
} |
229 |
|
} |
301 |
– |
|