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.5 by williamc, Mon Aug 14 12:38:22 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);
78 <        $self->addurltags("setup");
79 <        $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 name {
81 >        my $self=shift;
82 >        @_?$self->{name}=shift
83 >          :$self->{name};
84 > }
85 >
86 > sub version {
87 >        my $self=shift;
88 >        @_?$self->{version}=shift
89 >          :$self->{version};
90   }
91  
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 +        # -- add a cache
125 +        $self->cache();
126 +
127 +        # -- Save Environment File
128 +        $self->_SaveEnvFile();
129  
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());
130   }
131  
132 < sub _setupstore {
132 > sub configurationdir {
133          my $self=shift;
134 +        if ( @_ ) {
135 +          $self->{configurationdir}=shift;
136 +        }
137 +        return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
138 + }
139  
140 <        # --- make a new ActiveStore at the location and add it to the db list
141 <        my $ad=ActiveDoc::ActiveConfig->new($self->location()."/\.SCRAM");
140 > sub toolbox {
141 >        my $self=shift;
142 >        if ( ! defined $self->{toolbox} ) {
143 >          $self->{toolbox}=BuildSystem::ToolBox->new($self);
144 >        }
145 >        return $self->{toolbox};
146 > }
147  
148 <        $self->parentconfig($self->config());
149 < #        $self->config(Configuration::ConfigureStore->new());
150 < #        $self->config()->db("local",$ad);
151 < #        $self->config()->db("parent",$self->parentconfig());
152 < #        $self->config()->policy("cache","local");
153 <        $self->config($ad);
154 <        $self->config()->basedoc($self->parentconfig()->basedoc());
148 > sub requirementsdoc {
149 >        my $self=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 < sub parentconfig {
161 > sub scramversion {
162          my $self=shift;
163 <        @_?$self->{parentconfig}=shift
164 <          :$self->{parentconfig};
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 store {
179 > sub bootstrapfromlocation {
180          my $self=shift;
99        my $location=shift;
181  
182 <        my $fh=$self->openfile(">".$location);
183 <        $self->savevar($fh,"location", $self->location());
184 <        $self->savevar($fh,"url", $self->url());
185 <        $self->savevar($fh,"name", $self->name());
186 <        $self->savevar($fh,"version", $self->version());
187 <        $fh->close();
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 restore {
198 > sub location {
199          my $self=shift;
111        my $location=shift;
200  
201 <        my $fh=$self->openfile("<".$location);
202 <        my $varhash={};
203 <        $self->restorevars($fh,$varhash);
204 <        $self->location($$varhash{"location"});
205 <        $self->_setupstore();
206 <        $self->url($$varhash{"url"});
207 <        $self->name($$varhash{"name"});
208 <        $self->version($$varhash{"version"});
121 <        $fh->close();
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 name {
211 > sub searchlocation {
212          my $self=shift;
213  
214 <        @_?$self->{name}=shift
215 <          :$self->{name};
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 version {
242 > sub archname {
243          my $self=shift;
244 +        if ( @_ ) {
245 +          $self->{archname}=shift;
246 +        }
247 +        return $self->{archname};
248 + }
249  
250 <        @_?$self->{version}=shift
251 <          :$self->{version};
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 location {
268 > sub satellite {
269          my $self=shift;
270  
271 <        @_?$self->{location}=shift
272 <          :$self->{location};
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 >        return $sat;
288   }
289  
290 < sub meta {
290 > sub copy {
291          my $self=shift;
292 +        my $destination=shift;
293  
294 <        my $string=$self->name()." ".$self->version()." located at :\n  ".
295 <                $self->location;
294 >        # copy across the admin dir
295 >        my $temp=$self->location()."/".$self->{admindir};
296 >        AddDir::copydir($temp,"$destination/".$self->{admindir});
297   }
298  
299 < sub configitem {
299 > sub align {
300          my $self=shift;
301 <        my $location=shift;
302 <        
303 <        $self->config()->find("ConfigItem",@_);
301 >        use File::Copy;
302 >
303 >        $self->_LoadEnvFile();
304 >        my $Envfile=$self->location()."/".$self->{admindir}."/Environment";
305 >        my $tmpEnvfile=$Envfile.".bak";
306 >        my $rel=$self->{ENV}{RELEASETOP};
307 >        my $local=$self->location();
308 >
309 >        rename( $Envfile, $tmpEnvfile );
310 >        use FileHandle;
311 >        my $fh=FileHandle->new();
312 >        my $fout=FileHandle->new();
313 >        open ( $fh, "<".$tmpEnvfile ) or
314 >                $self->error("Cannot find Environment file. Area Corrupted? ("
315 >                                .$self->location().")\n $!");
316 >        open ( $fout, ">".$Envfile ) or
317 >                $self->error("Cannot find Environment file. Area Corrupted? ("
318 >                                .$self->location().")\n $!");
319 >        while ( <$fh> ) {
320 >          $_=~s/\Q$rel\L/$local/g;
321 >          print $fout $_;
322 >        }
323 >        undef $fh;
324 >        undef $fout;
325   }
326  
327 < sub addconfigitem {
327 > sub copysetup {
328          my $self=shift;
329 <        my $url=shift;
329 >        my $dest=shift;
330  
331 <        my $docref=$self->activatedoc($url);
332 <        # Set up the document
333 <        $docref->setup();
334 < #       $self->config()->storepolicy("local");
335 <        $docref->save();
331 >        my $rv=1;
332 >        # copy across the admin dir
333 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
334 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
335 >        if ( $temp ne $temp2 ) {
336 >         if ( -d $temp ) {
337 >          AddDir::copydir($temp,$temp2);
338 >          $rv=0;
339 >         }
340 >        }
341 >        return $rv;
342   }
343  
344 < # -------------- Tags ---------------------------------
171 < # -- init parse
172 < sub Project_Start {
344 > sub copyenv {
345          my $self=shift;
174        my $name=shift;
346          my $hashref=shift;
347 +        
348 +        foreach $elem ( keys %{$self->{ENV}} ) {
349 +           $$hashref{$elem}=$self->{ENV}{$elem};
350 +        }
351 + }
352  
353 <        $self->checktag($name,$hashref,'name');
354 <        $self->checktag($name,$hashref,'version');
353 > sub arch {
354 >        my $self=shift;
355 >        return $ENV{SCRAM_ARCH};
356 > }
357  
358 <        $self->name($$hashref{'name'});
359 <        $self->version($$hashref{'version'});
358 > sub linkto {
359 >        my $self=shift;
360 >        my $location=shift;
361 >        if ( -d $location ) {
362 >        my $area=Configuration::ConfigArea->new();
363 >        $area->bootstrapfromlocation($location);
364 >        $self->linkarea($area);
365 >        }
366 >        else {
367 >          $self->error("ConfigArea : Unable to link to non existing directory ".
368 >                         $location);
369 >        }
370   }
371  
372 + sub unlinkarea {
373 +        my $self=shift;
374 +        undef $self->{linkarea};
375 +        $self->{linkarea}=undef;
376 +        $self->save();
377 + }
378  
379 < sub Project_text {
379 > sub linkarea {
380          my $self=shift;
381 <        my $name=shift;
382 <        my $string=shift;
381 >        my $area=shift;
382 >        if ( defined $area ) {
383 >          $self->{linkarea}=$area;
384 >        }
385 >        return (defined $self->{linkarea} && $self->{linkarea} ne "")?
386 >                        $self->{linkarea}:undef;
387 > }
388  
389 <        print $string;
389 > sub save {
390 >        my $self=shift;
391 >        $self->_SaveEnvFile();
392   }
393  
394 < # ---- download parse
394 > # ---- support routines
395  
396 < sub Use_download_Start {
396 > sub _SaveEnvFile {
397          my $self=shift;
398 <        my $name=shift;
399 <        my $hashref=shift;
400 <
401 <        $self->checktag($name,$hashref,'url');
402 <        print "Downloading .... ".$$hashref{'url'}."\n";
403 <        $self->getfile($$hashref{'url'});
398 >        use FileHandle;
399 >        my $fh=FileHandle->new();
400 >        open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
401 >                "Environment" ) or
402 >                $self->error("Cannot Open Environment file to Save ("
403 >                                .$self->location().")\n $!");
404 >        
405 >        print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
406 >        print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
407 >        print $fh "projconfigdir=".$self->configurationdir()."\n";
408 >        print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n";
409 >        if ( defined $self->linkarea() ) {
410 >          my $area=$self->linkarea()->location();
411 >          if ( $area ne "" ) {
412 >          print $fh "RELEASETOP=".$area."\n";
413 >          }
414 >        }
415 >        undef $fh;
416   }
417  
205 # --- setup parse
418  
419 < sub Use_Start {
419 > sub _LoadEnvFile {
420          my $self=shift;
421 <        my $name=shift;
422 <        my $hashref=shift;
421 >
422 >        use FileHandle;
423 >        my $fh=FileHandle->new();
424 >        open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
425 >                "Environment" ) or
426 >                $self->error("Cannot find Environment file. Area Corrupted? ("
427 >                                .$self->location().")\n $!");
428 >        while ( <$fh> ) {
429 >           chomp;
430 >           next if /^#/;
431 >           next if /^\s*$/ ;
432 >           ($name, $value)=split /=/;
433 >           eval "\$self->{ENV}{${name}}=\"$value\"";
434 >        }
435 >        undef $fh;
436          
437 <        $self->checktag($name,$hashref,'url');
438 <        $self->addconfigitem($$hashref{'url'});
437 >        # -- set internal variables appropriately
438 >        if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} ) {
439 >          $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
440 >        }
441 >        if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} ) {
442 >          $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
443 >        }
444 >        if ( defined $self->{ENV}{"projconfigdir"} ) {
445 >          $self->configurationdir($self->{ENV}{projconfigdir});
446 >        }
447 >        if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} ) {
448 >          $self->requirementsdoc($self->{ENV}{SCRAM_ProjReqsDoc});
449 >        }
450 >        if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
451 >                        ($self->{ENV}{"RELEASETOP"} ne $self->location())) {
452 >          $self->linkto($self->{ENV}{"RELEASETOP"});
453 >        }
454 >        else {
455 >          $self->{ENV}{"RELEASETOP"}=$self->location();
456 >        }
457   }
215

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines