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.1 by williamc, Thu Jan 20 18:21:54 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
1   package Configuration::ConfigArea;
23 use ActiveDoc::ActiveDoc;
2   require 5.004;
3   use Utilities::AddDir;
4 < use ObjectUtilities::ObjectStore;
5 < @ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject);
4 > use Utilities::Verbose;
5 > use Cwd;
6 > @ISA=qw(Utilities::Verbose);
7 >
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 < sub init {
46 > sub configchksum {
47          my $self=shift;
48 <        $self->newparse("init");
49 <        $self->newparse("download");
33 <        $self->newparse("setup");
34 <        $self->addtag("init","project",\&Project_Start,$self,
35 <        \&Project_text,$self,"", $self );
36 <        $self->addurltags("download");
37 <        $self->addtag("download","use",\&Use_download_Start,$self,
38 <                                                "", $self, "",$self);
39 <        $self->addurltags("setup");
40 <        $self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self);
48 >        if (@_) {$self->{configchksum}=shift;}
49 >        return $self->{configchksum};
50   }
51  
52 < sub setup {
52 >
53 > sub name {
54          my $self=shift;
55 +        @_?$self->{name}=shift
56 +          :$self->{name};
57 + }
58  
59 <        # --- find out the location
60 <        my $location=$self->requestoption("area_location",
61 <                "Please Enter the location of the directory");
62 <
50 <        # --- find area directory name , default name projectname_version
51 <        my $name=$self->option("area_name");
52 <        my $vers=$self->version;
53 <        if ( ! defined $name ) {
54 <          $name=$self->name();
55 <          $vers=~s/^$name_//;
56 <          $name=$name."_".$vers;
57 <        }
58 <        $self->location($location."/".$name);
59 <
60 <        # --- make a new ActiveStore at the location and add it to the db list
61 <        my $ad=ActiveDoc::ActiveConfig->new($self->location()."/\.SCRAM");
62 <
63 <        # make a new store handler
64 <        my $parentconfig=$self->config;
65 <        $self->config(Configuration::ConfigureStore);
66 <        $self->config()->db("local",$ad);
67 <        $self->config()->db("parent",$parentconfig);
68 <        $self->config()->policy("cache","local");
69 <        $self->config()->basedoc($parentconfig->basedoc());
70 <
71 <        # --- download everything first
72 < # FIX-ME --- cacheing is broken
73 < #       $self->parse("download");
74 <        
75 <        # --- and parse the setup file
76 <        $self->parse("setup");
59 > sub version {
60 >        my $self=shift;
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 <        print $fh $self->location()."\n";
71 <        $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 restore {
95 > sub configurationdir {
96          my $self=shift;
97 <
98 <        my $fh=$self->openfile("<".$location);
99 <        $self->{location}=<$fh>;
100 <        chomp $self->{location};
94 <        $fh->close();
95 <
97 >        if ( @_ ) {
98 >          $self->{configurationdir}=shift;
99 >        }
100 >        return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
101   }
102  
103 < sub name {
103 > sub sourcedir {
104          my $self=shift;
105 <
106 <        @_?$self->{name}=shift
107 <          :$self->{name};
105 >        if ( @_ ) {
106 >          $self->{sourcedir}=shift;
107 >        }
108 >        return (defined $self->{sourcedir})?$self->{sourcedir}:undef;
109   }
110  
111 < sub version {
111 > sub releasetop {
112          my $self=shift;
113 +        if ( @_ ) {
114 +          $self->{releasetop}=shift;
115 +        }
116 +        return (defined $self->{releasetop})?$self->{releasetop}:undef;
117 + }
118  
119 <        @_?$self->{version}=shift
120 <          :$self->{version};
119 > sub admindir()
120 >   {
121 >   my $self=shift;
122 >  
123 >   @_ ? $self->{admindir} = shift
124 >      : $self->{admindir};
125 >   }
126 >
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 {
142          my $self=shift;
143  
144 <        @_?$self->{location}=shift
145 <          :$self->{location};
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();
151 >          if (defined $self->{location})
152 >             {
153 >             $self->archname($self->{archname});
154 >             }
155 >        }
156 >        return  $self->{location};
157   }
158  
159 < sub meta {
159 > sub searchlocation {
160          my $self=shift;
161 +        
162 +        #start search in current directory if not specified
163 +        my $thispath;
164 +        if ( @_ ) {
165 +          $thispath=shift
166 +        }
167 +        else {
168 +          $thispath=cwd();
169 +        }
170 +        
171 +        my $rv=0;
172  
173 <        my $string=$self->name()." ".$self->version()." located at :\n  ".
174 <                $self->location;
173 >        # chop off any files - we only want dirs
174 >        if ( -f $thispath ) {
175 >          $thispath=~s/(.*)\/.*/$1/;
176 >        }
177 >        Sloop:{
178 >        do {
179 >          $self->verbose("Searching $thispath");
180 >          if ( -e "$thispath/".$self->{admindir} ) {
181 >            $self->verbose("Found\n");
182 >            $rv=1;
183 >            last Sloop;
184 >          }
185 >        } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
186 >      
187 >        return $rv?$thispath:undef;
188 > }
189 >
190 > sub archname {
191 >        my $self=shift;
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 <        my $location=shift;
204 <        
205 <        $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 <        $self->config()->savepolicy("local");
217 <        $docref->save();
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 ---------------------------------
145 < # -- init parse
146 < sub Project_Start {
260 > sub copyenv {
261          my $self=shift;
148        my $name=shift;
262          my $hashref=shift;
263 <
264 <        $self->checktag($name,$hashref,'name');
265 <        $self->checktag($name,$hashref,'version');
266 <
154 <        $self->name($$hashref{'name'});
155 <        $self->version($$hashref{'version'});
263 >        
264 >        foreach $elem ( keys %{$self->{ENV}} ) {
265 >           $$hashref{$elem}=$self->{ENV}{$elem};
266 >        }
267   }
268  
269 <
159 < sub Project_text {
269 > sub arch {
270          my $self=shift;
271 <        my $name=shift;
162 <        my $string=shift;
163 <
164 <        print $string;
271 >        return $self->{archname};
272   }
273  
274 < # ---- download parse
168 <
169 < sub Use_download_Start {
274 > sub save {
275          my $self=shift;
276 <        my $name=shift;
172 <        my $hashref=shift;
173 <
174 <        $self->checktag($name,$hashref,'url');
175 <        print "Downloading .... ".$$hashref{'url'}."\n";
176 <        $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