ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/scram
Revision: 1.17
Committed: Mon Mar 29 16:47:51 1999 UTC (26 years, 1 month ago) by williamc
Branch: MAIN
CVS Tags: V0_4
Changes since 1.16: +0 -6 lines
Log Message:
Wrapper now takes care of return to exit from user

File Contents

# User Rev Content
1 williamc 1.8 #!/usr/local/bin/perl5
2 williamc 1.1 #
3     # User Interface
4     #
5    
6     $inputcmd=shift;
7     $found='false';
8 williamc 1.13 $bold = "\033[1m";
9     $normal = "\033[0m";
10 williamc 1.15 @allowed_commands=qw(project build install version list arch setup);
11 williamc 1.1
12     foreach $command ( @allowed_commands ) {
13 williamc 1.13 if ( $inputcmd=~/^$command\Z/i) {
14     # Deal with a help request
15     do{ helpheader($command);
16     &{"help_".$command}; exit; } if $ARGV[0]=~/help/i;
17     &$command; $found='true';
18     last;
19     }
20 williamc 1.1 }
21    
22     if ( ! ( $found=~/true/ ) ) {
23 williamc 1.15 helpheader('Recognised Commands');
24 williamc 1.1 foreach $command ( @allowed_commands ) {
25 williamc 1.15 print " $bold scram ".$command.$normal."\n";
26 williamc 1.1 }
27 williamc 1.15 print "\n";
28     print "Help on individual commands available through\n\n";
29     print "$bold scram".$normal." command$bold help $normal\n\n";
30 williamc 1.1 }
31    
32 williamc 1.14 sub help_build {
33     &build;
34     }
35 williamc 1.1 sub build {
36     # is this a based or free release?
37     FullEnvInit();
38     use BuildSetup;
39 williamc 1.10 $ENV{MAKETARGETS}=join ' ',@ARGV;
40 williamc 1.1 BuildSetup($ENV{THISDIR},@ARGV);
41     # system("$ENV{TOOL_HOME}/BuildSetup",$ENV{THISDIR},@ARGV);
42     }
43    
44     sub project {
45 williamc 1.7 # process options
46     while ( $ARGV[0]=~"^-" ) {
47     if ( (shift @ARGV)=~/-d/ ) { #installation area directory
48     chdir $ARGV[0];
49     shift @ARGV;
50     }
51     }
52 williamc 1.1 my $project=shift @ARGV;
53     my $version=shift @ARGV;
54     environmentinit();
55     use File::Copy;
56 williamc 1.2 use Utilities::AddDir;
57 williamc 1.1
58     use BootStrapProject;
59     # get the bootstrap files downloaded
60     BootStrapProject("$project\?\?$version");
61     # Go setup the rest of the environement, now we can
62     chdir $ENV{LOCALTOP};
63     &localtop;
64     LoadEnvFile();
65     #
66     # Now create the directories specified in the interface
67     #
68     foreach $key ( keys %ENV ) {
69     if ( $key=~/^INT/ ) {
70 williamc 1.5 AddDir::adddir($ENV{$key});
71 williamc 1.1 }
72     }
73 williamc 1.6 if ( ! -e "$ENV{LOCALTOP}/$ENV{projconfigdir}" ) {
74     system("cp", "-r", "$ENV{RELEASETOP}/$ENV{projconfigdir}",
75     "$ENV{LOCALTOP}/$ENV{projconfigdir}");
76     }
77 williamc 1.1 use clientfile;
78     BuildClientFile( $ENV{SCRAM_ProjReqsDoc} );
79 williamc 1.7 use Cwd;
80     print "Installation Located at:\n".cwd()."\n";
81 williamc 1.1 }
82 williamc 1.7
83 williamc 1.1 sub FullEnvInit {
84     environmentinit();
85     localtop();
86     LoadEnvFile();
87     }
88    
89     sub environmentinit {
90 williamc 1.2 use Utilities::setarchitecture;
91 williamc 1.1 my $name;
92     my $value;
93    
94     $ENV{LatestBuildFile}=""; # stop recursive behaviour in make
95 williamc 1.4 setarchitecture::setarch();
96 williamc 1.1 $ENV{INTwork}="tmp/$ENV{SCRAM_ARCH}";
97     $ENV{INTlib}="lib/$ENV{SCRAM_ARCH}";
98     $ENV{INTsrc}="src";
99     $ENV{INTbin}="bin/$ENV{SCRAM_ARCH}";
100     $ENV{INTlog}="logs";
101    
102     if ( ! ( exists $ENV{SCRAM_HOME}) ){
103 williamc 1.8 $ENV{SCRAM_HOME}="/afs/cern.ch/cms/Releases";
104 williamc 1.1 print "Warning : Environment Variable SCRAM_HOME not set.\n";
105     print "Defaulting to $ENV{SCRAM_HOME}\n";
106     }
107     if ( ! ( exists $ENV{SCRAM_CONFIG} ) ){
108 williamc 1.3 $ENV{SCRAM_CONFIG}="$ENV{SCRAM_HOME}/configuration";
109 williamc 1.1 }
110     if ( ! ( exists $ENV{TOOL_HOME} ) ){
111 williamc 1.4 $ENV{TOOL_HOME}="$ENV{SCRAM_HOME}/src";
112 williamc 1.1 }
113     if ( ! ( exists $ENV{SCRAM_LOOKUPDB} ) ){
114     $ENV{SCRAM_LOOKUPDB}="$ENV{SCRAM_CONFIG}/project.lookup";
115     }
116     }
117    
118     sub localtop {
119     # find localtop
120     use Cwd;
121     my $thispath=cwd;
122     block: {
123     do {
124     if ( -e "$thispath/.SCRAM" ) {
125     $ENV{LOCALTOP}=$thispath;
126     last block;
127     }
128     } while ( ( $thispath=~s/(.*)\/.*/$1/ )=~/./ );
129     if ( ! (defined $ENV{LOCALTOP}) ) {
130     print "Unable to locate the top of local release. Exiting\n";
131     }
132     } #end block
133     ($ENV{THISDIR}=cwd)=~s/^$ENV{LOCALTOP}//;
134     $ENV{THISDIR}=~s/^\///;
135     $ENV{SCRAM_WORKDIR}="$ENV{LOCALTOP}/.SCRAM";
136     }
137    
138     sub LoadEnvFile {
139     open ( SCRAMENV, "<$ENV{SCRAM_WORKDIR}/Environment" ) ||
140     die "Cant find Environment file $!\n";
141     while ( <SCRAMENV> ) {
142     chomp;
143     next if /^#/;
144     next if /^\s*$/ ;
145     ($name, $value)=split /=/;
146     eval "\$ENV{${name}}=\"$value\"";
147     }
148     close SCRAMENV;
149     }
150    
151     sub env {
152     print "Sorry - Not yet\n";
153     }
154    
155     #
156     # Create a lookup tag in the site database
157     #
158     sub install ( $tagname, $version ) {
159     my $tagname=shift @ARGV;
160     my $version=shift @ARGV;
161    
162     # create database entry
163     &FullEnvInit;
164     if ( $version eq "" ) {
165     $version=$ENV{SCRAM_PROJVERSION};
166     }
167     if ( $tagname eq "" ) {
168     $tagname=$ENV{SCRAM_PROJECTNAME};
169     }
170     my $filename="$ENV{SCRAM_CONFIG}/project.lookup";
171     my $outfile="$ENV{SCRAM_CONFIG}/project.lookup.tmp";
172     open ( LOCALLOOKUPDB, "<$filename" );
173 williamc 1.16 open ( OUTFILE , ">$outfile" ) or die "Unable to open $outfile $!\n";
174 williamc 1.1 while ( <LOCALLOOKUPDB> ) {
175     if ( /^$tagname/ ) {
176     print "Related tag :".$_."\n";
177     if ( /$version/) {
178     print "$tagname $version already exists. Overwrite (y/n)\n";
179     if ( ! (<STDIN>=~/y/i ) ) {
180     print "Aborting install ...\n";
181     close OUTFILE;
182     close LOCALLOOKUPDB;
183     exit 1;
184     }
185     }
186     else {
187     print OUTFILE $_;
188     }
189     }
190     else {
191     print OUTFILE $_;
192     }
193     }
194     print OUTFILE "$tagname:$version:file:$ENV{LOCALTOP}".
195     "/.SCRAM/InstallFile\n";
196     close OUTFILE;
197     close LOCALLOOKUPDB;
198     copy ( "$outfile", "$filename" )
199     || die "Unable to copy $! \n";
200    
201     }
202    
203     sub help_install() {
204    
205     print <<ENDTEXT;
206     Associates a label with the current release in the SCRAM database.
207     This allows other users to refer to a centrally installed project by
208     this label rather than a remote url reference.
209    
210     Usage:
211    
212     scram install [[label] [version]]
213    
214     label : override default label (the project name of the current release)
215     version : the version tag of the current release. If version is not
216     specified the base release version will be taken by default.
217    
218     ENDTEXT
219     exit;
220     }
221    
222     sub helpheader ($label) {
223     my $label=shift;
224     print <<ENDTEXT;
225     *************************************************************************
226     SCRAM HELP --------- $label
227     *************************************************************************
228     ENDTEXT
229     }
230    
231     sub version {
232     print "Scram version : prototype\n";
233     }
234    
235     sub list {
236     &environmentinit;
237     my $filename="$ENV{SCRAM_CONFIG}/project.lookup";
238     open ( LOCALLOOKUPDB, "<$filename" );
239     print "Installed Projects\n";
240     print "------------------\n";
241     print "|Project Name | Project Version |\n";
242     print "----------------------------------\n";
243     while ( <LOCALLOOKUPDB> ) {
244     ( $name, $version, $type, $url ) = split ":", $_;
245     printf "%1s",$name;
246     printf "%25s\n",$version;
247     printf "--> %25s\n",$type.":".$url;
248     }
249     close LOCALLOOKUPDB;
250     }
251    
252     sub arch {
253     &environmentinit();
254     print "$ENV{SCRAM_ARCH}\n";
255 williamc 1.11 }
256    
257 williamc 1.12
258     #
259     # Setup a new tool
260     #
261    
262     sub setup {
263     my $toolname=shift @ARGV;
264    
265     &FullEnvInit;
266     if ( $ENV{SCRAM_BootStrapFiles}!~/$ENV{LOCALTOP}\/\.SCRAM/ ) {
267     $ENV{SCRAM_BootStrapFiles}="$ENV{LOCALTOP}/.SCRAM:".
268     $ENV{SCRAM_BootStrapFiles};
269     }
270     # Check for the correct toolfile
271     # ideally try and download it if not already in .SCRAM
272     # Only scram toolbox files supported so far
273     if ( ! -e "$ENV{LOCALTOP}/.SCRAM/$toolname" ) {
274     &urlhandler::urlhandler("file:$ENV{SCRAM_HOME}/toolbox/"
275     .$toolname, "$ENV{LOCALTOP}/.SCRAM/$toolname") ;
276     }
277     # Parse the toolfile and update the clientsettings file
278     # currently just append to the end
279     use clientfile;
280     clientfile::openclientfile('add');
281     clientfile::_tool("file:$toolname");
282     closeclientfile;
283     }
284    
285 williamc 1.13 sub help_setup {
286 williamc 1.12
287     print <<ENDTEXT;
288 williamc 1.14 Allows installation of a new tool/external package into an already
289     existing area.
290 williamc 1.12
291     Usage:
292    
293 williamc 1.14 $bold scram setup $normal toolname
294 williamc 1.12
295     toolname : The name of the tool setup file required.
296     ENDTEXT
297     exit;
298 williamc 1.13 }
299    
300     sub help_list {
301     print <<ENDTEXT;
302     Create an entry in the SCRAM database so that an installed project can be
303     referenced in the 'project' command by a tag/version combination.
304     Usage: (command to be issued from inside an installed project)
305    
306 williamc 1.14 $bold scram install $normal [project_tag [version_tag]]
307 williamc 1.13
308     If not specified the project_tag and version_tag default to the project
309     name and version of the installation.
310     ENDTEXT
311     exit;
312     }
313     sub help_project {
314     print <<ENDTEXT;
315     Setup a new project development area. The new area will appear in the current
316     working directory.
317     Usage:
318    
319     $bold scram project [-d install_area] $normal project_url [project_version]
320    
321     Options:
322    
323     project_url: The url of a scram bootstrap file.
324     Currently supported types are:
325     $bold Database label $normal
326     Labels can be assigned to bootstrap files for easy
327     access (See "scram install" command). If you
328     specify a label you must also specify a project_version.
329     e.g.
330    
331     scram project SCRAM V1_0
332    
333     scram project ORCA ORCA_1_1_1
334    
335     To see the list of installed projects use the
336     "scram list" command.
337    
338     $bold file: $normal A regular file on an accessable file system
339     e.g.
340    
341     file:~/myprojects/projecta/config/BootStrapFile
342    
343     project_version:
344     Only for use with a database label
345    
346     -d install_area:
347     Indicate a project installation area into which the new
348     project area should appear. Default is the current working
349     directory.
350    
351 williamc 1.14 ENDTEXT
352     }
353    
354     sub help_version {
355     print <<ENDTEXT;
356     Print the version number of scram
357     Usage:
358     $bold scram version $normal
359    
360     ENDTEXT
361     }
362    
363     sub help_arch {
364     print <<ENDTEXT;
365     Print out the architecture flag for the current machine.
366    
367     Usage:
368     $bold scram arch $normal
369 williamc 1.13 ENDTEXT
370 williamc 1.1 }