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