ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BootStrapProject.pm
Revision: 1.4
Committed: Mon Mar 8 09:56:21 1999 UTC (26 years, 2 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.3: +15 -2 lines
Log Message:
Default base is now SCRAM_HOME/toolbox. Also updated directory selection mechanism with config

File Contents

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