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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines