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.8 by williamc, Thu Feb 10 10:59:44 2000 UTC

# Line 19 | Line 19
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  
31   package Configuration::ConfigArea;
32   use ActiveDoc::ActiveDoc;
33   require 5.004;
34   use Utilities::AddDir;
35   use ObjectUtilities::ObjectStore;
36 + use Configuration::ConfigStore;
37 + use Cwd;
38   @ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject);
39  
40   sub init {
41          my $self=shift;
42 +
43          $self->newparse("init");
44          $self->newparse("download");
45          $self->newparse("setup");
46          $self->addtag("init","project",\&Project_Start,$self,
47 <        \&Project_text,$self,"", $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);
53 +
54 +        # data init
55 +        $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;
66 +
67   }
68  
69   sub setup {
70          my $self=shift;
71  
72 <        # --- find out the location
73 <        my $location=$self->requestoption("area_location",
74 <                "Please Enter the location of the directory");
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");
53        my $vers=$self->version;
83          if ( ! defined $name ) {
84 <          $name=$self->name();
56 <          $vers=~s/^$name_//;
57 <          $name=$name."_".$vers;
84 >          $name=$self->defaultdirname();
85          }
86          $self->location($location."/".$name);
87  
# Line 68 | Line 95 | sub setup {
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());
# Line 76 | Line 106 | sub setup {
106   sub _setupstore {
107          my $self=shift;
108  
109 <        # --- make a new ActiveStore at the location and add it to the db list
110 <        my $ad=ActiveDoc::ActiveConfig->new($self->location()."/\.SCRAM");
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});
112  
113          $self->parentconfig($self->config());
114   #        $self->config(Configuration::ConfigureStore->new());
# Line 88 | Line 119 | sub _setupstore {
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");
127 +        }
128 +        print "Found top ".$self->location()."\n";
129 +        $self->_setupstore();
130 +        $self->restore($self->location()."/".$self->{admindir}.
131 +                                                "/ConfigArea.dat");
132 + }
133 +
134   sub parentconfig {
135          my $self=shift;
136          @_?$self->{parentconfig}=shift
# Line 106 | Line 149 | sub store {
149          $fh->close();
150   }
151  
152 + sub copy {
153 +        my $self=shift;
154 +        my $destination=shift;
155 +        use File::Basename;
156 +        # create the area
157 +
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");
173 + }
174 +
175   sub restore {
176          my $self=shift;
177          my $location=shift;
# Line 113 | Line 179 | sub restore {
179          my $fh=$self->openfile("<".$location);
180          my $varhash={};
181          $self->restorevars($fh,$varhash);
182 <        $self->location($$varhash{"location"});
182 >        if ( ! defined $self->location() ) {
183 >          $self->location($$varhash{"location"});
184 >        }
185          $self->_setupstore();
186          $self->url($$varhash{"url"});
187          $self->name($$varhash{"name"});
# Line 138 | Line 206 | sub version {
206   sub location {
207          my $self=shift;
208  
209 <        @_?$self->{location}=shift
210 <          :$self->{location};
209 >        if ( @_ ) {
210 >          $self->{location}=shift;
211 >        }
212 >        elsif ( ! defined $self->{location} ) {
213 >          # try and find the release location
214 >          #$self->{location}=$self->searchlocation();
215 >        }
216 >        return  $self->{location};
217 > }
218 >
219 > sub searchlocation {
220 >        my $self=shift;
221 >
222 >        #start search in current directory if not specified
223 >        my $thispath;
224 >        @_?$thispath=shift
225 >          :$thispath=cwd();
226 >
227 >        my $rv=0;
228 >
229 >        Sloop:{
230 >        do {
231 > #         print "Searching $thispath\n";
232 >          if ( -e "$thispath/".$self->{admindir} ) {
233 > #           print "Found\n";
234 >            $rv=1;
235 >            last Sloop;
236 >          }
237 >        } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
238 >
239 >        return $rv?$thispath:undef;
240   }
241  
242   sub meta {
# Line 151 | Line 248 | sub meta {
248  
249   sub configitem {
250          my $self=shift;
154        my $location=shift;
251          
252 <        $self->config()->find("ConfigItem",@_);
252 >        return ($self->config()->find("ConfigItem",@_));
253   }
254  
255   sub addconfigitem {
# Line 163 | Line 259 | sub addconfigitem {
259          my $docref=$self->activatedoc($url);
260          # Set up the document
261          $docref->setup();
262 +        $docref->save();
263   #       $self->config()->storepolicy("local");
167        $docref->save();
264   }
265  
266   # -------------- Tags ---------------------------------

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines