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 |
> |
# searchlocation([startdir]) : returns the location directory. search starts |
23 |
> |
# from cwd if not specified |
24 |
> |
# defaultdirname() : return the default directory name string |
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; |
24 |
– |
use ActiveDoc::ActiveDoc; |
35 |
|
require 5.004; |
36 |
|
use Utilities::AddDir; |
37 |
< |
use ObjectUtilities::ObjectStore; |
38 |
< |
@ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject); |
37 |
> |
use Utilities::Verbose; |
38 |
> |
use Cwd; |
39 |
> |
@ISA=qw(Utilities::Verbose); |
40 |
|
|
41 |
< |
sub init { |
42 |
< |
my $self=shift; |
43 |
< |
$self->newparse("init"); |
44 |
< |
$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 |
< |
} |
41 |
> |
sub new { |
42 |
> |
my $class=shift; |
43 |
> |
my $self={}; |
44 |
> |
bless $self, $class; |
45 |
|
|
46 |
< |
sub _setupstore { |
47 |
< |
my $self=shift; |
46 |
> |
# data init |
47 |
> |
$self->{admindir}=".SCRAM"; |
48 |
|
|
49 |
< |
# --- 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()); |
49 |
> |
return $self; |
50 |
|
} |
51 |
|
|
52 |
< |
sub parentconfig { |
52 |
> |
sub configurationdir { |
53 |
|
my $self=shift; |
54 |
< |
@_?$self->{parentconfig}=shift |
55 |
< |
:$self->{parentconfig}; |
54 |
> |
if ( @_ ) { |
55 |
> |
$self->{configurationdir}=shift; |
56 |
> |
} |
57 |
> |
if ( ! defined $self->{configurationdir} ) { |
58 |
> |
$self->_LoadEnvFile(); |
59 |
> |
$self->{configurationdir}=$self->{ENV}{projconfigdir}; |
60 |
> |
} |
61 |
> |
return $self->{configurationdir}; |
62 |
|
} |
63 |
|
|
64 |
< |
sub store { |
64 |
> |
sub scramversion { |
65 |
|
my $self=shift; |
66 |
< |
my $location=shift; |
67 |
< |
|
68 |
< |
my $fh=$self->openfile(">".$location); |
69 |
< |
$self->savevar($fh,"location", $self->location()); |
70 |
< |
$self->savevar($fh,"url", $self->url()); |
71 |
< |
$self->savevar($fh,"name", $self->name()); |
72 |
< |
$self->savevar($fh,"version", $self->version()); |
73 |
< |
$fh->close(); |
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 restore { |
82 |
> |
sub bootstrapfromlocation { |
83 |
|
my $self=shift; |
111 |
– |
my $location=shift; |
84 |
|
|
85 |
< |
my $fh=$self->openfile("<".$location); |
86 |
< |
my $varhash={}; |
87 |
< |
$self->restorevars($fh,$varhash); |
88 |
< |
$self->location($$varhash{"location"}); |
89 |
< |
$self->_setupstore(); |
90 |
< |
$self->url($$varhash{"url"}); |
91 |
< |
$self->name($$varhash{"name"}); |
92 |
< |
$self->version($$varhash{"version"}); |
93 |
< |
$fh->close(); |
85 |
> |
my $rv=0; |
86 |
> |
|
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 name { |
101 |
> |
sub location { |
102 |
|
my $self=shift; |
103 |
|
|
104 |
< |
@_?$self->{name}=shift |
105 |
< |
:$self->{name}; |
104 |
> |
if ( @_ ) { |
105 |
> |
$self->{location}=shift; |
106 |
> |
} |
107 |
> |
elsif ( ! defined $self->{location} ) { |
108 |
> |
# try and find the release location |
109 |
> |
$self->{location}=$self->searchlocation(); |
110 |
> |
} |
111 |
> |
return $self->{location}; |
112 |
|
} |
113 |
|
|
114 |
< |
sub version { |
114 |
> |
sub searchlocation { |
115 |
|
my $self=shift; |
116 |
|
|
117 |
< |
@_?$self->{version}=shift |
118 |
< |
:$self->{version}; |
119 |
< |
} |
117 |
> |
#start search in current directory if not specified |
118 |
> |
my $thispath; |
119 |
> |
if ( @_ ) { |
120 |
> |
$thispath=shift |
121 |
> |
} |
122 |
> |
else { |
123 |
> |
$thispath=cwd(); |
124 |
> |
} |
125 |
> |
|
126 |
> |
my $rv=0; |
127 |
|
|
128 |
< |
sub location { |
129 |
< |
my $self=shift; |
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 |
> |
$self->verbose("Searching $thispath"); |
137 |
> |
if ( -e "$thispath/".$self->{admindir} ) { |
138 |
> |
$self->verbose("Found\n"); |
139 |
> |
$rv=1; |
140 |
> |
last Sloop; |
141 |
> |
} |
142 |
> |
} while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) }; |
143 |
|
|
144 |
< |
@_?$self->{location}=shift |
142 |
< |
:$self->{location}; |
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; |
153 |
< |
} |
151 |
< |
|
152 |
< |
sub configitem { |
153 |
< |
my $self=shift; |
154 |
< |
my $location=shift; |
155 |
< |
|
156 |
< |
$self->config()->find("ConfigItem",@_); |
151 |
> |
# copy across the admin dir |
152 |
> |
my $temp=$self->location()."/".$self->{admindir}; |
153 |
> |
AddDir::copydir($temp,"$destination/".$self->{admindir}); |
154 |
|
} |
155 |
|
|
156 |
< |
sub addconfigitem { |
156 |
> |
sub copysetup { |
157 |
|
my $self=shift; |
158 |
< |
my $url=shift; |
158 |
> |
my $dest=shift; |
159 |
|
|
160 |
< |
my $docref=$self->activatedoc($url); |
161 |
< |
# Set up the document |
162 |
< |
$docref->setup(); |
163 |
< |
# $self->config()->storepolicy("local"); |
164 |
< |
$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 --------------------------------- |
171 |
< |
# -- init parse |
172 |
< |
sub Project_Start { |
173 |
> |
sub copyenv { |
174 |
|
my $self=shift; |
174 |
– |
my $name=shift; |
175 |
|
my $hashref=shift; |
176 |
< |
|
177 |
< |
$self->checktag($name,$hashref,'name'); |
178 |
< |
$self->checktag($name,$hashref,'version'); |
179 |
< |
|
180 |
< |
$self->name($$hashref{'name'}); |
181 |
< |
$self->version($$hashref{'version'}); |
176 |
> |
|
177 |
> |
foreach $elem ( keys %{$self->{ENV}} ) { |
178 |
> |
$$hashref{$elem}=$self->{ENV}{$elem}; |
179 |
> |
} |
180 |
|
} |
181 |
|
|
182 |
< |
|
185 |
< |
sub Project_text { |
182 |
> |
sub arch { |
183 |
|
my $self=shift; |
184 |
< |
my $name=shift; |
188 |
< |
my $string=shift; |
189 |
< |
|
190 |
< |
print $string; |
184 |
> |
return $ENV{SCRAM_ARCH}; |
185 |
|
} |
186 |
|
|
187 |
< |
# ---- download parse |
188 |
< |
|
195 |
< |
sub Use_download_Start { |
187 |
> |
# ---- support routines |
188 |
> |
sub _LoadEnvFile { |
189 |
|
my $self=shift; |
197 |
– |
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'}); |
203 |
– |
} |
204 |
– |
|
205 |
– |
# --- setup parse |
190 |
|
|
191 |
< |
sub Use_Start { |
192 |
< |
my $self=shift; |
193 |
< |
my $name=shift; |
194 |
< |
my $hashref=shift; |
195 |
< |
|
196 |
< |
$self->checktag($name,$hashref,'url'); |
197 |
< |
$self->addconfigitem($$hashref{'url'}); |
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 |
|
} |
215 |
– |
|