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.7 by williamc, Wed Feb 9 08:16:15 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 + # linkarea(oref)                : link area with another
31  
32   package Configuration::ConfigArea;
33   use ActiveDoc::ActiveDoc;
34   require 5.004;
35   use Utilities::AddDir;
36   use ObjectUtilities::ObjectStore;
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);
# Line 41 | Line 52 | sub init {
52          $self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self);
53   }
54  
55 +
56 + sub defaultdirname {
57 +        my $self=shift;
58 +        my $name=$self->name();
59 +        my $vers=$self->version();
60 +        $vers=~s/^$name_//;
61 +        $name=$name."_".$vers;
62 +        return $name;
63 +        
64 + }
65 +
66   sub setup {
67          my $self=shift;
68  
69 <        # --- find out the location
70 <        my $location=$self->requestoption("area_location",
71 <                "Please Enter the location of the directory");
69 >        # --- find out the location - default is cwd
70 >        my $location=$self->option("area_location");
71 >        if ( ! defined $location ) {
72 >                $location=cwd();
73 >        }
74 >        elsif ( $location!~/^\// ) {
75 >                $location=cwd()."/".$location;
76 >        }
77  
78          # --- find area directory name , default name projectname_version
79          my $name=$self->option("area_name");
53        my $vers=$self->version;
80          if ( ! defined $name ) {
81 <          $name=$self->name();
56 <          $vers=~s/^$name_//;
57 <          $name=$name."_".$vers;
81 >          $name=$self->defaultdirname();
82          }
83          $self->location($location."/".$name);
84  
# Line 68 | Line 92 | sub setup {
92          # --- and parse the setup file
93          $self->parse("setup");
94          
95 +        # --- store bootstrap info
96 +        $self->store($self->location()."/.SCRAM/ConfigArea.dat");
97 +
98          # --- store self in original database
99          $self->parentconfig()->store($self,"ConfigArea",$self->name(),
100                                                          $self->version());
# Line 88 | Line 115 | sub _setupstore {
115          $self->config()->basedoc($self->parentconfig()->basedoc());
116   }
117  
118 + sub bootstrapfromlocation {
119 +        my $self=shift;
120 +        
121 +        if ( ! defined $self->location(@_) ) {
122 +          $self->error("Unable to locate the top of local configuration area");
123 +        }
124 +        print "Found top ".$self->location()."\n";
125 +        $self->_setupstore();
126 +        $self->restore($self->location()."/.SCRAM/ConfigArea.dat");
127 + }
128 +
129   sub parentconfig {
130          my $self=shift;
131          @_?$self->{parentconfig}=shift
# Line 106 | Line 144 | sub store {
144          $fh->close();
145   }
146  
147 + sub copy {
148 +        my $self=shift;
149 +        my $destination=shift;
150 +        use File::Basename;
151 +        # create the area
152 +
153 +        AddDir::adddir(dirname($destination));
154 +        
155 +        $temp=$self->location();
156 +        my @cpcmd=(qw(cp -r), "$temp", "$destination");
157 +        print "@cpcmd"."\n";
158 + #       File::Copy::copy("$self->location()", "$destination") or
159 +        system(@cpcmd) == 0 or
160 +                        $self->error("Cannot copy ".$self->location().
161 +                        " to $destination ".$!);
162 +
163 +        # create a new object based on the new area
164 +        my $newarea=ref($self)->new($self->parentconfig());
165 +        $newarea->bootstrapfromlocation($destination);
166 +        # save it with the new location info
167 +        $newarea->store($self->location()."/.SCRAM/ConfigArea.dat");
168 + }
169 +
170   sub restore {
171          my $self=shift;
172          my $location=shift;
# Line 113 | Line 174 | sub restore {
174          my $fh=$self->openfile("<".$location);
175          my $varhash={};
176          $self->restorevars($fh,$varhash);
177 <        $self->location($$varhash{"location"});
177 >        if ( ! defined $self->location() ) {
178 >          $self->location($$varhash{"location"});
179 >        }
180          $self->_setupstore();
181          $self->url($$varhash{"url"});
182          $self->name($$varhash{"name"});
# Line 138 | Line 201 | sub version {
201   sub location {
202          my $self=shift;
203  
204 <        @_?$self->{location}=shift
205 <          :$self->{location};
204 >        if ( @_ ) {
205 >          $self->{location}=shift;
206 >        }
207 >        elsif ( ! defined $self->{location} ) {
208 >          # try and find the release location
209 >          $self->{location}=$self->searchlocation();
210 >        }
211 >        return  $self->{location};
212 > }
213 >
214 > sub searchlocation {
215 >        my $self=shift;
216 >
217 >        #start search in current directory if not specified
218 >        my $thispath;
219 >        @_?$thispath=shift
220 >          :$thispath=cwd();
221 >
222 >        my $rv=0;
223 >
224 >        Sloop:{
225 >        do {
226 > #         print "Searching $thispath\n";
227 >          if ( -e "$thispath/.SCRAM" ) {
228 > #           print "Found\n";
229 >            $rv=1;
230 >            last Sloop;
231 >          }
232 >        } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
233 >
234 >        return $rv?$thispath:undef;
235   }
236  
237   sub meta {
# Line 151 | Line 243 | sub meta {
243  
244   sub configitem {
245          my $self=shift;
154        my $location=shift;
246          
247 <        $self->config()->find("ConfigItem",@_);
247 >        return ($self->config()->find("ConfigItem",@_));
248   }
249  
250   sub addconfigitem {
# Line 164 | Line 255 | sub addconfigitem {
255          # Set up the document
256          $docref->setup();
257   #       $self->config()->storepolicy("local");
167        $docref->save();
258   }
259  
260   # -------------- Tags ---------------------------------

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines