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.8 by williamc, Thu Feb 10 10:59:44 2000 UTC vs.
Revision 1.36 by muzaffar, Fri Jan 14 17:36:42 2011 UTC

# Line 1 | Line 1
1 #
2 # ConfigArea.pm
3 #
4 # Originally Written by Christopher Williams
5 #
6 # Description
7 #
8 # Interface
9 # ---------
10 # new(ActiveConfig)             : A new ConfigArea object
11 # setup()                       : setup the configuration area
12 # location([dir])               : set/return the location of the area
13 # version([version])            : set/return the version of the area
14 # name([name])                  : set/return the name of the area
15 # store(location)               : store data in file location
16 # restore(location)             : restore data from file location
17 # meta()                        : return a description string of the area
18 # addconfigitem(url)            : add a new item to the area
19 # configitem(@keys)             : return a list of fig items that match
20 #                                 the keys - all if left blank
21 # parentstore()                 : set/return the parent ObjectStore
22 # bootstrapfromlocation([location]): bootstrap the object based on location.
23 #                                 no location specified - cwd used
24 # searchlocation([startdir])    : returns the location directory. search starts
25 #                                 from cwd if not specified
26 # defaultdirname()              : return the default directory name string
27 # copy(location)                : make a copy of the current area at the
28 #                                 specified location - return an object
29 #                                 representing the area
30
1   package Configuration::ConfigArea;
32 use ActiveDoc::ActiveDoc;
2   require 5.004;
3   use Utilities::AddDir;
4 < use ObjectUtilities::ObjectStore;
36 < use Configuration::ConfigStore;
4 > use Utilities::Verbose;
5   use Cwd;
6 < @ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject);
39 <
40 < sub init {
41 <        my $self=shift;
6 > @ISA=qw(Utilities::Verbose);
7  
8 <        $self->newparse("init");
9 <        $self->newparse("download");
10 <        $self->newparse("setup");
11 <        $self->addtag("init","project",\&Project_Start,$self,
12 <            \&Project_text,$self,"", $self );
13 <        $self->addurltags("download");
14 <        $self->addtag("download","use",\&Use_download_Start,$self,
15 <                                                "", $self, "",$self);
16 <        $self->addurltags("setup");
17 <        $self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self);
18 <
19 <        # data init
20 <        $self->{admindir}=".SCRAM";
8 > sub new {
9 >        my $class=shift;
10 >        my $self={};
11 >        bless $self, $class;
12 >        $self->{admindir}=".SCRAM";
13 >        $self->{configurationdir} = "config";
14 >        $self->archname(shift || $ENV{SCRAM_ARCH});
15 >        return $self;
16 > }
17 >
18 > sub toolcachename
19 >   {
20 >   my $self=shift;
21 >   return ($self->archdir()."/ToolCache.db.gz");
22 >   }
23 >
24 > sub projectcachename
25 >   {
26 >   my $self=shift;
27 >   return ($self->archdir()."/ProjectCache.db.gz");
28 >   }
29 >
30 > sub symlinks {
31 >        my $self=shift;
32 >        if (@_) {$self->{symlinks}=shift;}
33 >        return $self->{symlinks};
34 > }
35 >
36 > sub calchksum {
37 >        my $self=shift;
38 >        my $dir=$self->location()."/".$self->configurationdir();
39 >        push @INC,$dir;
40 >        require SCRAM::Plugins::ProjectChkSum;
41 >        my $sum=&SCRAM::Plugins::ProjectChkSum::chksum($dir);
42 >        pop @INC;
43 >        return $sum;
44   }
45  
46 <
59 < sub defaultdirname {
46 > sub configchksum {
47          my $self=shift;
48 <        my $name=$self->name();
49 <        my $vers=$self->version();
63 <        $vers=~s/^$name_//;
64 <        $name=$name."_".$vers;
65 <        return $name;
66 <
67 < }
68 <
69 < sub setup {
70 <        my $self=shift;
71 <
72 <        # --- find out the location - default is cwd
73 <        my $location=$self->option("area_location");
74 <        if ( ! defined $location ) {
75 <                $location=cwd();
76 <        }
77 <        elsif ( $location!~/^\// ) {
78 <                $location=cwd()."/".$location;
79 <        }
80 <
81 <        # --- find area directory name , default name projectname_version
82 <        my $name=$self->option("area_name");
83 <        if ( ! defined $name ) {
84 <          $name=$self->defaultdirname();
85 <        }
86 <        $self->location($location."/".$name);
87 <
88 <        # make a new store handler
89 <        $self->_setupstore();
90 <
91 <        # --- download everything first
92 < # FIX-ME --- cacheing is broken
93 <        $self->parse("download");
94 <        
95 <        # --- and parse the setup file
96 <        $self->parse("setup");
97 <        
98 <        # --- store bootstrap info
99 <        $self->store($self->location()."/".$self->{admindir}."/ConfigArea.dat");
100 <
101 <        # --- store self in original database
102 <        $self->parentconfig()->store($self,"ConfigArea",$self->name(),
103 <                                                        $self->version());
48 >        if (@_) {$self->{configchksum}=shift;}
49 >        return $self->{configchksum};
50   }
51  
106 sub _setupstore {
107        my $self=shift;
108
109        # --- make a new ConfigStore at the location and add it to the db list
110        my $ad=Configuration::ConfigStore->new($self->location().
111                                "/".$self->{admindir});
52  
53 <        $self->parentconfig($self->config());
114 < #        $self->config(Configuration::ConfigureStore->new());
115 < #        $self->config()->db("local",$ad);
116 < #        $self->config()->db("parent",$self->parentconfig());
117 < #        $self->config()->policy("cache","local");
118 <        $self->config($ad);
119 <        $self->config()->basedoc($self->parentconfig()->basedoc());
120 < }
121 <
122 < sub bootstrapfromlocation {
53 > sub name {
54          my $self=shift;
55 <        
56 <        if ( ! defined $self->location(@_) ) {
126 <          $self->error("Unable to locate the top of local configuration area");
127 <        }
128 <        print "Found top ".$self->location()."\n";
129 <        $self->_setupstore();
130 <        $self->restore($self->location()."/".$self->{admindir}.
131 <                                                "/ConfigArea.dat");
55 >        @_?$self->{name}=shift
56 >          :$self->{name};
57   }
58  
59 < sub parentconfig {
59 > sub version {
60          my $self=shift;
61 <        @_?$self->{parentconfig}=shift
62 <          :$self->{parentconfig};
61 >        @_?$self->{version}=shift
62 >          :$self->{version};
63   }
64  
65 < sub store {
65 > sub setup {
66          my $self=shift;
67          my $location=shift;
68 <
69 <        my $fh=$self->openfile(">".$location);
70 <        $self->savevar($fh,"location", $self->location());
71 <        $self->savevar($fh,"url", $self->url());
72 <        $self->savevar($fh,"name", $self->name());
73 <        $self->savevar($fh,"version", $self->version());
74 <        $fh->close();
68 >        my $areaname=shift  || undef;
69 >        my $symlinks=shift  || 0;
70 >        my $locarea = shift || undef;
71 >        if ( (! defined $areaname) || ( $areaname eq "" ) ) {
72 >          $areaname=$self->version();
73 >        }
74 >        $self->location($location."/".$areaname);
75 >        $self->symlinks($symlinks);
76 >        if ($self->configchksum() ne "")
77 >           {
78 >           if ((!-defined $locarea) && (-f "${location}/${areaname}/".$self->admindir()."/Environment"))
79 >              {
80 >              $locarea=Configuration::ConfigArea->new($self->arch());
81 >              $locarea->bootstrapfromlocation("${location}/${areaname}");
82 >              }
83 >           if ((defined $locarea) && ($locarea->configchksum() != $self->configchksum()))
84 >              {
85 >              print "ERROR: Can not setup your current working area for SCRAM_ARCH:".$self->arch().".\n",
86 >                    "Your current development area ${location}/${areaname}\n",
87 >                    "is using a different ${areaname}/config then the one used for\n",
88 >                    $self->releasetop(),".\n";
89 >              exit 1;
90 >              }
91 >           }
92 >        Utilities::AddDir::adddir($self->archdir());
93   }
94  
95 < sub copy {
95 > sub configurationdir {
96          my $self=shift;
97 <        my $destination=shift;
98 <        use File::Basename;
99 <        # create the area
100 <
158 <        AddDir::adddir(dirname($destination));
159 <        
160 <        $temp=$self->location();
161 <        my @cpcmd=(qw(cp -r), "$temp", "$destination");
162 <        print "@cpcmd"."\n";
163 < #       File::Copy::copy("$self->location()", "$destination") or
164 <        system(@cpcmd) == 0 or
165 <                        $self->error("Cannot copy ".$self->location().
166 <                        " to $destination ".$!);
167 <
168 <        # create a new object based on the new area
169 <        my $newarea=ref($self)->new($self->parentconfig());
170 <        $newarea->bootstrapfromlocation($destination);
171 <        # save it with the new location info
172 <        $newarea->store($self->location()."/".$self->{admindir}."/ConfigArea.dat");
97 >        if ( @_ ) {
98 >          $self->{configurationdir}=shift;
99 >        }
100 >        return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
101   }
102  
103 < sub restore {
103 > sub sourcedir {
104          my $self=shift;
105 <        my $location=shift;
106 <
107 <        my $fh=$self->openfile("<".$location);
108 <        my $varhash={};
181 <        $self->restorevars($fh,$varhash);
182 <        if ( ! defined $self->location() ) {
183 <          $self->location($$varhash{"location"});
184 <        }
185 <        $self->_setupstore();
186 <        $self->url($$varhash{"url"});
187 <        $self->name($$varhash{"name"});
188 <        $self->version($$varhash{"version"});
189 <        $fh->close();
105 >        if ( @_ ) {
106 >          $self->{sourcedir}=shift;
107 >        }
108 >        return (defined $self->{sourcedir})?$self->{sourcedir}:undef;
109   }
110  
111 < sub name {
111 > sub releasetop {
112          my $self=shift;
113 <
114 <        @_?$self->{name}=shift
115 <          :$self->{name};
113 >        if ( @_ ) {
114 >          $self->{releasetop}=shift;
115 >        }
116 >        return (defined $self->{releasetop})?$self->{releasetop}:undef;
117   }
118  
119 < sub version {
120 <        my $self=shift;
119 > sub admindir()
120 >   {
121 >   my $self=shift;
122 >  
123 >   @_ ? $self->{admindir} = shift
124 >      : $self->{admindir};
125 >   }
126  
127 <        @_?$self->{version}=shift
128 <          :$self->{version};
127 > sub bootstrapfromlocation {
128 >        my $self=shift;
129 >        my $location = $self->searchlocation(shift);
130 >        my $rv=0;
131 >        if ( ! defined $location) {
132 >         $rv=1;
133 >        }
134 >        else {
135 >         $self->location($location);
136 >         $self->_LoadEnvFile();
137 >        }
138 >        return $rv;
139   }
140  
141   sub location {
# Line 208 | Line 143 | sub location {
143  
144          if ( @_ ) {
145            $self->{location}=shift;
146 +          $self->archname($self->{archname});
147          }
148          elsif ( ! defined $self->{location} ) {
149            # try and find the release location
150 <          #$self->{location}=$self->searchlocation();
150 >          $self->{location}=$self->searchlocation();
151 >          if (defined $self->{location})
152 >             {
153 >             $self->archname($self->{archname});
154 >             }
155          }
156          return  $self->{location};
157   }
158  
159   sub searchlocation {
160          my $self=shift;
161 <
161 >        
162          #start search in current directory if not specified
163          my $thispath;
164 <        @_?$thispath=shift
165 <          :$thispath=cwd();
166 <
164 >        if ( @_ ) {
165 >          $thispath=shift
166 >        }
167 >        else {
168 >          $thispath=cwd();
169 >        }
170 >        
171          my $rv=0;
172  
173 +        # chop off any files - we only want dirs
174 +        if ( -f $thispath ) {
175 +          $thispath=~s/(.*)\/.*/$1/;
176 +        }
177          Sloop:{
178          do {
179 < #         print "Searching $thispath\n";
179 >          $self->verbose("Searching $thispath");
180            if ( -e "$thispath/".$self->{admindir} ) {
181 < #           print "Found\n";
181 >            $self->verbose("Found\n");
182              $rv=1;
183              last Sloop;
184            }
185          } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
186 <
186 >      
187          return $rv?$thispath:undef;
188   }
189  
190 < sub meta {
190 > sub archname {
191          my $self=shift;
192 <
193 <        my $string=$self->name()." ".$self->version()." located at :\n  ".
194 <                $self->location;
192 >        if ( @_ ) {
193 >          $self->{archname}=shift;
194 >          if (defined $self->{location}) {
195 >             $self->archdir($self->{location}."/".$self->{admindir}."/".$self->{archname});
196 >          }
197 >        }
198 >        return $self->{archname};
199   }
200  
201 < sub configitem {
201 > sub archdir {
202          my $self=shift;
203 <        
204 <        return ($self->config()->find("ConfigItem",@_));
203 >        if ( @_ ) {
204 >          $self->{archdir}=shift;
205 >        }
206 >        return $self->{archdir};
207   }
208  
209 < sub addconfigitem {
209 > sub satellite {
210          my $self=shift;
211 <        my $url=shift;
212 <
213 <        my $docref=$self->activatedoc($url);
214 <        # Set up the document
215 <        $docref->setup();
216 <        $docref->save();
217 < #       $self->config()->storepolicy("local");
211 >        my $relloc = $self->location();
212 >        my $sat=Configuration::ConfigArea->new($self->arch());
213 >        $sat->name($self->name());
214 >        $sat->version($self->version());
215 >        $sat->configurationdir($self->configurationdir());
216 >        $sat->sourcedir($self->sourcedir());
217 >        $sat->releasetop($relloc);
218 >        $sat->configchksum($self->configchksum());
219 >        $sat->setup(@_);
220 >        $self->copywithskip($self->archdir(),$sat->archdir(),["InstalledTools","ProjectCache.db.gz","RuntimeCache.db.gz","DirCache.db.gz","MakeData/DirCache","MakeData/DirCache.mk","MakeData/src.mk"]);
221 >        $envfile = $sat->archdir()."/Environment";
222 >        open ( $fh, "> $envfile" ) or  $sat->error("Cannot Open \"$envfile\" file to Save\n $!");
223 >        print $fh "RELEASETOP=$relloc\n";
224 >        close($fh);
225 >        my $devconf = $sat->location()."/".$sat->configurationdir();
226 >        my $relconf = $self->location()."/".$self->configurationdir();
227 >        if (!-d $devconf)
228 >           {
229 >           $self->copywithskip($relconf,$devconf,['toolbox']);
230 >           }
231 >        $envfile = $sat->location()."/".$self->{admindir}."/Environment";
232 >        if (! -f $envfile)
233 >           {
234 >           $sat->save ();
235 >           }
236 >        Utilities::AddDir::copydir("${relconf}/toolbox/".$self->arch(),"${devconf}/toolbox/".$sat->arch());
237 >        Utilities::AddDir::adddir ($sat->location()."/".$sat->sourcedir());
238 >        return $sat;
239 > }
240 >
241 > sub copywithskip {
242 >        my $self=shift;
243 >        my $src=shift;
244 >        my $des=shift;
245 >        my $filetoskip=shift || [];
246 >        my $rv=1;
247 >        if ( $src ne $des )
248 >           {
249 >           if ( -d $src )
250 >              {
251 >              my $fs=[];
252 >              foreach my $f (@$filetoskip) {push @$fs,"${src}/${f}";}
253 >              Utilities::AddDir::copydirwithskip($src,$des,$fs);
254 >              $rv=0;
255 >             }
256 >           }
257 >        return $rv;
258   }
259  
260 < # -------------- Tags ---------------------------------
267 < # -- init parse
268 < sub Project_Start {
260 > sub copyenv {
261          my $self=shift;
270        my $name=shift;
262          my $hashref=shift;
263 <
264 <        $self->checktag($name,$hashref,'name');
265 <        $self->checktag($name,$hashref,'version');
266 <
276 <        $self->name($$hashref{'name'});
277 <        $self->version($$hashref{'version'});
263 >        
264 >        foreach $elem ( keys %{$self->{ENV}} ) {
265 >           $$hashref{$elem}=$self->{ENV}{$elem};
266 >        }
267   }
268  
269 <
281 < sub Project_text {
269 > sub arch {
270          my $self=shift;
271 <        my $name=shift;
284 <        my $string=shift;
285 <
286 <        print $string;
271 >        return $self->{archname};
272   }
273  
274 < # ---- download parse
290 <
291 < sub Use_download_Start {
274 > sub save {
275          my $self=shift;
276 <        my $name=shift;
294 <        my $hashref=shift;
295 <
296 <        $self->checktag($name,$hashref,'url');
297 <        print "Downloading .... ".$$hashref{'url'}."\n";
298 <        $self->getfile($$hashref{'url'});
276 >        $self->_SaveEnvFile();
277   }
278  
279 < # --- setup parse
279 > # ---- support routines
280  
281 < sub Use_Start {
282 <        my $self=shift;
283 <        my $name=shift;
284 <        my $hashref=shift;
281 > sub _SaveEnvFile
282 >   {
283 >   my $self=shift;
284 >  
285 >   my $fh;
286 >   my $envfile = $self->location()."/".$self->{admindir}."/Environment";
287 >   open ( $fh, "> $envfile" ) or  $self->error("Cannot Open \"$envfile\" file to Save\n $!");
288          
289 <        $self->checktag($name,$hashref,'url');
290 <        $self->addconfigitem($$hashref{'url'});
291 < }
292 <
289 >   print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
290 >   print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
291 >   print $fh "SCRAM_CONFIGDIR=".$self->configurationdir()."\n";
292 >   print $fh "SCRAM_SOURCEDIR=".$self->sourcedir()."\n";
293 >   print $fh "SCRAM_SYMLINKS=",$self->symlinks(),"\n";
294 >   print $fh "SCRAM_CONFIGCHKSUM=",$self->configchksum(),"\n";
295 >   close($fh);
296 >
297 >   # Set the default permissions (-rw-r--r--):
298 >   my $filemode = 0644;
299 >   chmod $filemode, $self->location()."/".$self->{admindir}."/Environment";
300 >   }
301 >
302 > sub _LoadEnvFile
303 >   {
304 >   my $self=shift;
305 >
306 >   my $fh;
307 >   my $envfile = $self->location()."/".$self->{admindir}."/Environment";
308 >   open ( $fh, "< $envfile" ) or $self->error("Cannot open \"$envfile\" file for reading.\n $!");
309 >   while ( <$fh> )
310 >      {
311 >      chomp;
312 >      next if /^#/;
313 >      next if /^\s*$/ ;
314 >      ($name, $value)=split /=/;
315 >      eval "\$self->{ENV}{${name}}=\"$value\"";
316 >      }
317 >   close($fh);
318 >   $envfile = $self->archdir()."/Environment";
319 >   if (-f $envfile)
320 >      {
321 >      open ( $fh, "< $envfile" ) or $self->error("Cannot open \"$envfile\" file for reading.\n $!");
322 >      while ( <$fh> )
323 >         {
324 >         chomp;
325 >         next if /^#/;
326 >         next if /^\s*$/ ;
327 >         ($name, $value)=split /=/;
328 >         eval "\$self->{ENV}{${name}}=\"$value\"";
329 >         }
330 >      close($fh);
331 >      }
332 >        
333 >   # -- set internal variables appropriately
334 >   if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} )
335 >      {
336 >      $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
337 >      }
338 >   if ( defined $self->{ENV}{"SCRAM_SYMLINKS"} )
339 >      {
340 >      $self->symlinks($self->{ENV}{"SCRAM_SYMLINKS"});
341 >      }
342 >   if ( defined $self->{ENV}{"SCRAM_CONFIGCHKSUM"} )
343 >      {
344 >      $self->configchksum($self->{ENV}{"SCRAM_CONFIGCHKSUM"});
345 >      }
346 >   if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} )
347 >      {
348 >      $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
349 >      }
350 >   if ( defined $self->{ENV}{"SCRAM_CONFIGDIR"} )
351 >      {
352 >      $self->configurationdir($self->{ENV}{"SCRAM_CONFIGDIR"});
353 >      }
354 >   if ( defined $self->{ENV}{"SCRAM_SOURCEDIR"} )
355 >      {
356 >      $self->sourcedir($self->{ENV}{"SCRAM_SOURCEDIR"});
357 >      }
358 >   if ( defined $self->{ENV}{"RELEASETOP"} )
359 >      {
360 >      $self->releasetop($self->{ENV}{"RELEASETOP"});
361 >      }
362 >   }
363 > 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines