ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/Requirements.pm
Revision: 1.9
Committed: Mon Dec 3 19:02:04 2001 UTC (23 years, 5 months ago) by sashby
Content type: text/plain
Branch: MAIN
Changes since 1.8: +2 -0 lines
Log Message:
*** empty log message ***

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