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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines