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.11 by williamc, Thu Feb 24 14:24:29 2000 UTC vs.
Revision 1.13.2.5 by williamc, Thu May 4 07:53:17 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   # -----------
# Line 14 | Line 14
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
29 < # basearea(ConfigArea)          : Set/Get the base area
30 < # freebase()                    : Remove any link to a base area
31 < # bootstrapfromlocation([location]): bootstrap the object based on location.
32 < #                                 no location specified - cwd used
17 > # new()                         : A new ConfigArea object
18 > # location([dir])               : set/return the location of the work area
19 > # bootstrapfromlocation([location]) : bootstrap the object based on location.
20 > #                                     no location specified - cwd used
21 > #                                     return 0 if succesful 1 otherwise
22 > # requirementsdoc()             : get set the requirements doc
23   # searchlocation([startdir])    : returns the location directory. search starts
24   #                                 from cwd if not specified
25   # defaultdirname()              : return the default directory name string
26 < # copy(location)                : make a copy of the current area at the
27 < #                                 specified location - defaults to cwd/default
28 < #                                 if not specified . ConfigArea_name,
29 < #                                 ConfigArea_location also override .
30 < #                                 Return an object representing the area
31 < # satellite()                   : make a satellite area based on $self
32 < # arch([archobj])               : Set/get the architecture object
33 < # structure(name)               : return the object corresponding to the
34 < #                                 structure name
45 < # structurelist()               : return list of structure objectS
46 < # downloadtotop(dir,url)        : download the url to a dir in the config area
47 < #                                
26 > # scramversion()                : return the scram version associated with
27 > #                                 area
28 > # configurationdir()            : return the location of the project
29 > #                                 configuration directory
30 > # copy(location)                : copy a configuration
31 > # copysetup(location)           : copy the architecture specific tool setup
32 > #                                 returns 0 if successful, 1 otherwise
33 > # copyenv($ref)                 : copy the areas environment into the hashref
34 > # toolbox()                     : return the areas toolbox object
35  
36   package Configuration::ConfigArea;
50 use ActiveDoc::ActiveDoc;
37   require 5.004;
38   use Utilities::AddDir;
39 < use ObjectUtilities::ObjectStore;
54 < use Configuration::ConfigStore;
55 < use Configuration::ActiveDoc_arch;
39 > use Utilities::Verbose;
40   use Cwd;
41 < @ISA=qw(Configuration::ActiveDoc_arch ObjectUtilities::StorableObject);
41 > @ISA=qw(Utilities::Verbose);
42  
43 < sub init {
44 <        my $self=shift;
45 <
46 <        $self->newparse("init");
63 <        $self->newparse("download");
64 <        $self->newparse("setup");
65 <        $self->newparse("setup_tools");
66 <        $self->addarchtags("setup_tools");
67 <        $self->addarchtags("setup");
68 <        $self->addtag("init","project",\&Project_Start,$self,
69 <            \&Project_text,$self,"", $self );
70 <        $self->addurltags("download");
71 <        $self->addtag("download","download",\&Download_Start,$self,
72 <                                                "", $self, "",$self);
73 <        $self->addtag("download","use",\&Use_download_Start,$self,
74 <                                                "", $self, "",$self);
75 <        $self->addurltags("setup");
76 <        $self->addtag("setup_tools","use",\&Use_Start,$self, "", $self, "",$self);
77 <        $self->addtag("setup","structure",\&Structure_Start,$self,
78 <                         "", $self, "",$self);
43 > sub new {
44 >        my $class=shift;
45 >        my $self={};
46 >        bless $self, $class;
47  
48          # data init
49 <        $self->{admindir}=".SCRAM";
49 >        $self->{admindir}=".SCRAM";
50 >
51 >        return $self;
52   }
53  
54 < sub basearea {
54 > sub configurationdir {
55          my $self=shift;
86
87        my $area;
56          if ( @_ ) {
57 <          $area=shift;
90 <          $self->config()->store($area,"BaseArea");
57 >          $self->{configurationdir}=shift;
58          }
59 <        else {
60 <          ($area)=$self->config()->restore("BaseArea");
59 >        if ( ! defined $self->{configurationdir} ) {
60 >          $self->_LoadEnvFile();
61 >          $self->{configurationdir}=$self->{ENV}{projconfigdir};
62          }
63 <        return $area;
63 >        return $self->{configurationdir};
64   }
65  
66 < sub freebase {
66 > sub toolbox {
67          my $self=shift;
68 <        $self->config()->delete("BaseArea");
69 < }
102 <
103 < sub defaultdirname {
104 <        my $self=shift;
105 <        my $name=$self->name();
106 <        my $vers=$self->version();
107 <        $vers=~s/^$name\_//;
108 <        $name=$name."_".$vers;
109 <        return $name;
110 < }
111 <
112 <
113 < sub setup {
114 <        my $self=shift;
115 <
116 <        # --- find out the location - default is cwd
117 <        my $location=$self->option("ConfigArea_location");
118 <        if ( ! defined $location ) {
119 <                $location=cwd();
68 >        if ( ! defined $self->{toolbox} ) {
69 >          $self->{toolbox}=BuildSystem::ToolBox->new($self);
70          }
71 <        elsif ( $location!~/^\// ) {
122 <                $location=cwd()."/".$location;
123 <        }
124 <
125 <        # --- find area directory name , default name projectname_version
126 <        my $name=$self->option("ConfigArea_name");
127 <        if ( ! defined $name ) {
128 <          $name=$self->defaultdirname();
129 <        }
130 <        $self->location($location."/".$name);
131 <
132 <        # make a new store handler
133 <        $self->_setupstore();
134 <
135 <        # --- download everything first
136 <        $self->parse("download");
137 <        
138 <        # --- and parse the setup file
139 <        $self->parse("setup");
140 <        $self->parse("setup_tools");
141 <        
142 <        # --- store bootstrap info
143 <        $self->store($self->location()."/".$self->{admindir}."/ConfigArea.dat");
144 <
145 <        # --- store self in original database
146 <        $self->parentconfig()->store($self,"ConfigArea",$self->name(),
147 <                                                        $self->version());
71 >        return $self->{toolbox};
72   }
73  
74 < sub structure {
74 > sub requirementsdoc {
75          my $self=shift;
76 <        my $vr=shift;
77 <        return $self->{structures}{$vr};
78 < }
79 <
80 < sub structurelist {
81 <        my $self=shift;
82 <        return ( keys %{$self->{structures}} );
83 < }
84 <
85 < sub _setupstore {
86 <        my $self=shift;
87 <
88 <        # --- make a new ConfigStore at the location and add it to the db list
89 <        my $ad=Configuration::ConfigStore->new($self->location().
90 <                                "/".$self->{admindir}, $self->arch());
91 <
92 <        $self->parentconfig($self->config());
93 < #        $self->config(Configuration::ConfigureStore->new());
94 < #        $self->config()->db("local",$ad);
95 < #        $self->config()->db("parent",$self->parentconfig());
96 < #        $self->config()->policy("cache","local");
97 <        $self->config($ad);
98 <        $self->config()->basedoc($self->parentconfig()->basedoc());
99 < }
176 <
177 < sub bootstrapfromlocation {
178 <        my $self=shift;
179 <        
180 <        if ( ! defined $self->location(@_) ) {
181 <          $self->error("Unable to locate the top of local configuration area");
76 >        if ( @_ ) {
77 >          $self->{reqdoc}=shift;
78 >        }
79 >        if ( ! defined $self->{reqdoc} ) {
80 >          $self->_LoadEnvFile();
81 >          $self->{reqdoc}=$self->{ENV}{SCRAM_ProjReqsDoc};
82 >        }
83 >        return $self->{reqdoc};
84 > }
85 >
86 > sub scramversion {
87 >        my $self=shift;
88 >        if ( ! defined $self->{scramversion} ) {
89 >          my $filename=$self->location()."/".$self->configurationdir()."/".
90 >                                                        "scram_version";
91 >          if ( -f $filename ) {
92 >            use FileHandle;
93 >            $fh=FileHandle->new();
94 >            open ($fh, "<".$filename);
95 >            my $version=<$fh>;
96 >            chomp $version;
97 >            $self->{scramversion}=$version;
98 >            undef $fh;
99 >          }
100          }
101 <        print "Found top ".$self->location()."\n";
184 <        $self->_setupstore();
185 <        $self->restore($self->location()."/".$self->{admindir}.
186 <                                                "/ConfigArea.dat");
101 >        return $self->{scramversion};
102   }
103  
104 < sub parentconfig {
190 <        my $self=shift;
191 <        @_?$self->{parentconfig}=shift
192 <          :$self->{parentconfig};
193 < }
194 <
195 < sub store {
196 <        my $self=shift;
197 <        my $location=shift;
198 <
199 <        my $fh=$self->openfile(">".$location);
200 <        $self->savevar($fh,"location", $self->location());
201 <        $self->savevar($fh,"url", $self->url());
202 <        $self->savevar($fh,"name", $self->name());
203 <        $self->savevar($fh,"version", $self->version());
204 <        $fh->close();
205 <
206 <        $self->_storestructures();
207 < }
208 <
209 < sub satellite {
210 <        my $self=shift;
211 <        my $newarea=$self->copy(@_);
212 <        $newarea->_makesatellites();
213 <        return $newarea;
214 < }
215 <
216 < sub copy {
104 > sub bootstrapfromlocation {
105          my $self=shift;
218        use File::Basename;
219        # create the area
106  
107 <        my $destination;
108 <        if ( @_ ) {
109 <         $destination=shift;
107 >        my $rv=0;
108 >        
109 >        my $location;
110 >        if ( ! defined ($location=$self->searchlocation(@_)) ) {
111 >         $rv=1;
112 >         $self->verbose("Unable to locate the top of local configuration area");
113          }
114          else {
115 <          my($location,$name)=$self->_defaultoptions();
116 <          $destination=$location."/".$name
117 <        }
118 <        #AddDir::adddir(dirname($destination)."/".$self->{admindir});
230 <        #AddDir::adddir($destination."/".$self->{admindir});
231 <        
232 <        # copy across the admin dir
233 <        $temp=$self->location()."/".$self->{admindir};
234 <        AddDir::copydir($temp,"$destination/".$self->{admindir});
235 <        # create a new object based on the new area
236 <        my $newarea=ref($self)->new($self->parentconfig());
237 <        $newarea->bootstrapfromlocation($destination);
238 <        # save it with the new location info
239 <        $newarea->store($self->location()."/".$self->{admindir}.
240 <                                                        "/ConfigArea.dat");
241 <        return $newarea;
242 < }
243 <
244 < sub restore {
245 <        my $self=shift;
246 <        my $location=shift;
247 <
248 <        my $fh=$self->openfile("<".$location);
249 <        my $varhash={};
250 <        $self->restorevars($fh,$varhash);
251 <        if ( ! defined $self->location() ) {
252 <          $self->location($$varhash{"location"});
115 >         $self->location($location);
116 >         $self->verbose("Found top ".$self->location());
117 >         my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat";
118 >         $self->_LoadEnvFile();
119          }
120 <        $self->_setupstore();
255 <        $self->url($$varhash{"url"});
256 <        $self->name($$varhash{"name"});
257 <        $self->version($$varhash{"version"});
258 <        $fh->close();
259 <
260 <        $self->_restorestructures();
261 < }
262 <
263 < sub name {
264 <        my $self=shift;
265 <
266 <        @_?$self->{name}=shift
267 <          :$self->{name};
268 < }
269 <
270 < sub version {
271 <        my $self=shift;
272 <
273 <        @_?$self->{version}=shift
274 <          :$self->{version};
120 >        return $rv;
121   }
122  
123   sub location {
# Line 292 | Line 138 | sub searchlocation {
138  
139          #start search in current directory if not specified
140          my $thispath;
141 <        @_?$thispath=shift
142 <          :$thispath=cwd();
141 >        if ( @_ ) {
142 >          $thispath=shift
143 >        }
144 >        else {
145 >          $thispath=cwd();
146 >        }
147  
148          my $rv=0;
149  
150 +        # chop off any files - we only want dirs
151 +        if ( -f $thispath ) {
152 +          $thispath=~s/(.*)\/.*/$1/;
153 +        }
154          Sloop:{
155          do {
156 < #         print "Searching $thispath\n";
156 >          $self->verbose("Searching $thispath");
157            if ( -e "$thispath/".$self->{admindir} ) {
158 < #           print "Found\n";
158 >            $self->verbose("Found\n");
159              $rv=1;
160              last Sloop;
161            }
# Line 310 | Line 164 | sub searchlocation {
164          return $rv?$thispath:undef;
165   }
166  
167 < sub meta {
314 <        my $self=shift;
315 <
316 <        my $string=$self->name()." ".$self->version()." located at :\n  ".
317 <                $self->location;
318 < }
319 <
320 < sub configitem {
321 <        my $self=shift;
322 <        
323 <        return ($self->config()->find("ConfigItem",@_));
324 < }
325 <
326 < sub addconfigitem {
167 > sub copy {
168          my $self=shift;
169 <        my $url=shift;
169 >        my $destination=shift;
170  
171 <        my $docref=$self->activatedoc($url);
172 <        # Set up the document
173 <        $docref->setup();
333 <        $docref->save();
334 < #       $self->config()->storepolicy("local");
171 >        # copy across the admin dir
172 >        my $temp=$self->location()."/".$self->{admindir};
173 >        AddDir::copydir($temp,"$destination/".$self->{admindir});
174   }
175  
176 < sub downloadtotop {
176 > sub copysetup {
177          my $self=shift;
178 <        my $url=shift;
340 <        my $dir=shift;
341 <        
342 <        # only download once
343 <        if ( ! -e $self->location()."/".$dir ) {
344 <          $self->{urlhandler}->download($url,$self->location()."/".$dir);
345 <        }
346 < }
178 >        my $dest=shift;
179  
180 < sub _makesatellites {
181 <        my $self=shift;
182 <        foreach $st ( values %{$self->{structures}} ) {
183 <           $st->setupsatellite()
180 >        my $rv=1;
181 >        # copy across the admin dir
182 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
183 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
184 >        if ( $temp ne $temp2 ) {
185 >         if ( -d $temp ) {
186 >          AddDir::copydir($temp,$temp2);
187 >          $rv=0;
188 >         }
189          }
190 +        return $rv;
191   }
192  
193 < sub _storestructures {
193 > sub copyenv {
194          my $self=shift;
195 <        foreach $struct ( values %{$self->{structures}} ) {
196 <          $self->config()->store($struct, "Structures", $struct->name());
195 >        my $hashref=shift;
196 >        
197 >        foreach $elem ( keys %{$self->{ENV}} ) {
198 >           $$hashref{$elem}=$self->{ENV}{$elem};
199          }
200   }
201  
202 < sub _restorestructures {
202 > sub arch {
203          my $self=shift;
204 <        my @strs=$self->config()->find("Structures");
365 <        foreach $struct ( @strs ) {
366 <          $struct->parent($self);
367 <          $self->{structures}{$struct->name()}=$struct;
368 <        }
204 >        return $ENV{SCRAM_ARCH};
205   }
206  
207 < sub _defaultoptions {
207 > # ---- support routines
208 > sub _LoadEnvFile {
209          my $self=shift;
373        my $name;
374        my $location;
375
376        # --- find out the location - default is cwd
377        $location=$self->option("ConfigArea_location");
378        if ( ! defined $location ) {
379                $location=cwd();
380        }
381        elsif ( $location!~/^\// ) {
382                $location=cwd()."/".$location;
383        }
210  
211 <        # --- find area directory name , default name projectname_version
212 <        $name=$self->option("ConfigArea_name");
213 <        if ( ! defined $name ) {
214 <          $name=$self->defaultdirname();
211 >        use FileHandle;
212 >        my $fh=FileHandle->new();
213 >        open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
214 >                "Environment" ) or
215 >                $self->error("Cannot find Environment file. Area Corrupted? ("
216 >                                .$self->location().")\n $!");
217 >        while ( <$fh> ) {
218 >           chomp;
219 >           next if /^#/;
220 >           next if /^\s*$/ ;
221 >           ($name, $value)=split /=/;
222 >           eval "\$self->{ENV}{${name}}=\"$value\"";
223          }
224 <        return ($location,$name);
391 < }
392 < # -------------- Tags ---------------------------------
393 < # -- init parse
394 < sub Project_Start {
395 <        my $self=shift;
396 <        my $name=shift;
397 <        my $hashref=shift;
398 <
399 <        $self->checktag($name,$hashref,'name');
400 <        $self->checktag($name,$hashref,'version');
401 <
402 <        $self->name($$hashref{'name'});
403 <        $self->version($$hashref{'version'});
224 >        undef $fh;
225   }
226  
227 <
228 < sub Project_text {
229 <        my $self=shift;
409 <        my $name=shift;
410 <        my $string=shift;
411 <
412 <        print $string;
413 < }
414 <
415 < # ---- download parse
416 <
417 < sub Download_Start {
418 <        my $self=shift;
227 > sub _savevar {
228 >        my $self=shift;
229 >        my $fh=shift;
230          my $name=shift;
231 <        my $hashref=shift;
232 <
233 <        $self->checktag($name,$hashref,'url');
234 <        $self->checktag($name,$hashref,'location');
235 <        if ( $$hashref{'location'}!~/^\w/ ) {
236 <          $self->parseerror("location must start with an".
237 <                " alphanumeric character");
238 <        }
239 <        print "Downloading .... ".$$hashref{'url'}."\n";
240 <        $self->downloadtotop($$hashref{'url'},$$hashref{'location'});
241 < }
242 <
243 < sub Use_download_Start {
244 <        my $self=shift;
245 <        my $name=shift;
246 <        my $hashref=shift;
247 <
248 <        $self->checktag($name,$hashref,'url');
438 <        print "Downloading .... ".$$hashref{'url'}."\n";
439 <        $self->getfile($$hashref{'url'});
440 < }
441 <
442 < # --- setup parse
443 <
444 < sub Structure_Start {
445 <        my $self=shift;
446 <        my $name=shift;
447 <        my $hashref=shift;
448 <
449 <        $self->checktag($name,$hashref,'name');
450 <        if ( !(( exists $$hashref{'type'}) || ( exists $$hashref{'url'})) ) {
451 <            $self->parseerror("No url or type given in <$name> tag");
452 <        }
453 <        if ( ! exists $self->{structures}{$$hashref{'name'}} ) {
454 <          if ( exists $$hashref{'type'}) {
455 <            # create a new object of the specified type
456 <            eval "require $$hashref{'type'} ";
457 <            if  ( $@ ) {
458 <                $self->parseerror("Unable to instantiate type=".
459 <                        $$hashref{'type'}." in <$name> .".$@);
460 <            }
461 <            $self->{structures}{$$hashref{'name'}}=
462 <                $$hashref{'type'}->new($self->config());
463 <            $self->{structures}{$$hashref{'name'}}->name($$hashref{'name'});
464 <            $self->{structures}{$$hashref{'name'}}->parent($self);
465 <            $self->{structures}{$$hashref{'name'}}->vars($hashref);
466 <            $self->{structures}{$$hashref{'name'}}->arch($self->arch());
467 <          }
468 <          else { # its an activedoc
469 <                $self->{structures}{$$hashref{'name'}}=
470 <                                $self->activatedoc($$hashref{'url'});
471 <          }
472 <          $self->{structures}{$$hashref{'name'}}->setupbase();
473 <        }
474 <        else {
475 <             $self->parseerror("Multiply defined Structure - ".
476 <                                                        $$hashref{'name'});
477 <        }
478 < }
479 <
480 < sub Use_Start {
481 <        my $self=shift;
482 <        my $name=shift;
483 <        my $hashref=shift;
484 <        
485 <        $self->checktag($name,$hashref,'url');
486 <        $self->addconfigitem($$hashref{'url'});
231 >        my $val=shift;
232 >        print $fh "#".$name."\n";
233 >        print $fh $val."\n";
234 > }
235 >
236 > sub _restorevars {
237 >        my $self=shift;
238 >        my $fh=shift;
239 >        my $varhash=shift;
240 >
241 >        while ( <$fh>=~/^#(.*)/ ) {
242 >         $name=$1;
243 >         chomp $name;
244 >         $value=<$fh>;
245 >         chomp $value;
246 >         $$varhash{$name}=$value;
247 >        #print "Restoring ".$name."=".$value."\n";
248 >        }
249   }
488

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines