ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Configuration/ConfigArea.pm
Revision: 1.13.2.3
Committed: Fri Apr 28 12:36:29 2000 UTC (25 years ago) by williamc
Content type: text/plain
Branch: V0_9branch
Changes since 1.13.2.2: +20 -7 lines
Log Message:
BugFix bootstrapfromlocationn passed with an argument

File Contents

# User Rev Content
1 williamc 1.1 #
2     # ConfigArea.pm
3     #
4 williamc 1.13.2.1 # Written by Christopher Williams
5 williamc 1.1 #
6     # Description
7 williamc 1.9 # -----------
8     # creates and manages a configuration area
9     #
10     # Options
11     # -------
12     # ConfigArea_location
13     # ConfigArea_name
14 williamc 1.1 #
15     # Interface
16     # ---------
17 williamc 1.13.2.1 # new() : A new ConfigArea object
18     # location([dir]) : set/return the location of the work area
19 williamc 1.13.2.3 # bootstrapfromlocation([location]) : bootstrap the object based on location.
20     # no location specified - cwd used
21     # return 0 if succesful 1 otherwise
22 williamc 1.5 # searchlocation([startdir]) : returns the location directory. search starts
23     # from cwd if not specified
24 williamc 1.6 # defaultdirname() : return the default directory name string
25 williamc 1.13.2.1 # scramversion() : return the scram version associated with
26     # area
27     # configurationdir() : return the location of the project
28     # configuration directory
29 williamc 1.13.2.2 # copy(location) : copy a configuration
30     # copysetup(location) : copy the architecture specific tool setup
31     # returns 0 if successful, 1 otherwise
32     # copyenv($ref) : copy the areas environment into the hashref
33 williamc 1.1
34     package Configuration::ConfigArea;
35     require 5.004;
36     use Utilities::AddDir;
37 williamc 1.13.2.1 use Utilities::Verbose;
38 williamc 1.6 use Cwd;
39 williamc 1.13.2.1 @ISA=qw(Utilities::Verbose);
40 williamc 1.1
41 williamc 1.13.2.1 sub new {
42     my $class=shift;
43     my $self={};
44     bless $self, $class;
45 williamc 1.9
46 williamc 1.13.2.2 # data init
47     $self->{admindir}=".SCRAM";
48 williamc 1.7
49 williamc 1.13.2.2 return $self;
50 williamc 1.9 }
51 williamc 1.8
52 williamc 1.13.2.1 sub configurationdir {
53 williamc 1.1 my $self=shift;
54 williamc 1.13.2.1 if ( @_ ) {
55     $self->{configurationdir}=shift;
56 williamc 1.6 }
57 williamc 1.13.2.1 if ( ! defined $self->{configurationdir} ) {
58     $self->_LoadEnvFile();
59     $self->{configurationdir}=$self->{ENV}{projconfigdir};
60     }
61     return $self->{configurationdir};
62     }
63    
64     sub scramversion {
65     my $self=shift;
66     if ( ! defined $self->{scramversion} ) {
67 williamc 1.13.2.2 my $filename=$self->location()."/".$self->configurationdir()."/".
68 williamc 1.13.2.1 "scram_version";
69     if ( -f $filename ) {
70     use FileHandle;
71     $fh=FileHandle->new();
72     open ($fh, "<".$filename);
73     my $version=<$fh>;
74     chomp $version;
75     $self->{scramversion}=$version;
76     undef $fh;
77     }
78 williamc 1.1 }
79 williamc 1.13.2.1 return $self->{scramversion};
80 williamc 1.4 }
81    
82 williamc 1.5 sub bootstrapfromlocation {
83     my $self=shift;
84 williamc 1.13.2.2
85     my $rv=0;
86 williamc 1.5
87 williamc 1.13.2.3 my $location;
88     if ( ! defined ($location=$self->searchlocation(@_)) ) {
89 williamc 1.13.2.2 $rv=1;
90     $self->verbose("Unable to locate the top of local configuration area");
91     }
92     else {
93 williamc 1.13.2.3 $self->location($location);
94 williamc 1.13.2.2 $self->verbose("Found top ".$self->location());
95     my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat";
96     $self->_LoadEnvFile();
97 williamc 1.5 }
98 williamc 1.13.2.2 return $rv;
99 williamc 1.1 }
100    
101     sub location {
102     my $self=shift;
103    
104 williamc 1.5 if ( @_ ) {
105 williamc 1.6 $self->{location}=shift;
106 williamc 1.5 }
107     elsif ( ! defined $self->{location} ) {
108     # try and find the release location
109 williamc 1.9 $self->{location}=$self->searchlocation();
110 williamc 1.5 }
111     return $self->{location};
112     }
113    
114     sub searchlocation {
115     my $self=shift;
116    
117     #start search in current directory if not specified
118     my $thispath;
119 williamc 1.13.2.3 if ( @_ ) {
120     $thispath=shift
121     }
122     else {
123     $thispath=cwd();
124     }
125 williamc 1.5
126     my $rv=0;
127    
128 williamc 1.13.2.3 print $thispath." --not shortened\n";
129     # chop off any files - we only want dirs
130     if ( -f $thispath ) {
131     $thispath=~s/(.*)\/.*/$1/;
132     print $thispath." --shortened\n";
133     }
134 williamc 1.6 Sloop:{
135     do {
136 williamc 1.13.2.1 $self->verbose("Searching $thispath");
137 williamc 1.8 if ( -e "$thispath/".$self->{admindir} ) {
138 williamc 1.13.2.1 $self->verbose("Found\n");
139 williamc 1.5 $rv=1;
140 williamc 1.6 last Sloop;
141 williamc 1.5 }
142 williamc 1.6 } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
143 williamc 1.5
144     return $rv?$thispath:undef;
145 williamc 1.1 }
146    
147 williamc 1.13.2.2 sub copy {
148     my $self=shift;
149     my $destination=shift;
150    
151     # copy across the admin dir
152     my $temp=$self->location()."/".$self->{admindir};
153     AddDir::copydir($temp,"$destination/".$self->{admindir});
154     }
155    
156     sub copysetup {
157     my $self=shift;
158     my $dest=shift;
159    
160     my $rv=1;
161     # copy across the admin dir
162     my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
163     my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
164     if ( $temp ne $temp2 ) {
165     if ( -d $temp ) {
166     AddDir::copydir($temp,$temp2);
167     $rv=0;
168     }
169     }
170     return $rv;
171     }
172    
173     sub copyenv {
174     my $self=shift;
175     my $hashref=shift;
176    
177     foreach $elem ( keys %{$self->{ENV}} ) {
178     $$hashref{$elem}=$self->{ENV}{$elem};
179     }
180     }
181    
182     sub arch {
183     my $self=shift;
184     return $ENV{SCRAM_ARCH};
185     }
186    
187 williamc 1.13.2.1 # ---- support routines
188     sub _LoadEnvFile {
189 williamc 1.1 my $self=shift;
190    
191 williamc 1.13.2.1 use FileHandle;
192     my $fh=FileHandle->new();
193 williamc 1.13.2.2 open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
194     "Environment" ) or
195 williamc 1.13.2.3 $self->error("Cannot find Environment file. Area Corrupted? ("
196     .$self->location().")\n $!");
197 williamc 1.13.2.1 while ( <$fh> ) {
198     chomp;
199     next if /^#/;
200     next if /^\s*$/ ;
201     ($name, $value)=split /=/;
202     eval "\$self->{ENV}{${name}}=\"$value\"";
203 williamc 1.9 }
204 williamc 1.13.2.1 undef $fh;
205 williamc 1.1 }
206    
207 williamc 1.13.2.1 sub _savevar {
208     my $self=shift;
209     my $fh=shift;
210 williamc 1.9 my $name=shift;
211 williamc 1.13.2.1 my $val=shift;
212     print $fh "#".$name."\n";
213     print $fh $val."\n";
214     }
215    
216     sub _restorevars {
217     my $self=shift;
218     my $fh=shift;
219     my $varhash=shift;
220    
221     while ( <$fh>=~/^#(.*)/ ) {
222     $name=$1;
223     chomp $name;
224     $value=<$fh>;
225     chomp $value;
226     $$varhash{$name}=$value;
227     #print "Restoring ".$name."=".$value."\n";
228     }
229 williamc 1.1 }