1 |
williamc |
1.1 |
#
|
2 |
|
|
# ConfigArea.pm
|
3 |
|
|
#
|
4 |
williamc |
1.14 |
# Written by Christopher Williams
|
5 |
williamc |
1.1 |
#
|
6 |
|
|
# Description
|
7 |
williamc |
1.9 |
# -----------
|
8 |
|
|
# creates and manages a configuration area
|
9 |
|
|
#
|
10 |
williamc |
1.14 |
# Notes
|
11 |
williamc |
1.9 |
# -------
|
12 |
williamc |
1.14 |
# Persistency - remember to call the save method to make changes persistent
|
13 |
williamc |
1.1 |
#
|
14 |
|
|
# Interface
|
15 |
|
|
# ---------
|
16 |
williamc |
1.14 |
# new() : A new ConfigArea object
|
17 |
|
|
# name() : get/set project name
|
18 |
|
|
# setup(dir[,areaname]) : setup a fresh area in dir
|
19 |
|
|
# satellite(dir[,areaname]) : setup a satellite area in dir
|
20 |
|
|
# version() : get/set project version
|
21 |
|
|
# location([dir]) : set/return the location of the work area
|
22 |
|
|
# bootstrapfromlocation([location]) : bootstrap the object based on location.
|
23 |
|
|
# no location specified - cwd used
|
24 |
|
|
# return 0 if succesful 1 otherwise
|
25 |
|
|
# requirementsdoc() : get set the requirements doc
|
26 |
williamc |
1.5 |
# searchlocation([startdir]) : returns the location directory. search starts
|
27 |
|
|
# from cwd if not specified
|
28 |
williamc |
1.14 |
# scramversion() : return the scram version associated with
|
29 |
|
|
# area
|
30 |
|
|
# configurationdir() : return the location of the project
|
31 |
|
|
# configuration directory
|
32 |
|
|
# copy(location) : copy a configuration
|
33 |
|
|
# copysetup(location) : copy the architecture specific tool setup
|
34 |
|
|
# returns 0 if successful, 1 otherwise
|
35 |
|
|
# copyenv($ref) : copy the areas environment into the hashref
|
36 |
|
|
# toolbox() : return the areas toolbox object
|
37 |
|
|
# save() : save changes permanently
|
38 |
|
|
# linkto(location) : link the current area to that at location
|
39 |
|
|
# unlinkarea() : destroy link (autosave)
|
40 |
williamc |
1.19 |
# linkarea([ConfigArea]) : link the current area to the apec Area Object
|
41 |
williamc |
1.14 |
# archname() : get/set a string to indicate architecture
|
42 |
|
|
# archdir() : return the location of the administration arch dep
|
43 |
|
|
# directory
|
44 |
williamc |
1.18 |
# objectstore() : return the objectStore object of the area
|
45 |
williamc |
1.14 |
# - temporary
|
46 |
|
|
# align() : adjust hard paths to suit local loaction
|
47 |
williamc |
1.1 |
|
48 |
|
|
package Configuration::ConfigArea;
|
49 |
|
|
require 5.004;
|
50 |
williamc |
1.14 |
use URL::URLcache;
|
51 |
williamc |
1.1 |
use Utilities::AddDir;
|
52 |
williamc |
1.14 |
use Utilities::Verbose;
|
53 |
williamc |
1.1 |
use ObjectUtilities::ObjectStore;
|
54 |
williamc |
1.6 |
use Cwd;
|
55 |
williamc |
1.14 |
@ISA=qw(Utilities::Verbose);
|
56 |
williamc |
1.1 |
|
57 |
williamc |
1.14 |
sub new {
|
58 |
|
|
my $class=shift;
|
59 |
|
|
my $self={};
|
60 |
|
|
bless $self, $class;
|
61 |
williamc |
1.5 |
|
62 |
williamc |
1.14 |
# data init
|
63 |
|
|
$self->{admindir}=".SCRAM";
|
64 |
|
|
$self->{cachedir}="cache";
|
65 |
|
|
$self->{dbdir}="ObjectDB";
|
66 |
sashby |
1.23 |
$self->{tbupdate}=0;
|
67 |
williamc |
1.14 |
undef $self->{linkarea};
|
68 |
williamc |
1.8 |
|
69 |
williamc |
1.14 |
return $self;
|
70 |
williamc |
1.1 |
}
|
71 |
|
|
|
72 |
williamc |
1.14 |
sub cache {
|
73 |
williamc |
1.9 |
my $self=shift;
|
74 |
williamc |
1.16 |
|
75 |
williamc |
1.19 |
if ( @_ ) {
|
76 |
|
|
$self->{cache}=shift;
|
77 |
|
|
}
|
78 |
|
|
if ( ! defined $self->{cache} ) {
|
79 |
|
|
my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
|
80 |
|
|
if ( -e $loc ) {
|
81 |
|
|
$self->{cache}=URL::URLcache->new($loc);
|
82 |
|
|
}
|
83 |
|
|
else {
|
84 |
|
|
$self->{cache}=undef;
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
return $self->{cache};
|
88 |
williamc |
1.14 |
}
|
89 |
williamc |
1.9 |
|
90 |
sashby |
1.23 |
# Tool and project cache info:
|
91 |
|
|
sub cacheinfo
|
92 |
|
|
{
|
93 |
|
|
my $self=shift;
|
94 |
|
|
print "\n","<ConfigArea> cacheinfo: ToolCache = ",$self->{toolcachefile},
|
95 |
|
|
", ProjectCache = ",$self->{projectcachefile},"\n";
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
sub toolcachename
|
99 |
|
|
{
|
100 |
|
|
my $self=shift;
|
101 |
|
|
return ($self->location()."/".$self->{admindir}."/".$ENV{SCRAM_ARCH}."/ToolCache.db");
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
sub projectcachename
|
105 |
|
|
{
|
106 |
|
|
my $self=shift;
|
107 |
|
|
return ($self->location()."/".$self->{admindir}."/".$ENV{SCRAM_ARCH}."/ProjectCache.db");
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
sub _tbupdate
|
111 |
|
|
{
|
112 |
|
|
# Update toolbox relative to new RequirementsDoc:
|
113 |
|
|
my $self=shift;
|
114 |
|
|
@_?$self->{tbupdate}=shift
|
115 |
|
|
:$self->{tbupdate};
|
116 |
|
|
}
|
117 |
|
|
|
118 |
williamc |
1.18 |
sub _newcache {
|
119 |
williamc |
1.19 |
my $self=shift;
|
120 |
|
|
my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
|
121 |
|
|
$self->{cache}=URL::URLcache->new($loc);
|
122 |
|
|
return $self->{cache};
|
123 |
williamc |
1.18 |
}
|
124 |
|
|
|
125 |
|
|
sub _newobjectstore {
|
126 |
williamc |
1.19 |
my $self=shift;
|
127 |
|
|
my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
|
128 |
|
|
$self->{dbstore}=ObjectUtilities::ObjectStore->new($loc);
|
129 |
|
|
return $self->{dbstore};
|
130 |
|
|
}
|
131 |
williamc |
1.18 |
|
132 |
williamc |
1.14 |
sub objectstore {
|
133 |
williamc |
1.19 |
my $self=shift;
|
134 |
williamc |
1.16 |
|
135 |
williamc |
1.19 |
if ( @_ ) {
|
136 |
|
|
$self->{dbstore}=shift;
|
137 |
|
|
}
|
138 |
|
|
if ( ! defined $self->{dbstore} ) {
|
139 |
|
|
my $loc=$self->location()."/".$self->{admindir}."/".$self->{dbdir};
|
140 |
|
|
if ( -e $loc ) {
|
141 |
|
|
$self->{dbstore}=ObjectUtilities::ObjectStore->new($loc);
|
142 |
|
|
}
|
143 |
|
|
else {
|
144 |
|
|
$self->{dbstore}=undef;
|
145 |
|
|
}
|
146 |
|
|
}
|
147 |
|
|
return $self->{dbstore}
|
148 |
williamc |
1.9 |
}
|
149 |
|
|
|
150 |
williamc |
1.14 |
sub name {
|
151 |
williamc |
1.9 |
my $self=shift;
|
152 |
williamc |
1.14 |
@_?$self->{name}=shift
|
153 |
|
|
:$self->{name};
|
154 |
williamc |
1.9 |
}
|
155 |
williamc |
1.7 |
|
156 |
williamc |
1.14 |
sub version {
|
157 |
williamc |
1.6 |
my $self=shift;
|
158 |
williamc |
1.14 |
@_?$self->{version}=shift
|
159 |
|
|
:$self->{version};
|
160 |
williamc |
1.9 |
}
|
161 |
williamc |
1.8 |
|
162 |
williamc |
1.1 |
sub setup {
|
163 |
|
|
my $self=shift;
|
164 |
williamc |
1.14 |
my $location=shift;
|
165 |
|
|
my $areaname;
|
166 |
williamc |
1.1 |
|
167 |
williamc |
1.14 |
# -- check we have a project name and version
|
168 |
|
|
my $name=$self->name();
|
169 |
|
|
my $vers=$self->version();
|
170 |
sashby |
1.23 |
|
171 |
williamc |
1.14 |
if ( ( ! defined $name ) && ( ! defined $version )) {
|
172 |
|
|
$self->error("Set ConfigArea name and version before setup");
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
# -- check arguments and set location
|
176 |
williamc |
1.7 |
if ( ! defined $location ) {
|
177 |
williamc |
1.14 |
$self->error("ConfigArea: Cannot setup new area without a location");
|
178 |
williamc |
1.7 |
}
|
179 |
williamc |
1.14 |
if ( @_ ) {
|
180 |
|
|
$areaname=shift;
|
181 |
williamc |
1.6 |
}
|
182 |
williamc |
1.14 |
if ( (! defined $areaname) || ( $areaname eq "" ) ) {
|
183 |
|
|
# -- make up a name from the project name and version
|
184 |
|
|
$vers=~s/^$name\_//;
|
185 |
|
|
$areaname=$name."_".$vers;
|
186 |
williamc |
1.1 |
}
|
187 |
williamc |
1.14 |
my $arealoc=$location."/".$areaname;
|
188 |
|
|
my $workloc=$arealoc."/".$self->{admindir};
|
189 |
|
|
$self->verbose("Building at $arealoc");
|
190 |
|
|
$self->location($arealoc);
|
191 |
williamc |
1.1 |
|
192 |
williamc |
1.14 |
# -- create top level structure and work area
|
193 |
|
|
AddDir::adddir($workloc);
|
194 |
williamc |
1.1 |
|
195 |
williamc |
1.14 |
# -- add a cache
|
196 |
williamc |
1.18 |
$self->_newcache();
|
197 |
|
|
|
198 |
williamc |
1.19 |
# -- add an Objectstore
|
199 |
|
|
$self->_newobjectstore();
|
200 |
williamc |
1.5 |
|
201 |
williamc |
1.14 |
# -- Save Environment File
|
202 |
|
|
$self->_SaveEnvFile();
|
203 |
williamc |
1.3 |
|
204 |
williamc |
1.9 |
}
|
205 |
|
|
|
206 |
williamc |
1.14 |
sub configurationdir {
|
207 |
williamc |
1.9 |
my $self=shift;
|
208 |
williamc |
1.14 |
if ( @_ ) {
|
209 |
|
|
$self->{configurationdir}=shift;
|
210 |
|
|
}
|
211 |
|
|
return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
|
212 |
williamc |
1.9 |
}
|
213 |
|
|
|
214 |
sashby |
1.23 |
sub sourcedir {
|
215 |
|
|
my $self=shift;
|
216 |
|
|
if ( @_ ) {
|
217 |
|
|
$self->{sourcedir}=shift;
|
218 |
|
|
}
|
219 |
|
|
return (defined $self->{sourcedir})?$self->{sourcedir}:undef;
|
220 |
|
|
}
|
221 |
|
|
|
222 |
williamc |
1.14 |
sub toolbox {
|
223 |
williamc |
1.3 |
my $self=shift;
|
224 |
williamc |
1.14 |
if ( ! defined $self->{toolbox} ) {
|
225 |
williamc |
1.19 |
$self->{toolbox}=BuildSystem::ToolBox->new($self, $ENV{SCRAM_ARCH});
|
226 |
williamc |
1.14 |
}
|
227 |
|
|
return $self->{toolbox};
|
228 |
williamc |
1.4 |
}
|
229 |
|
|
|
230 |
sashby |
1.23 |
sub toolboxversion {
|
231 |
|
|
my $self=shift;
|
232 |
|
|
if ( @_ ) {
|
233 |
|
|
$self->{toolboxversion}=shift;
|
234 |
|
|
}
|
235 |
|
|
return (defined $self->{toolboxversion})?$self->{toolboxversion}:undef;
|
236 |
|
|
}
|
237 |
|
|
|
238 |
williamc |
1.14 |
sub requirementsdoc {
|
239 |
williamc |
1.5 |
my $self=shift;
|
240 |
williamc |
1.14 |
if ( @_ ) {
|
241 |
|
|
$self->{reqdoc}=shift;
|
242 |
|
|
}
|
243 |
|
|
if ( defined $self->{reqdoc} ) {
|
244 |
|
|
return $self->location()."/".$self->{reqdoc};
|
245 |
williamc |
1.12 |
}
|
246 |
|
|
else {
|
247 |
williamc |
1.14 |
return undef;
|
248 |
williamc |
1.12 |
}
|
249 |
williamc |
1.5 |
}
|
250 |
|
|
|
251 |
williamc |
1.14 |
sub scramversion {
|
252 |
williamc |
1.4 |
my $self=shift;
|
253 |
williamc |
1.14 |
if ( ! defined $self->{scramversion} ) {
|
254 |
|
|
my $filename=$self->location()."/".$self->configurationdir()."/".
|
255 |
|
|
"scram_version";
|
256 |
|
|
if ( -f $filename ) {
|
257 |
|
|
use FileHandle;
|
258 |
|
|
$fh=FileHandle->new();
|
259 |
|
|
open ($fh, "<".$filename);
|
260 |
|
|
my $version=<$fh>;
|
261 |
|
|
chomp $version;
|
262 |
|
|
$self->{scramversion}=$version;
|
263 |
|
|
undef $fh;
|
264 |
|
|
}
|
265 |
|
|
}
|
266 |
|
|
return $self->{scramversion};
|
267 |
williamc |
1.1 |
}
|
268 |
|
|
|
269 |
sashby |
1.21 |
sub sitename
|
270 |
|
|
{
|
271 |
|
|
###############################################################
|
272 |
|
|
# sitename() #
|
273 |
|
|
###############################################################
|
274 |
|
|
# modified : Mon Dec 3 15:45:35 2001 / SFA #
|
275 |
|
|
# params : #
|
276 |
|
|
# : #
|
277 |
|
|
# : #
|
278 |
|
|
# : #
|
279 |
|
|
# function : Read the site name from config/site/sitename and #
|
280 |
|
|
# : export it. #
|
281 |
|
|
# : #
|
282 |
|
|
# : #
|
283 |
|
|
###############################################################
|
284 |
|
|
my $self = shift;
|
285 |
|
|
my $sitefile = $self->location()."/".$self->configurationdir()."/site/sitename";
|
286 |
|
|
|
287 |
|
|
$self->{sitename} = 'CERN'; # Use CERN as the default site name
|
288 |
|
|
|
289 |
|
|
use FileHandle;
|
290 |
|
|
my $sitefh = FileHandle->new();
|
291 |
sashby |
1.22 |
|
292 |
|
|
# Be verbose and print file we're going to read:
|
293 |
|
|
$self->verbose(">> Going to try to get sitename from: ".$sitefile." ");
|
294 |
sashby |
1.21 |
|
295 |
|
|
# See if we can read from the file. If not, just
|
296 |
|
|
# use default site name:
|
297 |
|
|
open($sitefh,"<".$sitefile) ||
|
298 |
|
|
do
|
299 |
|
|
{
|
300 |
sashby |
1.22 |
$self->verbose(">> Unable to read a site name definition file. Using \'CERN\' as the site name.");
|
301 |
sashby |
1.21 |
return $self->{sitename};
|
302 |
|
|
};
|
303 |
|
|
|
304 |
|
|
$sitename = <$sitefh>;
|
305 |
|
|
chomp($sitename);
|
306 |
|
|
$self->{sitename} = $sitename;
|
307 |
|
|
|
308 |
|
|
# Close the file (be tidy!);
|
309 |
|
|
close($sitefile);
|
310 |
|
|
# Return:
|
311 |
|
|
return $self->{sitename};
|
312 |
|
|
}
|
313 |
|
|
|
314 |
|
|
|
315 |
williamc |
1.14 |
sub bootstrapfromlocation {
|
316 |
williamc |
1.1 |
my $self=shift;
|
317 |
|
|
|
318 |
williamc |
1.14 |
my $rv=0;
|
319 |
|
|
|
320 |
|
|
my $location;
|
321 |
|
|
if ( ! defined ($location=$self->searchlocation(@_)) ) {
|
322 |
|
|
$rv=1;
|
323 |
|
|
$self->verbose("Unable to locate the top of local configuration area");
|
324 |
williamc |
1.9 |
}
|
325 |
|
|
else {
|
326 |
williamc |
1.14 |
$self->location($location);
|
327 |
|
|
$self->verbose("Found top ".$self->location());
|
328 |
|
|
$self->_LoadEnvFile();
|
329 |
williamc |
1.9 |
}
|
330 |
williamc |
1.14 |
return $rv;
|
331 |
williamc |
1.1 |
}
|
332 |
|
|
|
333 |
|
|
sub location {
|
334 |
|
|
my $self=shift;
|
335 |
|
|
|
336 |
williamc |
1.5 |
if ( @_ ) {
|
337 |
williamc |
1.6 |
$self->{location}=shift;
|
338 |
williamc |
1.5 |
}
|
339 |
|
|
elsif ( ! defined $self->{location} ) {
|
340 |
|
|
# try and find the release location
|
341 |
williamc |
1.9 |
$self->{location}=$self->searchlocation();
|
342 |
williamc |
1.5 |
}
|
343 |
|
|
return $self->{location};
|
344 |
|
|
}
|
345 |
|
|
|
346 |
|
|
sub searchlocation {
|
347 |
|
|
my $self=shift;
|
348 |
sashby |
1.20 |
|
349 |
williamc |
1.5 |
#start search in current directory if not specified
|
350 |
|
|
my $thispath;
|
351 |
williamc |
1.14 |
if ( @_ ) {
|
352 |
|
|
$thispath=shift
|
353 |
|
|
}
|
354 |
|
|
else {
|
355 |
|
|
$thispath=cwd();
|
356 |
|
|
}
|
357 |
sashby |
1.20 |
|
358 |
williamc |
1.5 |
my $rv=0;
|
359 |
|
|
|
360 |
williamc |
1.14 |
# chop off any files - we only want dirs
|
361 |
|
|
if ( -f $thispath ) {
|
362 |
|
|
$thispath=~s/(.*)\/.*/$1/;
|
363 |
|
|
}
|
364 |
williamc |
1.6 |
Sloop:{
|
365 |
|
|
do {
|
366 |
williamc |
1.14 |
$self->verbose("Searching $thispath");
|
367 |
williamc |
1.8 |
if ( -e "$thispath/".$self->{admindir} ) {
|
368 |
williamc |
1.14 |
$self->verbose("Found\n");
|
369 |
williamc |
1.5 |
$rv=1;
|
370 |
williamc |
1.6 |
last Sloop;
|
371 |
williamc |
1.5 |
}
|
372 |
williamc |
1.6 |
} while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
|
373 |
sashby |
1.20 |
|
374 |
williamc |
1.5 |
return $rv?$thispath:undef;
|
375 |
williamc |
1.1 |
}
|
376 |
|
|
|
377 |
williamc |
1.14 |
sub archname {
|
378 |
williamc |
1.1 |
my $self=shift;
|
379 |
williamc |
1.14 |
if ( @_ ) {
|
380 |
|
|
$self->{archname}=shift;
|
381 |
|
|
}
|
382 |
|
|
return $self->{archname};
|
383 |
|
|
}
|
384 |
williamc |
1.1 |
|
385 |
williamc |
1.14 |
sub archdir {
|
386 |
|
|
my $self=shift;
|
387 |
|
|
if ( @_ ) {
|
388 |
|
|
$self->{archdir}=shift;
|
389 |
|
|
}
|
390 |
|
|
if ( ! defined $self->{archdir} ) {
|
391 |
|
|
if ( defined $self->{archname} ) {
|
392 |
|
|
$self->{archdir}=$self->location()."/".$self->{admindir}."/".
|
393 |
|
|
$self->{archname};
|
394 |
|
|
}
|
395 |
|
|
else {
|
396 |
|
|
$self->error("ConfigArea : cannot create arch directory - ".
|
397 |
|
|
"architecture name not set")
|
398 |
|
|
}
|
399 |
|
|
}
|
400 |
|
|
return $self->{archdir};
|
401 |
williamc |
1.1 |
}
|
402 |
|
|
|
403 |
williamc |
1.14 |
sub satellite {
|
404 |
williamc |
1.1 |
my $self=shift;
|
405 |
williamc |
1.14 |
|
406 |
|
|
# -- create the sat object
|
407 |
|
|
my $sat=Configuration::ConfigArea->new();
|
408 |
|
|
$sat->name($self->name());
|
409 |
|
|
$sat->version($self->version());
|
410 |
|
|
$sat->requirementsdoc($self->{reqdoc});
|
411 |
|
|
$sat->configurationdir($self->configurationdir());
|
412 |
sashby |
1.23 |
$sat->sourcedir($self->sourcedir());
|
413 |
|
|
$sat->toolboxversion($self->toolboxversion());
|
414 |
williamc |
1.14 |
$sat->setup(@_);
|
415 |
|
|
|
416 |
|
|
# -- copy across the cache and ObjectStore
|
417 |
williamc |
1.16 |
# -- make sure we dont try building new caches in release areas
|
418 |
williamc |
1.18 |
my $rcache=$self->cache();
|
419 |
williamc |
1.16 |
if ( defined $rcache ) {
|
420 |
|
|
copy($rcache->location(),$sat->cache()->location());
|
421 |
|
|
}
|
422 |
|
|
|
423 |
|
|
# -- make sure we dont try building new objectstores in release areas
|
424 |
williamc |
1.18 |
my $rostore=$self->objectstore();
|
425 |
williamc |
1.16 |
if ( defined $rostore ) {
|
426 |
|
|
copy($rostore->location(),$sat->objectstore()->location());
|
427 |
|
|
}
|
428 |
williamc |
1.14 |
|
429 |
|
|
# and make sure in reinitialises
|
430 |
|
|
undef ($sat->{cache});
|
431 |
|
|
|
432 |
|
|
# -- link it to this area
|
433 |
|
|
$sat->linkarea($self);
|
434 |
williamc |
1.1 |
|
435 |
williamc |
1.14 |
# -- save it
|
436 |
|
|
$sat->save();
|
437 |
|
|
|
438 |
|
|
return $sat;
|
439 |
williamc |
1.1 |
}
|
440 |
|
|
|
441 |
williamc |
1.14 |
sub copy {
|
442 |
williamc |
1.1 |
my $self=shift;
|
443 |
williamc |
1.14 |
my $destination=shift;
|
444 |
williamc |
1.1 |
|
445 |
williamc |
1.14 |
# copy across the admin dir
|
446 |
|
|
my $temp=$self->location()."/".$self->{admindir};
|
447 |
|
|
AddDir::copydir($temp,"$destination/".$self->{admindir});
|
448 |
williamc |
1.13 |
}
|
449 |
|
|
|
450 |
williamc |
1.14 |
sub align {
|
451 |
williamc |
1.13 |
my $self=shift;
|
452 |
williamc |
1.14 |
use File::Copy;
|
453 |
|
|
|
454 |
|
|
$self->_LoadEnvFile();
|
455 |
|
|
my $Envfile=$self->location()."/".$self->{admindir}."/Environment";
|
456 |
|
|
my $tmpEnvfile=$Envfile.".bak";
|
457 |
|
|
my $rel=$self->{ENV}{RELEASETOP};
|
458 |
|
|
my $local=$self->location();
|
459 |
|
|
|
460 |
|
|
rename( $Envfile, $tmpEnvfile );
|
461 |
|
|
use FileHandle;
|
462 |
|
|
my $fh=FileHandle->new();
|
463 |
|
|
my $fout=FileHandle->new();
|
464 |
|
|
open ( $fh, "<".$tmpEnvfile ) or
|
465 |
|
|
$self->error("Cannot find Environment file. Area Corrupted? ("
|
466 |
|
|
.$self->location().")\n $!");
|
467 |
|
|
open ( $fout, ">".$Envfile ) or
|
468 |
|
|
$self->error("Cannot find Environment file. Area Corrupted? ("
|
469 |
|
|
.$self->location().")\n $!");
|
470 |
|
|
while ( <$fh> ) {
|
471 |
|
|
$_=~s/\Q$rel\L/$local/g;
|
472 |
|
|
print $fout $_;
|
473 |
|
|
}
|
474 |
|
|
undef $fh;
|
475 |
|
|
undef $fout;
|
476 |
williamc |
1.1 |
}
|
477 |
|
|
|
478 |
williamc |
1.14 |
sub copysetup {
|
479 |
williamc |
1.9 |
my $self=shift;
|
480 |
sashby |
1.24 |
my $dest=shift;
|
481 |
|
|
my $rv=1;
|
482 |
|
|
# copy across the admin dir
|
483 |
|
|
my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
|
484 |
|
|
my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
|
485 |
|
|
if ( $temp ne $temp2 ) {
|
486 |
|
|
if ( -d $temp ) {
|
487 |
|
|
AddDir::copydir($temp,$temp2);
|
488 |
|
|
$rv=0;
|
489 |
|
|
}
|
490 |
|
|
}
|
491 |
|
|
return $rv;
|
492 |
|
|
}
|
493 |
|
|
|
494 |
sashby |
1.26 |
sub copyurlcache {
|
495 |
|
|
my $self=shift;
|
496 |
|
|
my $dest=shift;
|
497 |
|
|
my $rv=1;
|
498 |
|
|
# copy across the admin dir
|
499 |
|
|
my $temp=$self->location()."/".$self->{admindir}."/cache";
|
500 |
|
|
my $temp2=$dest."/".$self->{admindir}."/cache";
|
501 |
|
|
if ( $temp ne $temp2 ) {
|
502 |
|
|
if ( -d $temp ) {
|
503 |
|
|
AddDir::copydir($temp,$temp2);
|
504 |
|
|
$rv=0;
|
505 |
|
|
}
|
506 |
|
|
}
|
507 |
|
|
return $rv;
|
508 |
|
|
}
|
509 |
|
|
|
510 |
sashby |
1.24 |
sub copywithskip {
|
511 |
|
|
my $self=shift;
|
512 |
williamc |
1.14 |
my $dest=shift;
|
513 |
sashby |
1.24 |
my ($filetoskip)=@_;
|
514 |
williamc |
1.14 |
my $rv=1;
|
515 |
|
|
# copy across the admin dir
|
516 |
|
|
my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
|
517 |
|
|
my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
|
518 |
|
|
if ( $temp ne $temp2 ) {
|
519 |
|
|
if ( -d $temp ) {
|
520 |
sashby |
1.24 |
AddDir::copydirwithskip($temp,$temp2,$filetoskip);
|
521 |
williamc |
1.14 |
$rv=0;
|
522 |
|
|
}
|
523 |
williamc |
1.9 |
}
|
524 |
williamc |
1.14 |
return $rv;
|
525 |
williamc |
1.9 |
}
|
526 |
|
|
|
527 |
williamc |
1.14 |
sub copyenv {
|
528 |
williamc |
1.9 |
my $self=shift;
|
529 |
williamc |
1.14 |
my $hashref=shift;
|
530 |
|
|
|
531 |
|
|
foreach $elem ( keys %{$self->{ENV}} ) {
|
532 |
|
|
$$hashref{$elem}=$self->{ENV}{$elem};
|
533 |
williamc |
1.9 |
}
|
534 |
|
|
}
|
535 |
|
|
|
536 |
williamc |
1.14 |
sub arch {
|
537 |
williamc |
1.9 |
my $self=shift;
|
538 |
williamc |
1.14 |
return $ENV{SCRAM_ARCH};
|
539 |
williamc |
1.9 |
}
|
540 |
|
|
|
541 |
williamc |
1.14 |
sub linkto {
|
542 |
williamc |
1.9 |
my $self=shift;
|
543 |
williamc |
1.14 |
my $location=shift;
|
544 |
sashby |
1.23 |
|
545 |
williamc |
1.14 |
if ( -d $location ) {
|
546 |
|
|
my $area=Configuration::ConfigArea->new();
|
547 |
|
|
$area->bootstrapfromlocation($location);
|
548 |
|
|
$self->linkarea($area);
|
549 |
|
|
}
|
550 |
|
|
else {
|
551 |
|
|
$self->error("ConfigArea : Unable to link to non existing directory ".
|
552 |
|
|
$location);
|
553 |
williamc |
1.9 |
}
|
554 |
|
|
}
|
555 |
|
|
|
556 |
williamc |
1.14 |
sub unlinkarea {
|
557 |
williamc |
1.9 |
my $self=shift;
|
558 |
williamc |
1.14 |
undef $self->{linkarea};
|
559 |
|
|
$self->{linkarea}=undef;
|
560 |
|
|
$self->save();
|
561 |
|
|
}
|
562 |
williamc |
1.9 |
|
563 |
williamc |
1.14 |
sub linkarea {
|
564 |
williamc |
1.1 |
my $self=shift;
|
565 |
williamc |
1.14 |
my $area=shift;
|
566 |
|
|
if ( defined $area ) {
|
567 |
|
|
$self->{linkarea}=$area;
|
568 |
|
|
}
|
569 |
|
|
return (defined $self->{linkarea} && $self->{linkarea} ne "")?
|
570 |
|
|
$self->{linkarea}:undef;
|
571 |
williamc |
1.1 |
}
|
572 |
|
|
|
573 |
williamc |
1.14 |
sub save {
|
574 |
williamc |
1.1 |
my $self=shift;
|
575 |
williamc |
1.14 |
$self->_SaveEnvFile();
|
576 |
williamc |
1.1 |
}
|
577 |
|
|
|
578 |
sashby |
1.27 |
sub reqdoc()
|
579 |
|
|
{
|
580 |
|
|
my $self=shift;
|
581 |
|
|
my ($path)=@_;
|
582 |
|
|
return $path."/".$self->{reqdoc};
|
583 |
|
|
}
|
584 |
|
|
|
585 |
|
|
sub creationtime()
|
586 |
|
|
{
|
587 |
|
|
my $self=shift;
|
588 |
|
|
my ($location)= @_;
|
589 |
|
|
$location||=$self->location();
|
590 |
|
|
my $requirementsdoc = $self->reqdoc($location);
|
591 |
|
|
my ($mode, $time) = (stat($requirementsdoc))[2, 9];
|
592 |
|
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
|
593 |
|
|
|
594 |
|
|
($sec < 10) ? ($sec = "0".$sec) : $sec;
|
595 |
|
|
($min < 10) ? ($min = "0".$min) : $min;
|
596 |
|
|
|
597 |
|
|
$year += 1900;
|
598 |
|
|
my $months =
|
599 |
|
|
{
|
600 |
|
|
0 => "Jan", 1 => "Feb",
|
601 |
|
|
2 => "Mar", 3 => "Apr",
|
602 |
|
|
4 => "May", 5 => "Jun",
|
603 |
|
|
6 => "Jul", 7 => "Aug",
|
604 |
|
|
8 => "Sept", 9 => "Oct",
|
605 |
|
|
10 => "Nov", 11 => "Dec" };
|
606 |
|
|
|
607 |
|
|
my $days = { 1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat", 7 => "Sun"};
|
608 |
|
|
|
609 |
|
|
# Return the timestamp (as string) of the requirementsdoc:
|
610 |
|
|
return $days->{$wday}."-".$mday."-".$months->{$mon}."-".$year." ".$hour.":".$min.":".$sec;
|
611 |
|
|
}
|
612 |
|
|
|
613 |
williamc |
1.14 |
# ---- support routines
|
614 |
williamc |
1.1 |
|
615 |
sashby |
1.25 |
sub _SaveEnvFile
|
616 |
|
|
{
|
617 |
|
|
my $self=shift;
|
618 |
|
|
my $filemode = 0644;
|
619 |
|
|
|
620 |
|
|
use FileHandle;
|
621 |
|
|
my $fh=FileHandle->new();
|
622 |
|
|
open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
|
623 |
|
|
"Environment" ) or
|
624 |
|
|
$self->error("Cannot Open Environment file to Save ("
|
625 |
|
|
.$self->location().")\n $!");
|
626 |
williamc |
1.14 |
|
627 |
sashby |
1.25 |
print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
|
628 |
|
|
print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
|
629 |
|
|
print $fh "SCRAM_CONFIGDIR=".$self->configurationdir()."\n";
|
630 |
|
|
print $fh "SCRAM_SOURCEDIR=".$self->sourcedir()."\n";
|
631 |
|
|
print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n";
|
632 |
|
|
print $fh "SCRAM_TOOLBOXVERSION=".$self->{toolboxversion}."\n";
|
633 |
williamc |
1.9 |
|
634 |
sashby |
1.25 |
if ( defined $self->linkarea() )
|
635 |
|
|
{
|
636 |
|
|
my $area=$self->linkarea()->location();
|
637 |
|
|
if ( $area ne "" )
|
638 |
|
|
{
|
639 |
|
|
print $fh "RELEASETOP=".$area."\n";
|
640 |
|
|
}
|
641 |
|
|
}
|
642 |
|
|
|
643 |
|
|
undef $fh;
|
644 |
|
|
|
645 |
|
|
# Set the default permissions (-rw-r--r--):
|
646 |
|
|
chmod $filemode, $self->location()."/".$self->{admindir}."/Environment";
|
647 |
|
|
}
|
648 |
williamc |
1.1 |
|
649 |
sashby |
1.23 |
sub _LoadEnvFile
|
650 |
|
|
{
|
651 |
|
|
my $self=shift;
|
652 |
williamc |
1.9 |
|
653 |
sashby |
1.23 |
use FileHandle;
|
654 |
|
|
my $fh=FileHandle->new();
|
655 |
|
|
open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
|
656 |
|
|
"Environment" ) or
|
657 |
|
|
$self->error("Cannot find Environment file. Area Corrupted? ("
|
658 |
|
|
.$self->location().")\n $!");
|
659 |
|
|
while ( <$fh> )
|
660 |
|
|
{
|
661 |
|
|
chomp;
|
662 |
|
|
next if /^#/;
|
663 |
|
|
next if /^\s*$/ ;
|
664 |
|
|
($name, $value)=split /=/;
|
665 |
|
|
eval "\$self->{ENV}{${name}}=\"$value\"";
|
666 |
|
|
}
|
667 |
|
|
undef $fh;
|
668 |
williamc |
1.14 |
|
669 |
sashby |
1.23 |
# -- set internal variables appropriately
|
670 |
|
|
if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} )
|
671 |
|
|
{
|
672 |
|
|
$self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
|
673 |
|
|
}
|
674 |
|
|
if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} )
|
675 |
|
|
{
|
676 |
|
|
$self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
|
677 |
|
|
}
|
678 |
|
|
if ( defined $self->{ENV}{"SCRAM_CONFIGDIR"} )
|
679 |
|
|
{
|
680 |
|
|
$self->configurationdir($self->{ENV}{"SCRAM_CONFIGDIR"});
|
681 |
|
|
}
|
682 |
|
|
if ( defined $self->{ENV}{"SCRAM_SOURCEDIR"} )
|
683 |
|
|
{
|
684 |
|
|
$self->sourcedir($self->{ENV}{"SCRAM_SOURCEDIR"});
|
685 |
|
|
}
|
686 |
|
|
if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} )
|
687 |
|
|
{
|
688 |
|
|
$self->requirementsdoc($self->{ENV}{"SCRAM_ProjReqsDoc"});
|
689 |
|
|
}
|
690 |
|
|
if ( defined $self->{ENV}{"SCRAM_TOOLBOXVERSION"} )
|
691 |
|
|
{
|
692 |
sashby |
1.28 |
if ($self->{ENV}{"SCRAM_TOOLBOXVERSION"} eq '')
|
693 |
|
|
{
|
694 |
|
|
$self->toolboxversion("STANDALONE");
|
695 |
|
|
}
|
696 |
|
|
else
|
697 |
|
|
{
|
698 |
|
|
$self->toolboxversion($self->{ENV}{"SCRAM_TOOLBOXVERSION"});
|
699 |
|
|
}
|
700 |
sashby |
1.23 |
}
|
701 |
|
|
|
702 |
|
|
if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
|
703 |
|
|
($self->{ENV}{"RELEASETOP"} ne $self->location()))
|
704 |
|
|
{
|
705 |
|
|
$self->linkto($self->{ENV}{"RELEASETOP"});
|
706 |
|
|
}
|
707 |
|
|
}
|