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.6 by williamc, Thu Jan 27 17:50:55 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 Cwd;
37   @ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject);
38  
39   sub init {
40          my $self=shift;
41 +
42          $self->newparse("init");
43          $self->newparse("download");
44          $self->newparse("setup");
# Line 41 | Line 51 | sub init {
51          $self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self);
52   }
53  
54 + sub defaultdirname {
55 +        my $self=shift;
56 +        my $name=$self->name();
57 +        my $vers=$self->version();
58 +        $vers=~s/^$name_//;
59 +        $name=$name."_".$vers;
60 +        return $name;
61 +        
62 + }
63 +
64   sub setup {
65          my $self=shift;
66  
67          # --- find out the location
68          my $location=$self->requestoption("area_location",
69                  "Please Enter the location of the directory");
70 +        if ( $location!~/^\// ) {
71 +                $location=cwd()."/".$location;
72 +        }
73  
74          # --- find area directory name , default name projectname_version
75          my $name=$self->option("area_name");
53        my $vers=$self->version;
76          if ( ! defined $name ) {
77 <          $name=$self->name();
56 <          $vers=~s/^$name_//;
57 <          $name=$name."_".$vers;
77 >          $name=$self->defaultdirname();
78          }
79          $self->location($location."/".$name);
80  
# Line 68 | Line 88 | sub setup {
88          # --- and parse the setup file
89          $self->parse("setup");
90          
91 +        # --- store bootstrap info
92 +        $self->store($self->location()."/.SCRAM/ConfigArea.dat");
93 +
94          # --- store self in original database
95          $self->parentconfig()->store($self,"ConfigArea",$self->name(),
96                                                          $self->version());
# Line 88 | Line 111 | sub _setupstore {
111          $self->config()->basedoc($self->parentconfig()->basedoc());
112   }
113  
114 + sub bootstrapfromlocation {
115 +        my $self=shift;
116 +        
117 +        if ( ! defined $self->location(@_) ) {
118 +          $self->error("Unable to locate the top of local configuration area");
119 +        }
120 +        print "Found top ".$self->location()."\n";
121 +        $self->_setupstore();
122 +        $self->restore($self->location()."/.SCRAM/ConfigArea.dat");
123 + }
124 +
125   sub parentconfig {
126          my $self=shift;
127          @_?$self->{parentconfig}=shift
# Line 106 | Line 140 | sub store {
140          $fh->close();
141   }
142  
143 + sub copy {
144 +        my $self=shift;
145 +        my $destination=shift;
146 +        use File::Basename;
147 +        # create the area
148 +
149 +        AddDir::adddir(dirname($destination));
150 +        
151 +        my @cpcmd=(qw(cp -r), "$self->location()", "$destination");
152 +        print "@cpcmd";
153 + #       File::Copy::copy("$self->location()", "$destination") or
154 +        system(@cpcmd) or
155 +                        $self->error("Cannot copy ".$self->location().
156 +                        " to $destination ".$!);
157 +
158 +        # create a new object based on the new area
159 +        my $newarea=ref($self)->new($self->parentconfig());
160 +        $newarea->bootstrapfromlocation($destination);
161 +        # save it with the new location info
162 +        $newarea->store($self->location()."/.SCRAM/ConfigArea.dat");
163 + }
164 +
165   sub restore {
166          my $self=shift;
167          my $location=shift;
# Line 113 | Line 169 | sub restore {
169          my $fh=$self->openfile("<".$location);
170          my $varhash={};
171          $self->restorevars($fh,$varhash);
172 <        $self->location($$varhash{"location"});
172 >        if ( ! defined $self->location() ) {
173 >          $self->location($$varhash{"location"});
174 >        }
175          $self->_setupstore();
176          $self->url($$varhash{"url"});
177          $self->name($$varhash{"name"});
# Line 138 | Line 196 | sub version {
196   sub location {
197          my $self=shift;
198  
199 <        @_?$self->{location}=shift
200 <          :$self->{location};
199 >        if ( @_ ) {
200 >          $self->{location}=shift;
201 >        }
202 >        elsif ( ! defined $self->{location} ) {
203 >          # try and find the release location
204 >          $self->{location}=$self->searchlocation();
205 >        }
206 >        return  $self->{location};
207 > }
208 >
209 > sub searchlocation {
210 >        my $self=shift;
211 >
212 >        #start search in current directory if not specified
213 >        my $thispath;
214 >        @_?$thispath=shift
215 >          :$thispath=cwd();
216 >
217 >        my $rv=0;
218 >
219 >        Sloop:{
220 >        do {
221 > #         print "Searching $thispath\n";
222 >          if ( -e "$thispath/.SCRAM" ) {
223 > #           print "Found\n";
224 >            $rv=1;
225 >            last Sloop;
226 >          }
227 >        } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
228 >
229 >        return $rv?$thispath:undef;
230   }
231  
232   sub meta {
# Line 151 | Line 238 | sub meta {
238  
239   sub configitem {
240          my $self=shift;
154        my $location=shift;
241          
242 <        $self->config()->find("ConfigItem",@_);
242 >        return ($self->config()->find("ConfigItem",@_));
243   }
244  
245   sub addconfigitem {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines