ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Configuration/ConfigArea.pm
(Generate patch)

Comparing COMP/SCRAM/src/Configuration/ConfigArea.pm (file contents):
Revision 1.4 by williamc, Fri Jan 21 11:56:38 2000 UTC vs.
Revision 1.13.2.6.2.1 by williamc, Fri Aug 4 08:31:37 2000 UTC

# Line 1 | Line 1
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 + # Notes
11 + # -------
12 + # Persistency - remember to call the save method to make changes persistent
13   #
14   # Interface
15   # ---------
16 < # new(ActiveConfig)             : A new ConfigArea object
17 < # setup()                       : setup the configuration area
18 < # location([dir])               : set/return the location of the area
19 < # version([version])            : set/return the version of the area
20 < # name([name])                  : set/return the name of the area
21 < # store(location)               : store data in file location
22 < # restore(location)             : restore data from file location
23 < # meta()                        : return a description string of the area
24 < # addconfigitem(url)            : add a new item to the area
25 < # configitem(@keys)             : return a list of fig items that match
26 < #                                 the keys - all if left blank
27 < # parentstore()                 : set/return the parent ObjectStore
16 > # new()                         : A new ConfigArea object
17 > # name()                        : get/set project name
18 > # setup(dir[,areaname])         : setup a fresh area in dir
19 > # version()                     : get/set project version
20 > # location([dir])               : set/return the location of the work area
21 > # bootstrapfromlocation([location]) : bootstrap the object based on location.
22 > #                                     no location specified - cwd used
23 > #                                     return 0 if succesful 1 otherwise
24 > # requirementsdoc()             : get set the requirements doc
25 > # searchlocation([startdir])    : returns the location directory. search starts
26 > #                                 from cwd if not specified
27 > # scramversion()                : return the scram version associated with
28 > #                                 area
29 > # configurationdir()            : return the location of the project
30 > #                                 configuration directory
31 > # copy(location)                : copy a configuration
32 > # copysetup(location)           : copy the architecture specific tool setup
33 > #                                 returns 0 if successful, 1 otherwise
34 > # copyenv($ref)                 : copy the areas environment into the hashref
35 > # toolbox()                     : return the areas toolbox object
36 > # save()                        : save changes permanently
37 > # linkto(location)              : link the current area to that at location
38 > # unlinkarea()                  : destroy link (autosave)
39 > # linkarea([ConfigArea])        : link the current area to the apec Area Object
40 > # - temporary
41 > # align()                       : adjust hard paths to suit local loaction
42  
43   package Configuration::ConfigArea;
24 use ActiveDoc::ActiveDoc;
44   require 5.004;
45 + use URL::URLcache;
46   use Utilities::AddDir;
47 < use ObjectUtilities::ObjectStore;
48 < @ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject);
47 > use Utilities::Verbose;
48 > use Cwd;
49 > @ISA=qw(Utilities::Verbose);
50 >
51 > sub new {
52 >        my $class=shift;
53 >        my $self={};
54 >        bless $self, $class;
55 >
56 >        # data init
57 >        $self->{admindir}=".SCRAM";
58 >        $self->{cachedir}="cache";
59 >        undef $self->{linkarea};
60  
61 < sub init {
61 >        return $self;
62 > }
63 >
64 > sub cache {
65          my $self=shift;
66 <        $self->newparse("init");
67 <        $self->newparse("download");
68 <        $self->newparse("setup");
69 <        $self->addtag("init","project",\&Project_Start,$self,
70 <        \&Project_text,$self,"", $self );
71 <        $self->addurltags("download");
72 <        $self->addtag("download","use",\&Use_download_Start,$self,
73 <                                                "", $self, "",$self);
40 <        $self->addurltags("setup");
41 <        $self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self);
66 >        if ( @_ ) {
67 >          $self->{cache}=shift;
68 >        }
69 >        elsif ( ! defined $self->{cache} ) {
70 >          my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
71 >          $self->{cache}=URL::URLcache->new($loc);
72 >        }
73 >        return $self->{cache};
74   }
75  
76 < sub setup {
76 > sub name {
77          my $self=shift;
78 +        @_?$self->{name}=shift
79 +          :$self->{name};
80 + }
81  
82 <        # --- find out the location
83 <        my $location=$self->requestoption("area_location",
84 <                "Please Enter the location of the directory");
85 <
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());
82 > sub version {
83 >        my $self=shift;
84 >        @_?$self->{version}=shift
85 >          :$self->{version};
86   }
87  
88 < sub _setupstore {
88 > sub setup {
89          my $self=shift;
90 +        my $location=shift;
91 +        my $areaname;
92 +
93 +        # -- check we have a project name and version
94 +        my $name=$self->name();
95 +        my $vers=$self->version();
96 +        if ( ( ! defined $name ) && ( ! defined $version )) {
97 +          $self->error("Set ConfigArea name and version before setup");
98 +        }
99  
100 <        # --- make a new ActiveStore at the location and add it to the db list
101 <        my $ad=ActiveDoc::ActiveConfig->new($self->location()."/\.SCRAM");
100 >        # -- check arguments and set location
101 >        if ( ! defined $location ) {
102 >          $self->error("ConfigArea: Cannont setup area without a location");
103 >        }
104 >        if ( @_ ) {
105 >          $areaname=shift;
106 >        }
107 >        if ( (! defined $areaname) || ( $areaname eq "" ) ) {
108 >          # -- make up a name from the project name and version
109 >          $vers=~s/^$name\_//;
110 >          $areaname=$name."_".$vers;
111 >        }
112 >        my $arealoc=$location."/".$areaname;
113 >        my $workloc=$arealoc."/".$self->{admindir};
114 >        $self->verbose("Building at $arealoc");
115 >        $self->location($arealoc);
116 >
117 >        # -- create top level structure and work area
118 >        AddDir::adddir($workloc);
119 >
120 >        # -- add a cache
121 >        $self->cache();
122 >
123 >        # -- Save Environment File
124 >        $self->_SaveEnvFile();
125  
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());
126   }
127  
128 < sub parentconfig {
128 > sub configurationdir {
129          my $self=shift;
130 <        @_?$self->{parentconfig}=shift
131 <          :$self->{parentconfig};
130 >        if ( @_ ) {
131 >          $self->{configurationdir}=shift;
132 >        }
133 >        return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
134   }
135  
136 < sub store {
136 > sub toolbox {
137          my $self=shift;
138 <        my $location=shift;
138 >        if ( ! defined $self->{toolbox} ) {
139 >          $self->{toolbox}=BuildSystem::ToolBox->new($self);
140 >        }
141 >        return $self->{toolbox};
142 > }
143  
144 <        my $fh=$self->openfile(">".$location);
145 <        $self->savevar($fh,"location", $self->location());
146 <        $self->savevar($fh,"url", $self->url());
147 <        $self->savevar($fh,"name", $self->name());
148 <        $self->savevar($fh,"version", $self->version());
149 <        $fh->close();
144 > sub requirementsdoc {
145 >        my $self=shift;
146 >        if ( @_ ) {
147 >          $self->{reqdoc}=shift;
148 >        }
149 >        return (defined $self->{reqdoc})?$self->{reqdoc}:undef;
150 > }
151 >
152 > sub scramversion {
153 >        my $self=shift;
154 >        if ( ! defined $self->{scramversion} ) {
155 >          my $filename=$self->location()."/".$self->configurationdir()."/".
156 >                                                        "scram_version";
157 >          if ( -f $filename ) {
158 >            use FileHandle;
159 >            $fh=FileHandle->new();
160 >            open ($fh, "<".$filename);
161 >            my $version=<$fh>;
162 >            chomp $version;
163 >            $self->{scramversion}=$version;
164 >            undef $fh;
165 >          }
166 >        }
167 >        return $self->{scramversion};
168   }
169  
170 < sub restore {
170 > sub bootstrapfromlocation {
171          my $self=shift;
111        my $location=shift;
172  
173 <        my $fh=$self->openfile("<".$location);
174 <        my $varhash={};
175 <        $self->restorevars($fh,$varhash);
176 <        $self->location($$varhash{"location"});
177 <        $self->_setupstore();
178 <        $self->url($$varhash{"url"});
179 <        $self->name($$varhash{"name"});
180 <        $self->version($$varhash{"version"});
181 <        $fh->close();
173 >        my $rv=0;
174 >        
175 >        my $location;
176 >        if ( ! defined ($location=$self->searchlocation(@_)) ) {
177 >         $rv=1;
178 >         $self->verbose("Unable to locate the top of local configuration area");
179 >        }
180 >        else {
181 >         $self->location($location);
182 >         $self->verbose("Found top ".$self->location());
183 >         my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat";
184 >         $self->_LoadEnvFile();
185 >        }
186 >        return $rv;
187   }
188  
189 < sub name {
189 > sub location {
190          my $self=shift;
191  
192 <        @_?$self->{name}=shift
193 <          :$self->{name};
192 >        if ( @_ ) {
193 >          $self->{location}=shift;
194 >        }
195 >        elsif ( ! defined $self->{location} ) {
196 >          # try and find the release location
197 >          $self->{location}=$self->searchlocation();
198 >        }
199 >        return  $self->{location};
200   }
201  
202 < sub version {
202 > sub searchlocation {
203          my $self=shift;
204  
205 <        @_?$self->{version}=shift
206 <          :$self->{version};
205 >        #start search in current directory if not specified
206 >        my $thispath;
207 >        if ( @_ ) {
208 >          $thispath=shift
209 >        }
210 >        else {
211 >          $thispath=cwd();
212 >        }
213 >
214 >        my $rv=0;
215 >
216 >        # chop off any files - we only want dirs
217 >        if ( -f $thispath ) {
218 >          $thispath=~s/(.*)\/.*/$1/;
219 >        }
220 >        Sloop:{
221 >        do {
222 >          $self->verbose("Searching $thispath");
223 >          if ( -e "$thispath/".$self->{admindir} ) {
224 >            $self->verbose("Found\n");
225 >            $rv=1;
226 >            last Sloop;
227 >          }
228 >        } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
229 >
230 >        return $rv?$thispath:undef;
231   }
232  
233 < sub location {
233 > sub satellite {
234          my $self=shift;
235  
236 <        @_?$self->{location}=shift
237 <          :$self->{location};
236 >        # -- create the sat object
237 >        my $sat=Configuration::ConfigArea->new();
238 >        $sat->name($self->name());
239 >        $sat->version($self->version());
240 >        $sat->requirementsdoc($self->requirementsdoc());
241 >        $sat->configurationdir($self->configurationdir());
242 >        $sat->setup(@_);
243 >
244 >        # -- copy across the cache
245 >        copy($self->cache()->location(),$sat->cache()->location());
246 >        # and make sure in reinitialises
247 >        undef ($sat->{cache});
248 >
249 >        # -- link it to this area
250 >        $sat->linkarea($self);
251 >
252   }
253  
254 < sub meta {
254 > sub copy {
255          my $self=shift;
256 +        my $destination=shift;
257  
258 <        my $string=$self->name()." ".$self->version()." located at :\n  ".
259 <                $self->location;
258 >        # copy across the admin dir
259 >        my $temp=$self->location()."/".$self->{admindir};
260 >        AddDir::copydir($temp,"$destination/".$self->{admindir});
261   }
262  
263 < sub configitem {
263 > sub align {
264          my $self=shift;
265 <        my $location=shift;
266 <        
267 <        $self->config()->find("ConfigItem",@_);
265 >        use File::Copy;
266 >
267 >        $self->_LoadEnvFile();
268 >        my $Envfile=$self->location()."/".$self->{admindir}."/Environment";
269 >        my $tmpEnvfile=$Envfile.".bak";
270 >        my $rel=$self->{ENV}{RELEASETOP};
271 >        my $local=$self->location();
272 >
273 >        rename( $Envfile, $tmpEnvfile );
274 >        use FileHandle;
275 >        my $fh=FileHandle->new();
276 >        my $fout=FileHandle->new();
277 >        open ( $fh, "<".$tmpEnvfile ) or
278 >                $self->error("Cannot find Environment file. Area Corrupted? ("
279 >                                .$self->location().")\n $!");
280 >        open ( $fout, ">".$Envfile ) or
281 >                $self->error("Cannot find Environment file. Area Corrupted? ("
282 >                                .$self->location().")\n $!");
283 >        while ( <$fh> ) {
284 >          $_=~s/\Q$rel\L/$local/g;
285 >          print $fout $_;
286 >        }
287 >        undef $fh;
288 >        undef $fout;
289   }
290  
291 < sub addconfigitem {
291 > sub copysetup {
292          my $self=shift;
293 <        my $url=shift;
293 >        my $dest=shift;
294  
295 <        my $docref=$self->activatedoc($url);
296 <        # Set up the document
297 <        $docref->setup();
298 < #       $self->config()->storepolicy("local");
299 <        $docref->save();
295 >        my $rv=1;
296 >        # copy across the admin dir
297 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
298 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
299 >        if ( $temp ne $temp2 ) {
300 >         if ( -d $temp ) {
301 >          AddDir::copydir($temp,$temp2);
302 >          $rv=0;
303 >         }
304 >        }
305 >        return $rv;
306   }
307  
308 < # -------------- Tags ---------------------------------
171 < # -- init parse
172 < sub Project_Start {
308 > sub copyenv {
309          my $self=shift;
174        my $name=shift;
310          my $hashref=shift;
311 +        
312 +        foreach $elem ( keys %{$self->{ENV}} ) {
313 +           $$hashref{$elem}=$self->{ENV}{$elem};
314 +        }
315 + }
316  
317 <        $self->checktag($name,$hashref,'name');
318 <        $self->checktag($name,$hashref,'version');
317 > sub arch {
318 >        my $self=shift;
319 >        return $ENV{SCRAM_ARCH};
320 > }
321  
322 <        $self->name($$hashref{'name'});
323 <        $self->version($$hashref{'version'});
322 > sub linkto {
323 >        my $self=shift;
324 >        my $location=shift;
325 >        if ( -d $location ) {
326 >        my $area=Configuration::ConfigArea->new();
327 >        $area->bootstrapfromlocation($location);
328 >        $self->linkarea($area);
329 >        }
330 >        else {
331 >          $self->error("ConfigArea : Unable to link to non existing directory ".
332 >                         $location);
333 >        }
334   }
335  
336 + sub unlinkarea {
337 +        my $self=shift;
338 +        undef $self->{linkarea};
339 +        $self->{linkarea}=undef;
340 +        $self->save();
341 + }
342  
343 < sub Project_text {
343 > sub linkarea {
344          my $self=shift;
345 <        my $name=shift;
346 <        my $string=shift;
345 >        my $area=shift;
346 >        if ( defined $area ) {
347 >          $self->{linkarea}=$area;
348 >        }
349 >        return (defined $self->{linkarea} && $self->{linkarea} ne "")?
350 >                        $self->{linkarea}:undef;
351 > }
352  
353 <        print $string;
353 > sub save {
354 >        my $self=shift;
355 >        $self->_SaveEnvFile();
356   }
357  
358 < # ---- download parse
358 > # ---- support routines
359  
360 < sub Use_download_Start {
360 > sub _SaveEnvFile {
361          my $self=shift;
362 <        my $name=shift;
363 <        my $hashref=shift;
364 <
365 <        $self->checktag($name,$hashref,'url');
366 <        print "Downloading .... ".$$hashref{'url'}."\n";
367 <        $self->getfile($$hashref{'url'});
362 >        use FileHandle;
363 >        my $fh=FileHandle->new();
364 >        open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
365 >                "Environment" ) or
366 >                $self->error("Cannot Open Environment file to Save ("
367 >                                .$self->location().")\n $!");
368 >        
369 >        print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
370 >        print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
371 >        print $fh "projconfigdir=".$self->configurationdir()."\n";
372 >        print $fh "SCRAM_ProjReqsDoc=".$self->requirementsdoc()."\n";
373 >        if ( defined $self->linkarea() ) {
374 >          my $area=$self->linkarea()->location();
375 >          if ( $area ne "" ) {
376 >          print $fh "RELEASETOP=".$area."\n";
377 >          }
378 >        }
379 >        undef $fh;
380   }
381  
205 # --- setup parse
382  
383 < sub Use_Start {
383 > sub _LoadEnvFile {
384          my $self=shift;
385 <        my $name=shift;
386 <        my $hashref=shift;
385 >
386 >        use FileHandle;
387 >        my $fh=FileHandle->new();
388 >        open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
389 >                "Environment" ) or
390 >                $self->error("Cannot find Environment file. Area Corrupted? ("
391 >                                .$self->location().")\n $!");
392 >        while ( <$fh> ) {
393 >           chomp;
394 >           next if /^#/;
395 >           next if /^\s*$/ ;
396 >           ($name, $value)=split /=/;
397 >           eval "\$self->{ENV}{${name}}=\"$value\"";
398 >        }
399 >        undef $fh;
400          
401 <        $self->checktag($name,$hashref,'url');
402 <        $self->addconfigitem($$hashref{'url'});
401 >        # -- set internal variables appropriately
402 >        if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} ) {
403 >          $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
404 >        }
405 >        if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} ) {
406 >          $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
407 >        }
408 >        if ( defined $self->{ENV}{"projconfigdir"} ) {
409 >          $self->configurationdir($self->{ENV}{projconfigdir});
410 >        }
411 >        if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} ) {
412 >          $self->requirementsdoc($self->{ENV}{SCRAM_ProjReqsDoc});
413 >        }
414 >        if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
415 >                        ($self->{ENV}{"RELEASETOP"} ne $self->location())) {
416 >          $self->linkto($self->{ENV}{"RELEASETOP"});
417 >        }
418 >        else {
419 >          $self->{ENV}{"RELEASETOP"}=$self->location();
420 >        }
421   }
215

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines