1 |
williamc |
1.2 |
# Bootstrap file parser
|
2 |
|
|
#
|
3 |
|
|
# Interface
|
4 |
|
|
# ---------
|
5 |
|
|
# new(cache,installbase) : a new bootstrapper
|
6 |
|
|
# boot(url[,devareaname]) : boot up a new project , return the ConfigArea
|
7 |
|
|
|
8 |
|
|
package Configuration::BootStrapProject;
|
9 |
|
|
use ActiveDoc::SimpleURLDoc;
|
10 |
|
|
use URL::URLhandler;
|
11 |
|
|
use Utilities::Verbose;
|
12 |
|
|
require 5.004;
|
13 |
|
|
|
14 |
|
|
@ISA=qw(Utilities::Verbose);
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
sub new {
|
18 |
|
|
my $class=shift;
|
19 |
|
|
my $self={};
|
20 |
|
|
bless $self, $class;
|
21 |
|
|
$self->{cache}=shift;
|
22 |
|
|
$self->{baselocation}=shift;
|
23 |
|
|
$self->{mydoctype}="Configuration::BootStrapProject";
|
24 |
|
|
$self->{mydocversion}="1.0";
|
25 |
|
|
$self->{Arch}=1;
|
26 |
|
|
push @{$self->{ARCHBLOCK}}, $self->{Arch};
|
27 |
|
|
return $self;
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
sub _initswitcher {
|
31 |
|
|
my $self=shift;
|
32 |
|
|
my $switch=ActiveDoc::SimpleURLDoc->new($self->{cache});
|
33 |
|
|
my $parse="boot";
|
34 |
|
|
$switch->newparse($parse);
|
35 |
|
|
$switch->addbasetags($parse);
|
36 |
|
|
$switch->addtag($parse,"RequirementsDoc", \&ReqDoc_start, $self,
|
37 |
|
|
\&print_text, $self,
|
38 |
|
|
\&ReqDoc_end, $self);
|
39 |
|
|
$switch->addtag($parse,"config", \&Config_start, $self,
|
40 |
|
|
"", $self,
|
41 |
|
|
"", $self);
|
42 |
|
|
$switch->addtag($parse,"project", \&Project_start, $self,
|
43 |
|
|
\&print_text, $self,
|
44 |
|
|
\&Project_end, $self);
|
45 |
|
|
$switch->addtag($parse,"download", \&GetToTop_start, $self,
|
46 |
|
|
\&print_text, $self,
|
47 |
|
|
"", $self);
|
48 |
|
|
$self->{switch}=$switch;
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
sub boot {
|
52 |
|
|
my $self=shift;
|
53 |
|
|
my $url=shift;
|
54 |
|
|
|
55 |
|
|
# -- override directory name
|
56 |
|
|
if ( @_ ) {
|
57 |
|
|
$self->{devareaname}=shift;
|
58 |
|
|
}
|
59 |
|
|
else {
|
60 |
|
|
$self->{devareaname}="";
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
# -- initialise file parser
|
64 |
|
|
$self->_initswitcher();
|
65 |
|
|
my ($fullurl,$filename)=$self->{switch}->urldownload($url);
|
66 |
|
|
$self->{switch}->filetoparse($filename);
|
67 |
|
|
|
68 |
|
|
# -- document version check
|
69 |
|
|
my ($doctype,$docversion)=$self->{switch}->doctype();
|
70 |
|
|
if ( ( $doctype ne $self->{mydoctype}) &&
|
71 |
|
|
( $docversion ne $self->{mydocversion}) ) {
|
72 |
|
|
$self->{switch}->parseerror("Can Only process documents of type ".
|
73 |
|
|
$self->{mydoctype}." version ".$self->{mydocversion}.
|
74 |
|
|
"\nAre you sure you are using the correct scram version?");
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
$self->{switch}->parse("boot");
|
78 |
|
|
return $self->{area};
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
# --- Tag Routines
|
82 |
|
|
|
83 |
|
|
sub print_text {
|
84 |
|
|
my $self=shift;
|
85 |
|
|
my $name=shift;
|
86 |
|
|
my @text=shift;
|
87 |
|
|
|
88 |
|
|
print "@text\n";
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
sub Project_start {
|
92 |
|
|
my $self=shift;
|
93 |
|
|
my $name=shift;
|
94 |
|
|
my $hashref=shift;
|
95 |
|
|
|
96 |
|
|
$self->{switch}->checktag($name, $hashref, 'name');
|
97 |
|
|
$self->{switch}->checktag($name, $hashref, 'version');
|
98 |
|
|
print "Installing Project $$hashref{'name'} ".
|
99 |
|
|
"Version $$hashref{'version'}\n";
|
100 |
|
|
$self->{area}=Configuration::ConfigArea->new();
|
101 |
|
|
$self->{area}->name($$hashref{'name'});
|
102 |
|
|
$self->{area}->version($$hashref{'version'});
|
103 |
|
|
$self->{area}->setup($self->{baselocation});
|
104 |
|
|
|
105 |
|
|
# new urlhandler based on area cache
|
106 |
|
|
$self->{switch}->cache($self->{area}->cache());
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
sub Project_end {
|
110 |
|
|
my $self=shift;
|
111 |
|
|
$self->{area}->save();
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
# Set where the project specific configuration files live for the project
|
115 |
sashby |
1.4 |
sub Config_start
|
116 |
|
|
{
|
117 |
|
|
my $self=shift;
|
118 |
|
|
my $name=shift;
|
119 |
|
|
my $hashref=shift;
|
120 |
|
|
|
121 |
|
|
$self->{switch}->checktag($name, $hashref, "dir");
|
122 |
|
|
$$hashref{'dir'}=~s/`//g;
|
123 |
|
|
# Set the project config dir variable here so that
|
124 |
|
|
# "projconfigdir" value can be used while bootstrapping:
|
125 |
|
|
$ENV{projconfigdir} = $$hashref{'dir'};
|
126 |
|
|
$self->{area}->configurationdir($$hashref{'dir'});
|
127 |
|
|
}
|
128 |
williamc |
1.2 |
|
129 |
|
|
sub ReqDoc_start {
|
130 |
|
|
my $self=shift;
|
131 |
|
|
my $name=shift;
|
132 |
|
|
my $hashref=shift;
|
133 |
|
|
|
134 |
|
|
my ($filename,$fullurl);
|
135 |
|
|
if ( exists $$hashref{'url'} ) {
|
136 |
|
|
# -- download into our cache
|
137 |
|
|
($fullurl,$filename)=$self->{switch}->urlget($$hashref{'url'});
|
138 |
|
|
}
|
139 |
|
|
else {
|
140 |
|
|
$self->{switch}->checktag($name, $hashref, "name");
|
141 |
|
|
$filename=$$hashref{'name'};
|
142 |
|
|
}
|
143 |
|
|
$self->{area}->requirementsdoc($filename);
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
sub GetToTop_start {
|
147 |
|
|
my $self=shift;
|
148 |
|
|
my $name=shift;
|
149 |
|
|
my $hashref=shift;
|
150 |
|
|
|
151 |
|
|
$self->{switch}->checktag($name, $hashref, "url");
|
152 |
|
|
$self->{switch}->checktag($name, $hashref, "name");
|
153 |
|
|
|
154 |
|
|
# -- download into top directory
|
155 |
|
|
my ($fullurl,$filename)=$self->{switch}->urlget($$hashref{'url'},
|
156 |
|
|
$self->{area}->location()."/".$$hashref{'name'});
|
157 |
|
|
}
|