1 |
< |
#!/usr/local/bin/perl5 |
1 |
> |
#!/usr/local/bin/perl5 -w |
2 |
|
# |
3 |
|
# User Interface |
4 |
|
# |
5 |
|
|
6 |
< |
$inputcmd=shift; |
7 |
< |
$found='false'; |
8 |
< |
@allowed_commands=qw(project build env install version list arch); |
9 |
< |
|
10 |
< |
foreach $command ( @allowed_commands ) { |
11 |
< |
do { &$command; $found='true'; last;} if ( $inputcmd=~/^$command\Z/i); |
12 |
< |
} |
13 |
< |
|
14 |
< |
if ( ! ( $found=~/true/ ) ) { |
15 |
< |
print "scram help\n--------\n"; |
16 |
< |
print "Recognised Commands: \n"; |
17 |
< |
foreach $command ( @allowed_commands ) { |
18 |
< |
print " ".$command."\n"; |
19 |
< |
} |
20 |
< |
} |
21 |
< |
|
22 |
< |
sub build { |
23 |
< |
# is this a based or free release? |
24 |
< |
FullEnvInit(); |
25 |
< |
use BuildSetup; |
26 |
< |
$ENV{MAKETARGETS}=@ARGV; |
27 |
< |
BuildSetup($ENV{THISDIR},@ARGV); |
28 |
< |
# system("$ENV{TOOL_HOME}/BuildSetup",$ENV{THISDIR},@ARGV); |
29 |
< |
} |
30 |
< |
|
31 |
< |
sub project { |
32 |
< |
# process options |
33 |
< |
while ( $ARGV[0]=~"^-" ) { |
34 |
< |
if ( (shift @ARGV)=~/-d/ ) { #installation area directory |
35 |
< |
chdir $ARGV[0]; |
36 |
< |
shift @ARGV; |
37 |
< |
} |
38 |
< |
} |
39 |
< |
my $project=shift @ARGV; |
40 |
< |
my $version=shift @ARGV; |
41 |
< |
environmentinit(); |
42 |
< |
use File::Copy; |
43 |
< |
use Utilities::AddDir; |
44 |
< |
|
45 |
< |
use BootStrapProject; |
46 |
< |
# get the bootstrap files downloaded |
47 |
< |
BootStrapProject("$project\?\?$version"); |
48 |
< |
# Go setup the rest of the environement, now we can |
49 |
< |
chdir $ENV{LOCALTOP}; |
50 |
< |
&localtop; |
51 |
< |
LoadEnvFile(); |
52 |
< |
# |
53 |
< |
# Now create the directories specified in the interface |
54 |
< |
# |
55 |
< |
foreach $key ( keys %ENV ) { |
56 |
< |
if ( $key=~/^INT/ ) { |
57 |
< |
AddDir::adddir($ENV{$key}); |
58 |
< |
} |
59 |
< |
} |
60 |
< |
if ( ! -e "$ENV{LOCALTOP}/$ENV{projconfigdir}" ) { |
61 |
< |
system("cp", "-r", "$ENV{RELEASETOP}/$ENV{projconfigdir}", |
62 |
< |
"$ENV{LOCALTOP}/$ENV{projconfigdir}"); |
63 |
< |
} |
64 |
< |
use clientfile; |
65 |
< |
BuildClientFile( $ENV{SCRAM_ProjReqsDoc} ); |
66 |
< |
use Cwd; |
67 |
< |
print "Installation Located at:\n".cwd()."\n"; |
68 |
< |
print "Press RETURN to exit\n"; |
69 |
< |
$junk=<STDIN>; |
70 |
< |
} |
71 |
< |
|
72 |
< |
sub FullEnvInit { |
73 |
< |
environmentinit(); |
74 |
< |
localtop(); |
75 |
< |
LoadEnvFile(); |
76 |
< |
} |
77 |
< |
|
78 |
< |
sub environmentinit { |
79 |
< |
use Utilities::setarchitecture; |
80 |
< |
my $name; |
81 |
< |
my $value; |
82 |
< |
|
83 |
< |
$ENV{LatestBuildFile}=""; # stop recursive behaviour in make |
84 |
< |
setarchitecture::setarch(); |
85 |
< |
$ENV{INTwork}="tmp/$ENV{SCRAM_ARCH}"; |
86 |
< |
$ENV{INTlib}="lib/$ENV{SCRAM_ARCH}"; |
87 |
< |
$ENV{INTsrc}="src"; |
88 |
< |
$ENV{INTbin}="bin/$ENV{SCRAM_ARCH}"; |
89 |
< |
$ENV{INTlog}="logs"; |
90 |
< |
|
91 |
< |
if ( ! ( exists $ENV{SCRAM_HOME}) ){ |
92 |
< |
$ENV{SCRAM_HOME}="/afs/cern.ch/cms/Releases"; |
93 |
< |
print "Warning : Environment Variable SCRAM_HOME not set.\n"; |
94 |
< |
print "Defaulting to $ENV{SCRAM_HOME}\n"; |
95 |
< |
} |
96 |
< |
if ( ! ( exists $ENV{SCRAM_CONFIG} ) ){ |
97 |
< |
$ENV{SCRAM_CONFIG}="$ENV{SCRAM_HOME}/configuration"; |
98 |
< |
} |
99 |
< |
if ( ! ( exists $ENV{TOOL_HOME} ) ){ |
100 |
< |
$ENV{TOOL_HOME}="$ENV{SCRAM_HOME}/src"; |
101 |
< |
} |
102 |
< |
if ( ! ( exists $ENV{SCRAM_LOOKUPDB} ) ){ |
103 |
< |
$ENV{SCRAM_LOOKUPDB}="$ENV{SCRAM_CONFIG}/project.lookup"; |
104 |
< |
} |
105 |
< |
} |
106 |
< |
|
107 |
< |
sub localtop { |
108 |
< |
# find localtop |
109 |
< |
use Cwd; |
110 |
< |
my $thispath=cwd; |
111 |
< |
block: { |
112 |
< |
do { |
113 |
< |
if ( -e "$thispath/.SCRAM" ) { |
114 |
< |
$ENV{LOCALTOP}=$thispath; |
115 |
< |
last block; |
116 |
< |
} |
117 |
< |
} while ( ( $thispath=~s/(.*)\/.*/$1/ )=~/./ ); |
118 |
< |
if ( ! (defined $ENV{LOCALTOP}) ) { |
119 |
< |
print "Unable to locate the top of local release. Exiting\n"; |
120 |
< |
exit 1 |
121 |
< |
} |
122 |
< |
} #end block |
123 |
< |
($ENV{THISDIR}=cwd)=~s/^$ENV{LOCALTOP}//; |
124 |
< |
$ENV{THISDIR}=~s/^\///; |
125 |
< |
$ENV{SCRAM_WORKDIR}="$ENV{LOCALTOP}/.SCRAM"; |
126 |
< |
} |
127 |
< |
|
128 |
< |
sub LoadEnvFile { |
129 |
< |
open ( SCRAMENV, "<$ENV{SCRAM_WORKDIR}/Environment" ) || |
130 |
< |
die "Cant find Environment file $!\n"; |
131 |
< |
while ( <SCRAMENV> ) { |
132 |
< |
chomp; |
133 |
< |
next if /^#/; |
134 |
< |
next if /^\s*$/ ; |
135 |
< |
($name, $value)=split /=/; |
136 |
< |
eval "\$ENV{${name}}=\"$value\""; |
137 |
< |
} |
138 |
< |
close SCRAMENV; |
139 |
< |
} |
140 |
< |
|
141 |
< |
sub env { |
142 |
< |
print "Sorry - Not yet\n"; |
143 |
< |
} |
6 |
> |
#use Scram::SCRAM; |
7 |
> |
use ActiveDoc::CommandLineInterface; |
8 |
> |
use Utilities::PathMod; |
9 |
> |
|
10 |
> |
# Set up our scram objects |
11 |
> |
$self={}; |
12 |
> |
|
13 |
> |
# Search for configuration resource file |
14 |
> |
$self->{configpath}="$ENV{HOME}:$ENV{SCRAM_HOME}/configuration"; |
15 |
> |
$self->{PathMod}=Utilities::PathMod->new(); |
16 |
> |
$self->{file}=$self->{PathMod}->SearchPath( |
17 |
> |
$self->{configpath},".scramrc"); |
18 |
> |
|
19 |
> |
#$self->{cli}=ActiveDoc::CommandLineInterface->new(qw(file:$self->{file} UserInterface_basic)); |
20 |
> |
$self->{cli}=ActiveDoc::CommandLineInterface->new(qw(Scram::SCRAM ActiveDoc::UserInterface_basic)); |
21 |
> |
|
22 |
> |
$self->{cli}->parse(@ARGV) |
23 |
> |
|
24 |
> |
#@allowed_commands=qw(project build install version list arch setup runtime devtest); |
25 |
|
|
145 |
– |
# |
146 |
– |
# Create a lookup tag in the site database |
147 |
– |
# |
148 |
– |
sub install ( $tagname, $version ) { |
149 |
– |
my $tagname=shift @ARGV; |
150 |
– |
my $version=shift @ARGV; |
151 |
– |
|
152 |
– |
# create database entry |
153 |
– |
do { &help_install; } if $tagname=~/help/i; |
154 |
– |
&FullEnvInit; |
155 |
– |
if ( $version eq "" ) { |
156 |
– |
$version=$ENV{SCRAM_PROJVERSION}; |
157 |
– |
} |
158 |
– |
if ( $tagname eq "" ) { |
159 |
– |
$tagname=$ENV{SCRAM_PROJECTNAME}; |
160 |
– |
} |
161 |
– |
my $filename="$ENV{SCRAM_CONFIG}/project.lookup"; |
162 |
– |
my $outfile="$ENV{SCRAM_CONFIG}/project.lookup.tmp"; |
163 |
– |
open ( LOCALLOOKUPDB, "<$filename" ); |
164 |
– |
open ( OUTFILE , ">$outfile" ); |
165 |
– |
while ( <LOCALLOOKUPDB> ) { |
166 |
– |
if ( /^$tagname/ ) { |
167 |
– |
print "Related tag :".$_."\n"; |
168 |
– |
if ( /$version/) { |
169 |
– |
print "$tagname $version already exists. Overwrite (y/n)\n"; |
170 |
– |
if ( ! (<STDIN>=~/y/i ) ) { |
171 |
– |
print "Aborting install ...\n"; |
172 |
– |
close OUTFILE; |
173 |
– |
close LOCALLOOKUPDB; |
174 |
– |
exit 1; |
175 |
– |
} |
176 |
– |
} |
177 |
– |
else { |
178 |
– |
print OUTFILE $_; |
179 |
– |
} |
180 |
– |
} |
181 |
– |
else { |
182 |
– |
print OUTFILE $_; |
183 |
– |
} |
184 |
– |
} |
185 |
– |
print OUTFILE "$tagname:$version:file:$ENV{LOCALTOP}". |
186 |
– |
"/.SCRAM/InstallFile\n"; |
187 |
– |
close OUTFILE; |
188 |
– |
close LOCALLOOKUPDB; |
189 |
– |
copy ( "$outfile", "$filename" ) |
190 |
– |
|| die "Unable to copy $! \n"; |
191 |
– |
|
192 |
– |
} |
193 |
– |
|
194 |
– |
sub help_install() { |
195 |
– |
|
196 |
– |
helpheader("install"); |
197 |
– |
print <<ENDTEXT; |
198 |
– |
Associates a label with the current release in the SCRAM database. |
199 |
– |
This allows other users to refer to a centrally installed project by |
200 |
– |
this label rather than a remote url reference. |
201 |
– |
|
202 |
– |
Usage: |
203 |
– |
|
204 |
– |
scram install [[label] [version]] |
205 |
– |
|
206 |
– |
label : override default label (the project name of the current release) |
207 |
– |
version : the version tag of the current release. If version is not |
208 |
– |
specified the base release version will be taken by default. |
209 |
– |
|
210 |
– |
ENDTEXT |
211 |
– |
exit; |
212 |
– |
} |
213 |
– |
|
214 |
– |
sub helpheader ($label) { |
215 |
– |
my $label=shift; |
216 |
– |
print <<ENDTEXT; |
217 |
– |
************************************************************************* |
218 |
– |
SCRAM HELP --------- $label |
219 |
– |
************************************************************************* |
220 |
– |
ENDTEXT |
221 |
– |
} |
222 |
– |
|
223 |
– |
sub version { |
224 |
– |
print "Scram version : prototype\n"; |
225 |
– |
} |
226 |
– |
|
227 |
– |
sub list { |
228 |
– |
&environmentinit; |
229 |
– |
my $filename="$ENV{SCRAM_CONFIG}/project.lookup"; |
230 |
– |
open ( LOCALLOOKUPDB, "<$filename" ); |
231 |
– |
print "Installed Projects\n"; |
232 |
– |
print "------------------\n"; |
233 |
– |
print "|Project Name | Project Version |\n"; |
234 |
– |
print "----------------------------------\n"; |
235 |
– |
while ( <LOCALLOOKUPDB> ) { |
236 |
– |
( $name, $version, $type, $url ) = split ":", $_; |
237 |
– |
printf "%1s",$name; |
238 |
– |
printf "%25s\n",$version; |
239 |
– |
printf "--> %25s\n",$type.":".$url; |
240 |
– |
} |
241 |
– |
close LOCALLOOKUPDB; |
242 |
– |
} |
243 |
– |
|
244 |
– |
sub arch { |
245 |
– |
&environmentinit(); |
246 |
– |
print "$ENV{SCRAM_ARCH}\n"; |
247 |
– |
} |