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.13.2.6 by williamc, Tue May 16 14:03:02 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 + # Options
11 + # -------
12 + # ConfigArea_location
13 + # ConfigArea_name
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
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
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 - return an object
28 < #                                 representing the area
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 > # - temporary
36 > # align()                       : adjust hard paths to suit local loaction
37  
38   package Configuration::ConfigArea;
32 use ActiveDoc::ActiveDoc;
39   require 5.004;
40   use Utilities::AddDir;
41 < use ObjectUtilities::ObjectStore;
36 < use Configuration::ConfigStore;
41 > use Utilities::Verbose;
42   use Cwd;
43 < @ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject);
39 <
40 < sub init {
41 <        my $self=shift;
43 > @ISA=qw(Utilities::Verbose);
44  
45 <        $self->newparse("init");
46 <        $self->newparse("download");
47 <        $self->newparse("setup");
48 <        $self->addtag("init","project",\&Project_Start,$self,
47 <            \&Project_text,$self,"", $self );
48 <        $self->addurltags("download");
49 <        $self->addtag("download","use",\&Use_download_Start,$self,
50 <                                                "", $self, "",$self);
51 <        $self->addurltags("setup");
52 <        $self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self);
45 > sub new {
46 >        my $class=shift;
47 >        my $self={};
48 >        bless $self, $class;
49  
50          # data init
51 <        $self->{admindir}=".SCRAM";
56 < }
57 <
58 <
59 < sub defaultdirname {
60 <        my $self=shift;
61 <        my $name=$self->name();
62 <        my $vers=$self->version();
63 <        $vers=~s/^$name_//;
64 <        $name=$name."_".$vers;
65 <        return $name;
51 >        $self->{admindir}=".SCRAM";
52  
53 +        return $self;
54   }
55  
56 < sub setup {
56 > sub configurationdir {
57          my $self=shift;
58 <
59 <        # --- 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;
58 >        if ( @_ ) {
59 >          $self->{configurationdir}=shift;
60          }
61 <
62 <        # --- find area directory name , default name projectname_version
63 <        my $name=$self->option("area_name");
83 <        if ( ! defined $name ) {
84 <          $name=$self->defaultdirname();
61 >        if ( ! defined $self->{configurationdir} ) {
62 >          $self->_LoadEnvFile();
63 >          $self->{configurationdir}=$self->{ENV}{projconfigdir};
64          }
65 <        $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());
65 >        return $self->{configurationdir};
66   }
67  
68 < sub _setupstore {
68 > sub toolbox {
69          my $self=shift;
70 <
71 <        # --- 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});
112 <
113 <        $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 {
123 <        my $self=shift;
124 <        
125 <        if ( ! defined $self->location(@_) ) {
126 <          $self->error("Unable to locate the top of local configuration area");
70 >        if ( ! defined $self->{toolbox} ) {
71 >          $self->{toolbox}=BuildSystem::ToolBox->new($self);
72          }
73 <        print "Found top ".$self->location()."\n";
129 <        $self->_setupstore();
130 <        $self->restore($self->location()."/".$self->{admindir}.
131 <                                                "/ConfigArea.dat");
73 >        return $self->{toolbox};
74   }
75  
76 < sub parentconfig {
76 > sub requirementsdoc {
77          my $self=shift;
78 <        @_?$self->{parentconfig}=shift
79 <          :$self->{parentconfig};
80 < }
81 <
82 < sub store {
83 <        my $self=shift;
84 <        my $location=shift;
85 <
86 <        my $fh=$self->openfile(">".$location);
87 <        $self->savevar($fh,"location", $self->location());
88 <        $self->savevar($fh,"url", $self->url());
89 <        $self->savevar($fh,"name", $self->name());
90 <        $self->savevar($fh,"version", $self->version());
91 <        $fh->close();
78 >        if ( @_ ) {
79 >          $self->{reqdoc}=shift;
80 >        }
81 >        if ( ! defined $self->{reqdoc} ) {
82 >          $self->_LoadEnvFile();
83 >          $self->{reqdoc}=$self->{ENV}{SCRAM_ProjReqsDoc};
84 >        }
85 >        return $self->{reqdoc};
86 > }
87 >
88 > sub scramversion {
89 >        my $self=shift;
90 >        if ( ! defined $self->{scramversion} ) {
91 >          my $filename=$self->location()."/".$self->configurationdir()."/".
92 >                                                        "scram_version";
93 >          if ( -f $filename ) {
94 >            use FileHandle;
95 >            $fh=FileHandle->new();
96 >            open ($fh, "<".$filename);
97 >            my $version=<$fh>;
98 >            chomp $version;
99 >            $self->{scramversion}=$version;
100 >            undef $fh;
101 >          }
102 >        }
103 >        return $self->{scramversion};
104   }
105  
106 < sub copy {
106 > sub bootstrapfromlocation {
107          my $self=shift;
154        my $destination=shift;
155        use File::Basename;
156        # create the area
108  
109 <        AddDir::adddir(dirname($destination));
109 >        my $rv=0;
110          
111 <        $temp=$self->location();
112 <        my @cpcmd=(qw(cp -r), "$temp", "$destination");
113 <        print "@cpcmd"."\n";
114 < #       File::Copy::copy("$self->location()", "$destination") or
115 <        system(@cpcmd) == 0 or
116 <                        $self->error("Cannot copy ".$self->location().
117 <                        " to $destination ".$!);
118 <
119 <        # create a new object based on the new area
120 <        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");
173 < }
174 <
175 < sub restore {
176 <        my $self=shift;
177 <        my $location=shift;
178 <
179 <        my $fh=$self->openfile("<".$location);
180 <        my $varhash={};
181 <        $self->restorevars($fh,$varhash);
182 <        if ( ! defined $self->location() ) {
183 <          $self->location($$varhash{"location"});
111 >        my $location;
112 >        if ( ! defined ($location=$self->searchlocation(@_)) ) {
113 >         $rv=1;
114 >         $self->verbose("Unable to locate the top of local configuration area");
115 >        }
116 >        else {
117 >         $self->location($location);
118 >         $self->verbose("Found top ".$self->location());
119 >         my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat";
120 >         $self->_LoadEnvFile();
121          }
122 <        $self->_setupstore();
186 <        $self->url($$varhash{"url"});
187 <        $self->name($$varhash{"name"});
188 <        $self->version($$varhash{"version"});
189 <        $fh->close();
190 < }
191 <
192 < sub name {
193 <        my $self=shift;
194 <
195 <        @_?$self->{name}=shift
196 <          :$self->{name};
197 < }
198 <
199 < sub version {
200 <        my $self=shift;
201 <
202 <        @_?$self->{version}=shift
203 <          :$self->{version};
122 >        return $rv;
123   }
124  
125   sub location {
# Line 211 | Line 130 | sub location {
130          }
131          elsif ( ! defined $self->{location} ) {
132            # try and find the release location
133 <          #$self->{location}=$self->searchlocation();
133 >          $self->{location}=$self->searchlocation();
134          }
135          return  $self->{location};
136   }
# Line 221 | Line 140 | sub searchlocation {
140  
141          #start search in current directory if not specified
142          my $thispath;
143 <        @_?$thispath=shift
144 <          :$thispath=cwd();
143 >        if ( @_ ) {
144 >          $thispath=shift
145 >        }
146 >        else {
147 >          $thispath=cwd();
148 >        }
149  
150          my $rv=0;
151  
152 +        # chop off any files - we only want dirs
153 +        if ( -f $thispath ) {
154 +          $thispath=~s/(.*)\/.*/$1/;
155 +        }
156          Sloop:{
157          do {
158 < #         print "Searching $thispath\n";
158 >          $self->verbose("Searching $thispath");
159            if ( -e "$thispath/".$self->{admindir} ) {
160 < #           print "Found\n";
160 >            $self->verbose("Found\n");
161              $rv=1;
162              last Sloop;
163            }
# Line 239 | Line 166 | sub searchlocation {
166          return $rv?$thispath:undef;
167   }
168  
169 < sub meta {
169 > sub copy {
170          my $self=shift;
171 +        my $destination=shift;
172  
173 <        my $string=$self->name()." ".$self->version()." located at :\n  ".
174 <                $self->location;
173 >        # copy across the admin dir
174 >        my $temp=$self->location()."/".$self->{admindir};
175 >        AddDir::copydir($temp,"$destination/".$self->{admindir});
176   }
177  
178 < sub configitem {
178 > sub align {
179          my $self=shift;
180 <        
252 <        return ($self->config()->find("ConfigItem",@_));
253 < }
180 >        use File::Copy;
181  
182 < sub addconfigitem {
183 <        my $self=shift;
184 <        my $url=shift;
182 >        $self->_LoadEnvFile();
183 >        my $Envfile=$self->location()."/".$self->{admindir}."/Environment";
184 >        my $tmpEnvfile=$Envfile.".bak";
185 >        my $rel=$self->{ENV}{RELEASETOP};
186 >        my $local=$self->location();
187  
188 <        my $docref=$self->activatedoc($url);
189 <        # Set up the document
190 <        $docref->setup();
191 <        $docref->save();
192 < #       $self->config()->storepolicy("local");
188 >        rename( $Envfile, $tmpEnvfile );
189 >        use FileHandle;
190 >        my $fh=FileHandle->new();
191 >        my $fout=FileHandle->new();
192 >        open ( $fh, "<".$tmpEnvfile ) or
193 >                $self->error("Cannot find Environment file. Area Corrupted? ("
194 >                                .$self->location().")\n $!");
195 >        open ( $fout, ">".$Envfile ) or
196 >                $self->error("Cannot find Environment file. Area Corrupted? ("
197 >                                .$self->location().")\n $!");
198 >        while ( <$fh> ) {
199 >          $_=~s/\Q$rel\L/$local/g;
200 >          print $fout $_;
201 >        }
202 >        undef $fh;
203 >        undef $fout;
204   }
205  
206 < # -------------- Tags ---------------------------------
267 < # -- init parse
268 < sub Project_Start {
206 > sub copysetup {
207          my $self=shift;
208 <        my $name=shift;
271 <        my $hashref=shift;
272 <
273 <        $self->checktag($name,$hashref,'name');
274 <        $self->checktag($name,$hashref,'version');
208 >        my $dest=shift;
209  
210 <        $self->name($$hashref{'name'});
211 <        $self->version($$hashref{'version'});
210 >        my $rv=1;
211 >        # copy across the admin dir
212 >        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
213 >        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
214 >        if ( $temp ne $temp2 ) {
215 >         if ( -d $temp ) {
216 >          AddDir::copydir($temp,$temp2);
217 >          $rv=0;
218 >         }
219 >        }
220 >        return $rv;
221   }
222  
223 <
281 < sub Project_text {
223 > sub copyenv {
224          my $self=shift;
225 <        my $name=shift;
226 <        my $string=shift;
227 <
228 <        print $string;
225 >        my $hashref=shift;
226 >        
227 >        foreach $elem ( keys %{$self->{ENV}} ) {
228 >           $$hashref{$elem}=$self->{ENV}{$elem};
229 >        }
230   }
231  
232 < # ---- download parse
290 <
291 < sub Use_download_Start {
232 > sub arch {
233          my $self=shift;
234 <        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'});
234 >        return $ENV{SCRAM_ARCH};
235   }
236  
237 < # --- setup parse
238 <
303 < sub Use_Start {
237 > # ---- support routines
238 > sub _LoadEnvFile {
239          my $self=shift;
305        my $name=shift;
306        my $hashref=shift;
307        
308        $self->checktag($name,$hashref,'url');
309        $self->addconfigitem($$hashref{'url'});
310 }
240  
241 +        use FileHandle;
242 +        my $fh=FileHandle->new();
243 +        open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
244 +                "Environment" ) or
245 +                $self->error("Cannot find Environment file. Area Corrupted? ("
246 +                                .$self->location().")\n $!");
247 +        while ( <$fh> ) {
248 +           chomp;
249 +           next if /^#/;
250 +           next if /^\s*$/ ;
251 +           ($name, $value)=split /=/;
252 +           eval "\$self->{ENV}{${name}}=\"$value\"";
253 +        }
254 +        undef $fh;
255 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines