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 |
22 |
< |
# store(location) : store data in file location |
23 |
< |
# restore(location) : restore data from file location |
24 |
< |
# meta() : return a description string of the area |
25 |
< |
# addconfigitem(url) : add a new item to the area |
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 |
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 |
> |
# requirementsdoc() : get set the requirements doc |
23 |
> |
# searchlocation([startdir]) : returns the location directory. search starts |
24 |
> |
# from cwd if not specified |
25 |
> |
# defaultdirname() : return the default directory name string |
26 |
> |
# scramversion() : return the scram version associated with |
27 |
> |
# area |
28 |
> |
# configurationdir() : return the location of the project |
29 |
> |
# configuration directory |
30 |
> |
# copy(location) : copy a configuration |
31 |
> |
# copysetup(location) : copy the architecture specific tool setup |
32 |
> |
# returns 0 if successful, 1 otherwise |
33 |
> |
# copyenv($ref) : copy the areas environment into the hashref |
34 |
> |
# toolbox() : return the areas toolbox object |
35 |
|
|
36 |
|
package Configuration::ConfigArea; |
24 |
– |
use ActiveDoc::ActiveDoc; |
37 |
|
require 5.004; |
38 |
|
use Utilities::AddDir; |
39 |
< |
use ObjectUtilities::ObjectStore; |
40 |
< |
@ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject); |
39 |
> |
use Utilities::Verbose; |
40 |
> |
use Cwd; |
41 |
> |
@ISA=qw(Utilities::Verbose); |
42 |
|
|
43 |
< |
sub init { |
44 |
< |
my $self=shift; |
45 |
< |
$self->newparse("init"); |
46 |
< |
$self->newparse("download"); |
34 |
< |
$self->newparse("setup"); |
35 |
< |
$self->addtag("init","project",\&Project_Start,$self, |
36 |
< |
\&Project_text,$self,"", $self ); |
37 |
< |
$self->addurltags("download"); |
38 |
< |
$self->addtag("download","use",\&Use_download_Start,$self, |
39 |
< |
"", $self, "",$self); |
40 |
< |
$self->addurltags("setup"); |
41 |
< |
$self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self); |
42 |
< |
} |
43 |
< |
|
44 |
< |
sub setup { |
45 |
< |
my $self=shift; |
46 |
< |
|
47 |
< |
# --- find out the location |
48 |
< |
my $location=$self->requestoption("area_location", |
49 |
< |
"Please Enter the location of the directory"); |
50 |
< |
|
51 |
< |
# --- find area directory name , default name projectname_version |
52 |
< |
my $name=$self->option("area_name"); |
53 |
< |
my $vers=$self->version; |
54 |
< |
if ( ! defined $name ) { |
55 |
< |
$name=$self->name(); |
56 |
< |
$vers=~s/^$name_//; |
57 |
< |
$name=$name."_".$vers; |
58 |
< |
} |
59 |
< |
$self->location($location."/".$name); |
60 |
< |
|
61 |
< |
# make a new store handler |
62 |
< |
$self->_setupstore(); |
63 |
< |
|
64 |
< |
# --- download everything first |
65 |
< |
# FIX-ME --- cacheing is broken |
66 |
< |
$self->parse("download"); |
67 |
< |
|
68 |
< |
# --- and parse the setup file |
69 |
< |
$self->parse("setup"); |
70 |
< |
|
71 |
< |
# --- store self in original database |
72 |
< |
$self->parentconfig()->store($self,"ConfigArea",$self->name(), |
73 |
< |
$self->version()); |
74 |
< |
} |
43 |
> |
sub new { |
44 |
> |
my $class=shift; |
45 |
> |
my $self={}; |
46 |
> |
bless $self, $class; |
47 |
|
|
48 |
< |
sub _setupstore { |
49 |
< |
my $self=shift; |
48 |
> |
# data init |
49 |
> |
$self->{admindir}=".SCRAM"; |
50 |
|
|
51 |
< |
# --- make a new ActiveStore at the location and add it to the db list |
80 |
< |
my $ad=ActiveDoc::ActiveConfig->new($self->location()."/\.SCRAM"); |
81 |
< |
|
82 |
< |
$self->parentconfig($self->config()); |
83 |
< |
# $self->config(Configuration::ConfigureStore->new()); |
84 |
< |
# $self->config()->db("local",$ad); |
85 |
< |
# $self->config()->db("parent",$self->parentconfig()); |
86 |
< |
# $self->config()->policy("cache","local"); |
87 |
< |
$self->config($ad); |
88 |
< |
$self->config()->basedoc($self->parentconfig()->basedoc()); |
51 |
> |
return $self; |
52 |
|
} |
53 |
|
|
54 |
< |
sub parentconfig { |
54 |
> |
sub configurationdir { |
55 |
|
my $self=shift; |
56 |
< |
@_?$self->{parentconfig}=shift |
57 |
< |
:$self->{parentconfig}; |
56 |
> |
if ( @_ ) { |
57 |
> |
$self->{configurationdir}=shift; |
58 |
> |
} |
59 |
> |
if ( ! defined $self->{configurationdir} ) { |
60 |
> |
$self->_LoadEnvFile(); |
61 |
> |
$self->{configurationdir}=$self->{ENV}{projconfigdir}; |
62 |
> |
} |
63 |
> |
return $self->{configurationdir}; |
64 |
|
} |
65 |
|
|
66 |
< |
sub store { |
66 |
> |
sub toolbox { |
67 |
|
my $self=shift; |
68 |
< |
my $location=shift; |
69 |
< |
|
70 |
< |
my $fh=$self->openfile(">".$location); |
71 |
< |
$self->savevar($fh,"location", $self->location()); |
103 |
< |
$self->savevar($fh,"url", $self->url()); |
104 |
< |
$self->savevar($fh,"name", $self->name()); |
105 |
< |
$self->savevar($fh,"version", $self->version()); |
106 |
< |
$fh->close(); |
68 |
> |
if ( ! defined $self->{toolbox} ) { |
69 |
> |
$self->{toolbox}=BuildSystem::ToolBox->new($self); |
70 |
> |
} |
71 |
> |
return $self->{toolbox}; |
72 |
|
} |
73 |
|
|
74 |
< |
sub restore { |
74 |
> |
sub requirementsdoc { |
75 |
|
my $self=shift; |
76 |
< |
my $location=shift; |
77 |
< |
|
78 |
< |
my $fh=$self->openfile("<".$location); |
79 |
< |
my $varhash={}; |
80 |
< |
$self->restorevars($fh,$varhash); |
81 |
< |
$self->location($$varhash{"location"}); |
82 |
< |
$self->_setupstore(); |
83 |
< |
$self->url($$varhash{"url"}); |
119 |
< |
$self->name($$varhash{"name"}); |
120 |
< |
$self->version($$varhash{"version"}); |
121 |
< |
$fh->close(); |
76 |
> |
if ( @_ ) { |
77 |
> |
$self->{reqdoc}=shift; |
78 |
> |
} |
79 |
> |
if ( ! defined $self->{reqdoc} ) { |
80 |
> |
$self->_LoadEnvFile(); |
81 |
> |
$self->{reqdoc}=$self->{ENV}{SCRAM_ProjReqsDoc}; |
82 |
> |
} |
83 |
> |
return $self->{reqdoc}; |
84 |
|
} |
85 |
|
|
86 |
< |
sub name { |
86 |
> |
sub scramversion { |
87 |
|
my $self=shift; |
88 |
< |
|
89 |
< |
@_?$self->{name}=shift |
90 |
< |
:$self->{name}; |
88 |
> |
if ( ! defined $self->{scramversion} ) { |
89 |
> |
my $filename=$self->location()."/".$self->configurationdir()."/". |
90 |
> |
"scram_version"; |
91 |
> |
if ( -f $filename ) { |
92 |
> |
use FileHandle; |
93 |
> |
$fh=FileHandle->new(); |
94 |
> |
open ($fh, "<".$filename); |
95 |
> |
my $version=<$fh>; |
96 |
> |
chomp $version; |
97 |
> |
$self->{scramversion}=$version; |
98 |
> |
undef $fh; |
99 |
> |
} |
100 |
> |
} |
101 |
> |
return $self->{scramversion}; |
102 |
|
} |
103 |
|
|
104 |
< |
sub version { |
104 |
> |
sub bootstrapfromlocation { |
105 |
|
my $self=shift; |
106 |
|
|
107 |
< |
@_?$self->{version}=shift |
108 |
< |
:$self->{version}; |
107 |
> |
my $rv=0; |
108 |
> |
|
109 |
> |
my $location; |
110 |
> |
if ( ! defined ($location=$self->searchlocation(@_)) ) { |
111 |
> |
$rv=1; |
112 |
> |
$self->verbose("Unable to locate the top of local configuration area"); |
113 |
> |
} |
114 |
> |
else { |
115 |
> |
$self->location($location); |
116 |
> |
$self->verbose("Found top ".$self->location()); |
117 |
> |
my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat"; |
118 |
> |
$self->_LoadEnvFile(); |
119 |
> |
} |
120 |
> |
return $rv; |
121 |
|
} |
122 |
|
|
123 |
|
sub location { |
124 |
|
my $self=shift; |
125 |
|
|
126 |
< |
@_?$self->{location}=shift |
127 |
< |
:$self->{location}; |
126 |
> |
if ( @_ ) { |
127 |
> |
$self->{location}=shift; |
128 |
> |
} |
129 |
> |
elsif ( ! defined $self->{location} ) { |
130 |
> |
# try and find the release location |
131 |
> |
$self->{location}=$self->searchlocation(); |
132 |
> |
} |
133 |
> |
return $self->{location}; |
134 |
|
} |
135 |
|
|
136 |
< |
sub meta { |
136 |
> |
sub searchlocation { |
137 |
|
my $self=shift; |
138 |
|
|
139 |
< |
my $string=$self->name()." ".$self->version()." located at :\n ". |
140 |
< |
$self->location; |
141 |
< |
} |
139 |
> |
#start search in current directory if not specified |
140 |
> |
my $thispath; |
141 |
> |
if ( @_ ) { |
142 |
> |
$thispath=shift |
143 |
> |
} |
144 |
> |
else { |
145 |
> |
$thispath=cwd(); |
146 |
> |
} |
147 |
> |
|
148 |
> |
my $rv=0; |
149 |
|
|
150 |
< |
sub configitem { |
151 |
< |
my $self=shift; |
152 |
< |
my $location=shift; |
153 |
< |
|
154 |
< |
$self->config()->find("ConfigItem",@_); |
150 |
> |
# chop off any files - we only want dirs |
151 |
> |
if ( -f $thispath ) { |
152 |
> |
$thispath=~s/(.*)\/.*/$1/; |
153 |
> |
} |
154 |
> |
Sloop:{ |
155 |
> |
do { |
156 |
> |
$self->verbose("Searching $thispath"); |
157 |
> |
if ( -e "$thispath/".$self->{admindir} ) { |
158 |
> |
$self->verbose("Found\n"); |
159 |
> |
$rv=1; |
160 |
> |
last Sloop; |
161 |
> |
} |
162 |
> |
} while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) }; |
163 |
> |
|
164 |
> |
return $rv?$thispath:undef; |
165 |
|
} |
166 |
|
|
167 |
< |
sub addconfigitem { |
167 |
> |
sub copy { |
168 |
|
my $self=shift; |
169 |
< |
my $url=shift; |
169 |
> |
my $destination=shift; |
170 |
|
|
171 |
< |
my $docref=$self->activatedoc($url); |
172 |
< |
# Set up the document |
173 |
< |
$docref->setup(); |
166 |
< |
# $self->config()->storepolicy("local"); |
167 |
< |
$docref->save(); |
171 |
> |
# copy across the admin dir |
172 |
> |
my $temp=$self->location()."/".$self->{admindir}; |
173 |
> |
AddDir::copydir($temp,"$destination/".$self->{admindir}); |
174 |
|
} |
175 |
|
|
176 |
< |
# -------------- Tags --------------------------------- |
171 |
< |
# -- init parse |
172 |
< |
sub Project_Start { |
176 |
> |
sub copysetup { |
177 |
|
my $self=shift; |
178 |
< |
my $name=shift; |
175 |
< |
my $hashref=shift; |
176 |
< |
|
177 |
< |
$self->checktag($name,$hashref,'name'); |
178 |
< |
$self->checktag($name,$hashref,'version'); |
178 |
> |
my $dest=shift; |
179 |
|
|
180 |
< |
$self->name($$hashref{'name'}); |
181 |
< |
$self->version($$hashref{'version'}); |
180 |
> |
my $rv=1; |
181 |
> |
# copy across the admin dir |
182 |
> |
my $temp=$self->location()."/".$self->{admindir}."/".$self->arch(); |
183 |
> |
my $temp2=$dest."/".$self->{admindir}."/".$self->arch(); |
184 |
> |
if ( $temp ne $temp2 ) { |
185 |
> |
if ( -d $temp ) { |
186 |
> |
AddDir::copydir($temp,$temp2); |
187 |
> |
$rv=0; |
188 |
> |
} |
189 |
> |
} |
190 |
> |
return $rv; |
191 |
|
} |
192 |
|
|
193 |
< |
|
185 |
< |
sub Project_text { |
193 |
> |
sub copyenv { |
194 |
|
my $self=shift; |
195 |
< |
my $name=shift; |
196 |
< |
my $string=shift; |
197 |
< |
|
198 |
< |
print $string; |
195 |
> |
my $hashref=shift; |
196 |
> |
|
197 |
> |
foreach $elem ( keys %{$self->{ENV}} ) { |
198 |
> |
$$hashref{$elem}=$self->{ENV}{$elem}; |
199 |
> |
} |
200 |
|
} |
201 |
|
|
202 |
< |
# ---- download parse |
194 |
< |
|
195 |
< |
sub Use_download_Start { |
202 |
> |
sub arch { |
203 |
|
my $self=shift; |
204 |
< |
my $name=shift; |
198 |
< |
my $hashref=shift; |
199 |
< |
|
200 |
< |
$self->checktag($name,$hashref,'url'); |
201 |
< |
print "Downloading .... ".$$hashref{'url'}."\n"; |
202 |
< |
$self->getfile($$hashref{'url'}); |
204 |
> |
return $ENV{SCRAM_ARCH}; |
205 |
|
} |
206 |
|
|
207 |
< |
# --- setup parse |
208 |
< |
|
207 |
< |
sub Use_Start { |
207 |
> |
# ---- support routines |
208 |
> |
sub _LoadEnvFile { |
209 |
|
my $self=shift; |
209 |
– |
my $name=shift; |
210 |
– |
my $hashref=shift; |
211 |
– |
|
212 |
– |
$self->checktag($name,$hashref,'url'); |
213 |
– |
$self->addconfigitem($$hashref{'url'}); |
214 |
– |
} |
210 |
|
|
211 |
+ |
use FileHandle; |
212 |
+ |
my $fh=FileHandle->new(); |
213 |
+ |
open ( $fh, "<".$self->location()."/".$self->{admindir}."/". |
214 |
+ |
"Environment" ) or |
215 |
+ |
$self->error("Cannot find Environment file. Area Corrupted? (" |
216 |
+ |
.$self->location().")\n $!"); |
217 |
+ |
while ( <$fh> ) { |
218 |
+ |
chomp; |
219 |
+ |
next if /^#/; |
220 |
+ |
next if /^\s*$/ ; |
221 |
+ |
($name, $value)=split /=/; |
222 |
+ |
eval "\$self->{ENV}{${name}}=\"$value\""; |
223 |
+ |
} |
224 |
+ |
undef $fh; |
225 |
+ |
} |
226 |
+ |
|
227 |
+ |
sub _savevar { |
228 |
+ |
my $self=shift; |
229 |
+ |
my $fh=shift; |
230 |
+ |
my $name=shift; |
231 |
+ |
my $val=shift; |
232 |
+ |
print $fh "#".$name."\n"; |
233 |
+ |
print $fh $val."\n"; |
234 |
+ |
} |
235 |
+ |
|
236 |
+ |
sub _restorevars { |
237 |
+ |
my $self=shift; |
238 |
+ |
my $fh=shift; |
239 |
+ |
my $varhash=shift; |
240 |
+ |
|
241 |
+ |
while ( <$fh>=~/^#(.*)/ ) { |
242 |
+ |
$name=$1; |
243 |
+ |
chomp $name; |
244 |
+ |
$value=<$fh>; |
245 |
+ |
chomp $value; |
246 |
+ |
$$varhash{$name}=$value; |
247 |
+ |
#print "Restoring ".$name."=".$value."\n"; |
248 |
+ |
} |
249 |
+ |
} |