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 |
> |
# top() : return the very top directory of the area |
19 |
> |
# location([dir]) : set/return the location of the work area |
20 |
> |
# bootstrapfromlocation([location]): bootstrap the object based on location. |
21 |
> |
# no location specified - cwd used |
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 |
|
|
30 |
|
package Configuration::ConfigArea; |
24 |
– |
use ActiveDoc::ActiveDoc; |
31 |
|
require 5.004; |
32 |
|
use Utilities::AddDir; |
33 |
< |
use ObjectUtilities::ObjectStore; |
34 |
< |
@ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject); |
35 |
< |
|
30 |
< |
sub init { |
31 |
< |
my $self=shift; |
32 |
< |
$self->newparse("init"); |
33 |
< |
$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 |
< |
} |
75 |
< |
|
76 |
< |
sub _setupstore { |
77 |
< |
my $self=shift; |
78 |
< |
|
79 |
< |
# --- 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()); |
89 |
< |
} |
90 |
< |
|
91 |
< |
sub parentconfig { |
92 |
< |
my $self=shift; |
93 |
< |
@_?$self->{parentconfig}=shift |
94 |
< |
:$self->{parentconfig}; |
95 |
< |
} |
96 |
< |
|
97 |
< |
sub store { |
98 |
< |
my $self=shift; |
99 |
< |
my $location=shift; |
100 |
< |
|
101 |
< |
my $fh=$self->openfile(">".$location); |
102 |
< |
$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(); |
107 |
< |
} |
108 |
< |
|
109 |
< |
sub restore { |
110 |
< |
my $self=shift; |
111 |
< |
my $location=shift; |
33 |
> |
use Utilities::Verbose; |
34 |
> |
use Cwd; |
35 |
> |
@ISA=qw(Utilities::Verbose); |
36 |
|
|
37 |
< |
my $fh=$self->openfile("<".$location); |
38 |
< |
my $varhash={}; |
39 |
< |
$self->restorevars($fh,$varhash); |
40 |
< |
$self->location($$varhash{"location"}); |
41 |
< |
$self->_setupstore(); |
118 |
< |
$self->url($$varhash{"url"}); |
119 |
< |
$self->name($$varhash{"name"}); |
120 |
< |
$self->version($$varhash{"version"}); |
121 |
< |
$fh->close(); |
37 |
> |
sub new { |
38 |
> |
my $class=shift; |
39 |
> |
my $self={}; |
40 |
> |
bless $self, $class; |
41 |
> |
return $self; |
42 |
|
} |
43 |
|
|
44 |
< |
sub name { |
44 |
> |
sub top { |
45 |
|
my $self=shift; |
46 |
+ |
use File::Basename; |
47 |
|
|
48 |
< |
@_?$self->{name}=shift |
128 |
< |
:$self->{name}; |
48 |
> |
return dirname($self->location()); |
49 |
|
} |
50 |
|
|
51 |
< |
sub version { |
51 |
> |
sub configurationdir { |
52 |
|
my $self=shift; |
53 |
< |
|
54 |
< |
@_?$self->{version}=shift |
55 |
< |
:$self->{version}; |
56 |
< |
} |
57 |
< |
|
58 |
< |
sub location { |
59 |
< |
my $self=shift; |
60 |
< |
|
141 |
< |
@_?$self->{location}=shift |
142 |
< |
:$self->{location}; |
53 |
> |
if ( @_ ) { |
54 |
> |
$self->{configurationdir}=shift; |
55 |
> |
} |
56 |
> |
if ( ! defined $self->{configurationdir} ) { |
57 |
> |
$self->_LoadEnvFile(); |
58 |
> |
$self->{configurationdir}=$self->{ENV}{projconfigdir}; |
59 |
> |
} |
60 |
> |
return $self->{configurationdir}; |
61 |
|
} |
62 |
|
|
63 |
< |
sub meta { |
63 |
> |
sub scramversion { |
64 |
|
my $self=shift; |
65 |
< |
|
66 |
< |
my $string=$self->name()." ".$self->version()." located at :\n ". |
67 |
< |
$self->location; |
65 |
> |
if ( ! defined $self->{scramversion} ) { |
66 |
> |
my $filename=$self->top()."/".$self->configurationdir()."/". |
67 |
> |
"scram_version"; |
68 |
> |
if ( -f $filename ) { |
69 |
> |
use FileHandle; |
70 |
> |
$fh=FileHandle->new(); |
71 |
> |
open ($fh, "<".$filename); |
72 |
> |
my $version=<$fh>; |
73 |
> |
chomp $version; |
74 |
> |
$self->{scramversion}=$version; |
75 |
> |
undef $fh; |
76 |
> |
} |
77 |
> |
} |
78 |
> |
return $self->{scramversion}; |
79 |
|
} |
80 |
|
|
81 |
< |
sub configitem { |
81 |
> |
sub bootstrapfromlocation { |
82 |
|
my $self=shift; |
154 |
– |
my $location=shift; |
83 |
|
|
84 |
< |
$self->config()->find("ConfigItem",@_); |
85 |
< |
} |
86 |
< |
|
87 |
< |
sub addconfigitem { |
88 |
< |
my $self=shift; |
161 |
< |
my $url=shift; |
162 |
< |
|
163 |
< |
my $docref=$self->activatedoc($url); |
164 |
< |
# Set up the document |
165 |
< |
$docref->setup(); |
166 |
< |
# $self->config()->storepolicy("local"); |
167 |
< |
$docref->save(); |
168 |
< |
} |
169 |
< |
|
170 |
< |
# -------------- Tags --------------------------------- |
171 |
< |
# -- init parse |
172 |
< |
sub Project_Start { |
173 |
< |
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'}); |
84 |
> |
if ( ! defined $self->location(@_) ) { |
85 |
> |
$self->error("Unable to locate the top of local configuration area"); |
86 |
> |
} |
87 |
> |
$self->verbose("Found top ".$self->location()); |
88 |
> |
my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat"; |
89 |
|
} |
90 |
|
|
91 |
< |
|
185 |
< |
sub Project_text { |
91 |
> |
sub location { |
92 |
|
my $self=shift; |
187 |
– |
my $name=shift; |
188 |
– |
my $string=shift; |
93 |
|
|
94 |
< |
print $string; |
94 |
> |
if ( @_ ) { |
95 |
> |
$self->{location}=shift; |
96 |
> |
} |
97 |
> |
elsif ( ! defined $self->{location} ) { |
98 |
> |
# try and find the release location |
99 |
> |
$self->{location}=$self->searchlocation(); |
100 |
> |
} |
101 |
> |
return $self->{location}; |
102 |
|
} |
103 |
|
|
104 |
< |
# ---- download parse |
194 |
< |
|
195 |
< |
sub Use_download_Start { |
104 |
> |
sub searchlocation { |
105 |
|
my $self=shift; |
197 |
– |
my $name=shift; |
198 |
– |
my $hashref=shift; |
106 |
|
|
107 |
< |
$self->checktag($name,$hashref,'url'); |
108 |
< |
print "Downloading .... ".$$hashref{'url'}."\n"; |
109 |
< |
$self->getfile($$hashref{'url'}); |
107 |
> |
#start search in current directory if not specified |
108 |
> |
my $thispath; |
109 |
> |
@_?$thispath=shift |
110 |
> |
:$thispath=cwd(); |
111 |
> |
|
112 |
> |
my $rv=0; |
113 |
> |
|
114 |
> |
Sloop:{ |
115 |
> |
do { |
116 |
> |
$self->verbose("Searching $thispath"); |
117 |
> |
if ( -e "$thispath/".$self->{admindir} ) { |
118 |
> |
$self->verbose("Found\n"); |
119 |
> |
$rv=1; |
120 |
> |
last Sloop; |
121 |
> |
} |
122 |
> |
} while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) }; |
123 |
> |
|
124 |
> |
return $rv?$thispath:undef; |
125 |
> |
} |
126 |
> |
|
127 |
> |
# ---- support routines |
128 |
> |
sub _LoadEnvFile { |
129 |
> |
my $self=shift; |
130 |
> |
|
131 |
> |
use FileHandle; |
132 |
> |
my $fh=FileHandle->new(); |
133 |
> |
open ( $fh, "<".$self->location()."/Environment" ); |
134 |
> |
while ( <$fh> ) { |
135 |
> |
chomp; |
136 |
> |
next if /^#/; |
137 |
> |
next if /^\s*$/ ; |
138 |
> |
($name, $value)=split /=/; |
139 |
> |
eval "\$self->{ENV}{${name}}=\"$value\""; |
140 |
> |
} |
141 |
> |
undef $fh; |
142 |
> |
} |
143 |
> |
|
144 |
> |
sub _savevar { |
145 |
> |
my $self=shift; |
146 |
> |
my $fh=shift; |
147 |
> |
my $name=shift; |
148 |
> |
my $val=shift; |
149 |
> |
print $fh "#".$name."\n"; |
150 |
> |
print $fh $val."\n"; |
151 |
> |
} |
152 |
> |
|
153 |
> |
sub _restorevars { |
154 |
> |
my $self=shift; |
155 |
> |
my $fh=shift; |
156 |
> |
my $varhash=shift; |
157 |
> |
|
158 |
> |
while ( <$fh>=~/^#(.*)/ ) { |
159 |
> |
$name=$1; |
160 |
> |
chomp $name; |
161 |
> |
$value=<$fh>; |
162 |
> |
chomp $value; |
163 |
> |
$$varhash{$name}=$value; |
164 |
> |
#print "Restoring ".$name."=".$value."\n"; |
165 |
> |
} |
166 |
|
} |
204 |
– |
|
205 |
– |
# --- setup parse |
206 |
– |
|
207 |
– |
sub Use_Start { |
208 |
– |
my $self=shift; |
209 |
– |
my $name=shift; |
210 |
– |
my $hashref=shift; |
211 |
– |
|
212 |
– |
$self->checktag($name,$hashref,'url'); |
213 |
– |
$self->addconfigitem($$hashref{'url'}); |
214 |
– |
} |
215 |
– |
|