ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/Requirements.pm
Revision: 1.3
Committed: Tue Nov 28 16:12:21 2000 UTC (24 years, 5 months ago) by williamc
Content type: text/plain
Branch: MAIN
CVS Tags: V0_18_5, V0_18_4, V_18_3_TEST, VO_18_3, V0_18_2
Changes since 1.2: +6 -0 lines
Log Message:
Add verbose messages

File Contents

# User Rev Content
1 williamc 1.2 # Requirements Doc - just to get ordering info
2     #
3     # Interface
4     # ---------
5     # new(ActiveStore,url[,arch]) : new requirements doc
6     # setup(toolbox): set up the requirements into the specified toolbox object
7     # download(toolbox) : download description files (into toolbox cache)
8     # tools() : Return list of ALL requirements (ordered)
9     # selectedtools() : Return list of only those tools selected
10     # version(tool) : return the version of a given tool
11     # toolurl(tool) : return the url of a given tool
12     # getreqforarch(arch) : Return a RequirementsObject corresponding to the
13     # specified architecture
14     # toolcomment(tool,version) : return the comment string for the specified tool
15     # distributionurl(tool,version) : return the dist info url for the tool
16    
17     package BuildSystem::Requirements;
18     use ActiveDoc::ActiveDoc;
19     use Utilities::Verbose;
20    
21     require 5.004;
22     @ISA=qw(Utilities::Verbose);
23    
24     sub new {
25     my $class=shift;
26     my $self={};
27     bless $self, $class;
28     $self->{dbstore}=shift;
29     $self->{file}=shift;
30     $self->{cache}=$self->{dbstore}->cache();
31     if ( @_ ) {
32     $self->arch(shift);
33     }
34 williamc 1.3 $self->verbose("Initialising a new Requirements Doc");
35 williamc 1.2 $self->{mydocversion}="2.0";
36     $self->{Arch}=1;
37     push @{$self->{ARCHBLOCK}}, $self->{Arch};
38     $self->init($self->{file});
39     return $self;
40     }
41    
42     sub url {
43     my $self=shift;
44     if ( @_ ) {
45     $self->{file}=shift;
46     }
47     return $self->{file}
48     }
49    
50     sub setup {
51     my $self=shift;
52     my $toolbox=shift;
53    
54     my $tool;
55     foreach $tool ( $self->selectedtools() ) {
56     $self->verbose("Setting Up Tool $tool");
57     $toolbox->toolsetup($tool, $self->version($tool), $self->toolurl($tool));
58     }
59     }
60    
61     sub tools {
62     my $self=shift;
63     return @{$self->{tools}};
64     }
65    
66     sub selectedtools {
67     my $self=shift;
68     my @toollist=();
69     foreach $tool ( @{$self->{tools}} ) {
70     if ( $self->{selected}{$tool} == 1 ) {
71     push @toollist, $tool;
72     }
73     }
74     return @toollist;
75     }
76    
77     sub toolcomment {
78     my $self=shift;
79     my $tool=shift;
80     my $version=shift;
81    
82     return $self->{reqtext}{$tool}{$version};
83     }
84    
85     sub distributionurl {
86     my $self=shift;
87     my $tool=shift;
88     my $version=shift;
89    
90     return ( defined $self->{dist}{$tool}{$version})?
91     $self->{dist}{$tool}{$version}:undef;
92     }
93    
94     sub version {
95     my $self=shift;
96     my $tool=shift;
97     return $self->{'version'}{$tool};
98     }
99    
100     sub toolurl {
101     my $self=shift;
102     my $tool=shift;
103     return $self->{'url'}{$tool};
104     }
105    
106     sub init {
107     my $self=shift;
108     my $url=shift;
109    
110     my $switch=ActiveDoc::ActiveDoc->new($self->{dbstore});
111     $switch->verbosity($self->verbosity());
112     $switch->url($url);
113     $switch->newparse("ordering");
114     $switch->addbasetags("ordering");
115     $switch->addtag("ordering","Architecture",
116     \&Arch_Start,$self,
117     "", $self,
118     \&Arch_End, $self);
119     $switch->addtag("ordering","Restrict",
120     \&Restrict_start,$self,
121     "", $self,
122     \&Restrict_end, $self);
123     $switch->addtag("ordering","deselect",
124     \&deselect_start,$self,
125     "", $self,
126     "", $self);
127     $switch->addtag("ordering","select",
128     \&select_start,$self,
129     "", $self,
130     "", $self);
131     $switch->addtag("ordering","distribution",
132     \&disttag,$self);
133     $switch->grouptag("Architecture","ordering");
134     $switch->addtag("ordering","require",
135     \&require_start,$self,
136     \&require_text, $self,
137     \&require_end, $self);
138    
139     $self->{reqcontext}=0;
140     $self->{switch}=$switch;
141     undef $self->{restrictstack};
142     @{$self->{tools}}=();
143    
144     my($doctype,$docversion)=$switch->doctype();
145     # -- for backwards compatability only parse if we have a docversion
146     # defined
147     if ( defined $docversion ) {
148     if ( $docversion eq $self->{mydocversion} ) {
149     @{$self->{ArchStack}}=();
150 williamc 1.3 $self->verbose("Initial Document Parse");
151 williamc 1.2 $self->{switch}->parse("ordering");
152     }
153 williamc 1.3 else {
154     $self->verbose("wrong doc version - not parsing");
155     }
156 williamc 1.2 }
157     else {
158 williamc 1.3 $self->verbose("wrong doc type - not parsing");
159 williamc 1.2 #print "wrong doc version - not parsing\n";
160     }
161     }
162    
163     sub arch {
164     my $self=shift;
165     if ( @_ ) {
166     $self->{arch}=shift
167     }
168     else {
169     if ( ! defined $self->{arch} ) {
170     $self->{arch}="";
171     }
172     }
173     return $self->{arch};
174     }
175    
176     sub archlist {
177     my $self=shift;
178     return @{$self->{ArchStack}};
179     }
180    
181     sub getreqforarch {
182     my $self=shift;
183     my $arch=shift;
184    
185     if ( ! defined $self->{reqsforarch}{$arch} ) {
186     $self->{reqsforarch}{$arch}=
187     BuildSystem::Requirements->new($self->{dbstore},$self->{file},
188     $arch);
189     }
190     return $self->{reqsforarch}{$arch};
191     }
192    
193    
194     sub download {
195     my $self=shift;
196    
197     my $tool;
198     foreach $tool ( $self->tools() ) {
199     $self->verbose("Downloading ".$self->toolurl($tool));
200     # get into the cache
201     $self->{switch}->urlget($self->toolurl($tool));
202     }
203     }
204    
205     sub _autoselect {
206     my $self=shift;
207     if ( @_ ) {
208     $self->{autoselect}=shift;
209     }
210     # -- default is true
211     return ((defined $self->{autoselect})?$self->{autoselect}:1);
212     }
213    
214     # ---- Tag routines
215    
216     sub Restrict_start {
217     my $self=shift;
218     my $name=shift;
219     my $hashref=shift;
220    
221     $self->{switch}->checktag( $name, $hashref, 'autoselect');
222     if ( $self->{Arch} ) {
223     # -- create selection state stack
224     push @{$self->{restrictstack}}, $self->_autoselect();
225     $self->_autoselect(
226     (($$hashref{'autoselect'}=~/true/i)?1:0));
227     }
228     }
229    
230     sub Restrict_end {
231     my $self=shift;
232     my $name=shift;
233    
234     if ( $self->{Arch} ) {
235     if ( $#{$self->{restrictstack}} >= 0 ) {
236     $self->_autoselect(pop @{$self->{restrictstack}});
237     }
238     else {
239     $self->{switch}->parseerror("Unmatched </$name>");
240     }
241     }
242     }
243    
244     sub require_start {
245     my $self=shift;
246     my $name=shift;
247     my $hashref=shift;
248    
249     $self->{switch}->checktag( $name, $hashref, 'version');
250     $self->{switch}->checktag( $name, $hashref, 'name');
251     $self->{switch}->checktag( $name, $hashref, 'url');
252    
253     if ( $self->{reqcontext} == 1 ) {
254     $self->{switch}->parseerror(
255     "Open new $name conext without previous </$name>");
256     }
257     $self->{reqcontext}=1;
258     $$hashref{'name'}=~tr[A-Z][a-z];
259     push @{$self->{tools}}, $$hashref{'name'};
260     $self->{version}{$$hashref{'name'}}=$$hashref{'version'};
261     # -- make sure the full url is taken
262     my $urlobj=$self->{switch}->expandurl($$hashref{'url'});
263     $self->{url}{$$hashref{'name'}}=$urlobj->url();
264    
265     # -- selection
266     if ( $self->{Arch} ) {
267     if ( $self->_autoselect() ) {
268     $self->{selected}{$$hashref{'name'}}=1;
269     }
270     else {
271     $self->{selected}{$$hashref{'name'}}=0;
272     }
273     }
274     $self->{creqtool}=$$hashref{'name'};
275     $self->{creqversion}=$$hashref{'version'};
276     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}="";
277     }
278    
279     sub require_text {
280     my $self=shift;
281     my $name=shift;
282     my $string=shift;
283    
284     chomp $string;
285     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}=
286     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}.
287     $string;
288    
289     }
290    
291     sub require_end {
292     my $self=shift;
293     my $name=shift;
294    
295     if ( $self->{reqcontext} != 1 ) {
296     $self->{switch}->parseerror("No matching tag for </$name>");
297     }
298     else {
299     $self->{reqcontext}=0;
300     }
301     }
302    
303     sub select_start {
304     my $self=shift;
305     my $name=shift;
306     my $hashref=shift;
307    
308     $self->{switch}->checktag( $name, $hashref, 'name');
309     $$hashref{'name'}=~tr[A-Z][a-z];
310     if ( $self->{Arch} ) {
311     $self->verbose("Selecting ".$$hashref{'name'});
312     $self->{selected}{$$hashref{'name'}}=1;
313     }
314     }
315    
316     sub deselect_start {
317     my $self=shift;
318     my $name=shift;
319     my $hashref=shift;
320    
321     $self->{switch}->checktag( $name, $hashref, 'name');
322     $$hashref{'name'}=~tr[A-Z][a-z];
323     if ( $self->{Arch} ) {
324     $self->verbose("Deselecting ".$$hashref{'name'});
325     $self->{selected}{$$hashref{'name'}}=0;
326     }
327     }
328    
329     sub Arch_Start {
330     my $self=shift;
331     my $name=shift;
332     my $hashref=shift;
333    
334     $self->{switch}->checktag($name, $hashref,'name');
335    
336     ( ($self->arch()=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
337     : ($self->{Arch}=0);
338     $self->verbose(($self->{Arch}?"OK":"skipping")." ".$$hashref{name});
339     push @{$self->{ARCHBLOCK}}, $self->{Arch};
340     push @{$self->{ArchStack}}, $$hashref{'name'};
341     }
342    
343     sub Arch_End {
344     my $self=shift;
345     my $name=shift;
346    
347     pop @{$self->{ARCHBLOCK}};
348     $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
349     }
350    
351     sub disttag {
352     my $self=shift;
353     my $name=shift;
354     my $hashref=shift;
355    
356     if ( exists $$hashref{'url'} ) {
357     $self->{dist}{$self->{creqtool}}{$self->{creqversion}}=
358     $$hashref{'url'};
359     }
360     }