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

# User Rev Content
1 williamc 1.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 williamc 1.3 use Utilities::cvsmodule;
9 williamc 1.1
10     sub BootStrapProject($) {
11     my $url=shift;
12     # my $outputfile=shift;
13    
14 williamc 1.2 use Utilities::urlhandler;
15     use Utilities::Switcher;
16 williamc 1.1
17     my $filename;
18     $BootHash={
19 williamc 1.3 '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 williamc 1.1 'config_starttag' => \&config_starttag,
26 williamc 1.4 'config_endtag' => \&config_endtag,
27 williamc 1.1 '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 williamc 1.3 $filename=urlhandler::urlhandler($url);
43 williamc 1.1 $switch=Switcher->new($BootHash, $filename);
44     $switch->parse();
45     }
46    
47     sub Bootlocaltop($hashref) {
48     my $hashref=shift;
49     use Cwd;
50 williamc 1.2 use Utilities::AddDir;
51 williamc 1.1
52 williamc 1.3 $switch->checkparam($hashref, $name, "name");
53     $switch->checkparam($hashref, $name, "version");
54 williamc 1.1 $ENV{LOCALTOP}=&cwd."/".$$hashref{'name'}."_".$$hashref{'version'};
55     $scramdir=$ENV{LOCALTOP}."/.SCRAM";
56 williamc 1.3 &AddDir::adddir($scramdir);
57 williamc 1.4 chdir $ENV{LOCALTOP};
58 williamc 1.1 }
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 williamc 1.4 push @{ $basehash{file}}, "$ENV{SCRAM_HOME}/toolbox";
78     $lastbasekey='file';
79     push @dirstack, $scramdir;
80     $currentdir=$scramdir;
81 williamc 1.1 }
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 williamc 1.3 $switch->checkparam($hashref, $name, "dir");
99 williamc 1.1 print ENVIRONMENT 'projconfigdir='.$$hashref{'dir'}."\n";
100     $ENV{SCRAM_BootStrapFiles}=$ENV{SCRAM_BootStrapFiles}.":".
101     $ENV{LOCALTOP}."/".$$hashref{'dir'};
102 williamc 1.4 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 williamc 1.1 }
109    
110     sub file_start {
111     my $name=shift;
112     my @vars=@_;
113     my $hashref;
114    
115     $hashref=$switch->SetupValueHash( \@vars );
116 williamc 1.3 $switch->checkparam($hashref, $name, "name");
117 williamc 1.1 # now download the file
118     print "Downloading File .... $$hashref{'name'}\n";
119 williamc 1.3 &urlhandler::urlhandler(&geturlbase."/".$$hashref{'name'},
120 williamc 1.1 $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 williamc 1.3 $switch->checkparam($hashref, $name, "name");
133 williamc 1.1 use clientfile;
134     $ENV{SCRAM_ProjReqsDoc}=
135 williamc 1.4 $currentdir."/".$$hashref{'name'};
136     # &urlhandler::urlhandler(&geturlbase."/".$$hashref{'name'},
137     # $scramdir."/".$$hashref{'name'}) ;
138 williamc 1.1 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 williamc 1.3 $switch->checkparam($hashref, $name, 'urltype');
150     $switch->checkparam($hashref, $name, 'value');
151 williamc 1.1 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 williamc 1.3 #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 williamc 1.1
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 williamc 1.3 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 williamc 1.1 }