1 |
#!/usr/local/bin/perl5
|
2 |
# Bootstrap file parser
|
3 |
|
4 |
package BootStrapProject;
|
5 |
require Exporter;
|
6 |
@ISA=qw(Exporter);
|
7 |
@EXPORT=qw(BootStrapProject);
|
8 |
use Utilities::cvsmodule;
|
9 |
|
10 |
sub BootStrapProject($) {
|
11 |
my $url=shift;
|
12 |
# my $outputfile=shift;
|
13 |
|
14 |
use Utilities::urlhandler;
|
15 |
use Utilities::Switcher;
|
16 |
|
17 |
my $filename;
|
18 |
$BootHash={
|
19 |
'cvsrep_StartTag' => \&cvsrep_start,
|
20 |
'cvsrep' => 'none',
|
21 |
'cvsrep_EndTag' => \&cvsrep_end,
|
22 |
'cvs_StartTag' => \&cvs_start,
|
23 |
'cvs' => 'none',
|
24 |
'cvs_EndTag' => 'none',
|
25 |
'config_starttag' => \&config_starttag,
|
26 |
'config_endtag' => \&config_endtag,
|
27 |
'config' => 'none',
|
28 |
'base' => 'none',
|
29 |
'base_starttag' => \&base_start,
|
30 |
'base_endtag' => \&base_end,
|
31 |
'project' => 'none',
|
32 |
'project_starttag' => \&project_start,
|
33 |
'project_endtag' => \&project_finish,
|
34 |
'install' => \&install,
|
35 |
'install_starttag' => \&install_start,
|
36 |
'install_endtag' => \&install_finish,
|
37 |
'requirements' => 'none',
|
38 |
'requirements_starttag' => \&reqs_start,
|
39 |
'file' => 'none',
|
40 |
'file_starttag' => \&file_start
|
41 |
};
|
42 |
$filename=urlhandler::urlhandler($url);
|
43 |
$switch=Switcher->new($BootHash, $filename);
|
44 |
$switch->parse();
|
45 |
}
|
46 |
|
47 |
sub Bootlocaltop {
|
48 |
my $hashref=shift;
|
49 |
use Cwd;
|
50 |
use Utilities::AddDir;
|
51 |
|
52 |
$switch->checkparam($hashref, $name, "name");
|
53 |
$switch->checkparam($hashref, $name, "version");
|
54 |
$ENV{LOCALTOP}=&cwd."/".$$hashref{'name'}."_".$$hashref{'version'};
|
55 |
$scramdir=$ENV{LOCALTOP}."/.SCRAM";
|
56 |
&AddDir::adddir($scramdir);
|
57 |
chdir $ENV{LOCALTOP};
|
58 |
}
|
59 |
|
60 |
sub project_start {
|
61 |
my $name=shift;
|
62 |
my @vars=@_;
|
63 |
my $hashref;
|
64 |
|
65 |
$hashref=$switch->SetupValueHash( \@vars );
|
66 |
Bootlocaltop($hashref);
|
67 |
print "Installing Project $$hashref{'name'} ".
|
68 |
"Version $$hashref{'version'}\n";
|
69 |
open ( ENVIRONMENT , ">$scramdir/Environment" ) || die "Unable to open ".
|
70 |
"Environment file : $!\n";
|
71 |
print ENVIRONMENT 'SCRAM_PROJECTNAME='.$$hashref{'name'}."\n";
|
72 |
print ENVIRONMENT 'SCRAM_PROJVERSION='.$$hashref{'version'}."\n";
|
73 |
$ENV{SCRAM_BootStrapFiles}=$scramdir;
|
74 |
open INSTALLFILE, ">$scramdir/InstallFile";
|
75 |
print INSTALLFILE "<install name=$$hashref{name} ".
|
76 |
"version=$$hashref{version}>\n";
|
77 |
print INSTALLFILE "<base urltype=file value=$scramdir>\n";
|
78 |
print INSTALLFILE "<file name=Environment>\n";
|
79 |
push @{ $basehash{file}}, "$ENV{SCRAM_HOME}/toolbox";
|
80 |
$lastbasekey='file';
|
81 |
push @dirstack, $scramdir;
|
82 |
$currentdir=$scramdir;
|
83 |
}
|
84 |
|
85 |
sub project_finish {
|
86 |
print ENVIRONMENT "SCRAM_BootStrapFiles=".$ENV{SCRAM_BootStrapFiles}."\n";
|
87 |
print ENVIRONMENT "RELEASETOP=$ENV{LOCALTOP}\n";
|
88 |
close ENVIRONMENT;
|
89 |
print INSTALLFILE "</install>\n";
|
90 |
close INSTALLFILE
|
91 |
}
|
92 |
|
93 |
# Set where the project specific configuration files live for the project
|
94 |
sub config_starttag {
|
95 |
my $name=shift;
|
96 |
my @vars=@_;
|
97 |
my $hashref;
|
98 |
|
99 |
$hashref=$switch->SetupValueHash( \@vars );
|
100 |
$switch->checkparam($hashref, $name, "dir");
|
101 |
print ENVIRONMENT 'projconfigdir='.$$hashref{'dir'}."\n";
|
102 |
$ENV{SCRAM_BootStrapFiles}=$ENV{SCRAM_BootStrapFiles}.":".
|
103 |
$ENV{LOCALTOP}."/".$$hashref{'dir'};
|
104 |
push @dirstack, $ENV{LOCALTOP}."/".$$hashref{'dir'};
|
105 |
$currentdir=$ENV{LOCALTOP}."/".$$hashref{'dir'};
|
106 |
if ( $switch->context('project') ) {
|
107 |
print INSTALLFILE "<$name dir=$$hashref{dir}>\n";
|
108 |
}
|
109 |
}
|
110 |
sub config_endtag {
|
111 |
my $name=shift;
|
112 |
|
113 |
pop @dirstack;
|
114 |
$currentdir=$dirstack[$#dirstack];
|
115 |
if ( $switch->context('project') ) {
|
116 |
print INSTALLFILE "</$name>\n";
|
117 |
}
|
118 |
}
|
119 |
|
120 |
sub file_start {
|
121 |
my $name=shift;
|
122 |
my @vars=@_;
|
123 |
my $hashref;
|
124 |
|
125 |
$hashref=$switch->SetupValueHash( \@vars );
|
126 |
$switch->checkparam($hashref, $name, "name");
|
127 |
# now download the file
|
128 |
print "Downloading File .... $$hashref{'name'}\n";
|
129 |
&urlhandler::urlhandler(&geturlbase."/".$$hashref{'name'},
|
130 |
$scramdir."/".$$hashref{'name'}) ;
|
131 |
if ( $switch->context('project') ) {
|
132 |
print INSTALLFILE "<$name name=$$hashref{name}>\n";
|
133 |
}
|
134 |
}
|
135 |
|
136 |
sub reqs_start {
|
137 |
my $name=shift;
|
138 |
my @vars=@_;
|
139 |
my $hashref;
|
140 |
|
141 |
$hashref=$switch->SetupValueHash( \@vars );
|
142 |
$switch->checkparam($hashref, $name, "name");
|
143 |
use clientfile;
|
144 |
$ENV{SCRAM_ProjReqsDoc}=
|
145 |
$currentdir."/".$$hashref{'name'};
|
146 |
print ENVIRONMENT 'SCRAM_ProjReqsDoc='.$ENV{SCRAM_ProjReqsDoc}."\n";
|
147 |
# &urlhandler::urlhandler(&geturlbase."/".$$hashref{'name'},
|
148 |
# $scramdir."/".$$hashref{'name'}) ;
|
149 |
if ( $switch->context("project") ) {
|
150 |
print INSTALLFILE "<$name name=$$hashref{name}>\n";
|
151 |
}
|
152 |
}
|
153 |
|
154 |
sub base_start {
|
155 |
my $name=shift;
|
156 |
my @vars=@_;
|
157 |
my $hashref;
|
158 |
|
159 |
$hashref=$switch->SetupValueHash( \@vars );
|
160 |
$switch->checkparam($hashref, $name, 'urltype');
|
161 |
$switch->checkparam($hashref, $name, 'value');
|
162 |
push @{ $basehash{ $$hashref{'urltype'} }}, $$hashref{'value'};
|
163 |
$lastbasekey=$$hashref{'urltype'};
|
164 |
#print $lastbasekey." lastbasekey \n";
|
165 |
}
|
166 |
|
167 |
sub base_end {
|
168 |
pop @{ $basehash{$lastbasekey} };
|
169 |
}
|
170 |
|
171 |
#sub checkparam($hash, $name, $key) {
|
172 |
# my $hashref=shift;
|
173 |
# my $name=shift;
|
174 |
# my $key=shift;
|
175 |
#
|
176 |
# if ( ! defined $$hashref{$key} ) {
|
177 |
# print "BootParser: Badly formed $name tag -".
|
178 |
# " undefined $key parameter\n";
|
179 |
# exit 1;
|
180 |
# }
|
181 |
# $$hashref{$key}=~s/["']//;
|
182 |
#}
|
183 |
|
184 |
#Just a file for now!
|
185 |
#Will eventually cross ref with access checker to get types available.
|
186 |
sub geturlbase {
|
187 |
return "file:".@{$basehash{'file'}}[$#{$basehash{'file'}}];
|
188 |
}
|
189 |
|
190 |
|
191 |
#
|
192 |
# Now deal with an already intalled release base
|
193 |
#
|
194 |
|
195 |
sub install_start {
|
196 |
my $name=shift;
|
197 |
my @vars=@_;
|
198 |
my $hashref;
|
199 |
|
200 |
$hashref=$switch->SetupValueHash( \@vars );
|
201 |
Bootlocaltop($hashref);
|
202 |
|
203 |
}
|
204 |
|
205 |
# Can use this to print out a project specific message
|
206 |
sub install {
|
207 |
my $name=shift;
|
208 |
my $vars=shift;
|
209 |
|
210 |
print @$vars;
|
211 |
}
|
212 |
|
213 |
sub install_finish {
|
214 |
my $name=shift;
|
215 |
my @vars=@_;
|
216 |
my $hashref;
|
217 |
}
|
218 |
|
219 |
sub cvsrep_start {
|
220 |
my $name=shift;
|
221 |
my @vars=@_;
|
222 |
my $hashref;
|
223 |
|
224 |
$hashref=$switch->SetupValueHash( \@vars );
|
225 |
$switch->checkparam($hashref, $name, 'auth' );
|
226 |
$switch->checkparam($hashref, $name, 'base' );
|
227 |
$cvsobject=cvsmodule->new();
|
228 |
$cvsobject->set_base($$hashref{base});
|
229 |
$cvsobject->set_auth($$hashref{auth});
|
230 |
if ( exists $$hashref{user} ) {
|
231 |
$cvsobject->set_user($$hashref{user});
|
232 |
}
|
233 |
if ( exists $$hashref{passkey} ) {
|
234 |
$cvsobject->set_passkey($$hashref{passkey});
|
235 |
}
|
236 |
}
|
237 |
|
238 |
sub cvsrep_end {
|
239 |
my $name=shift;
|
240 |
$cvsobject=undef; #Move out of scope to destroy cvsrep context
|
241 |
}
|
242 |
|
243 |
sub cvs_start {
|
244 |
my $name=shift;
|
245 |
my @vars=@_;
|
246 |
my $hashref;
|
247 |
|
248 |
if ( ! defined $cvsobject ) {
|
249 |
print "BootStraper: Undefined cvs repository on line ".
|
250 |
$switch->{linenumber}."\n - set up repository".
|
251 |
"specifics with the <cvsrep> flag\n";
|
252 |
exit 1;
|
253 |
}
|
254 |
$hashref=$switch->SetupValueHash( \@vars );
|
255 |
$switch->checkparam( $hashref, $name, "fn" );
|
256 |
$cvsobject->invokecvs( (split / /, $$hashref{fn} ) );
|
257 |
}
|