ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/Requirements.pm
Revision: 1.8
Committed: Thu Nov 29 12:56:11 2001 UTC (23 years, 5 months ago) by sashby
Content type: text/plain
Branch: MAIN
Changes since 1.7: +45 -35 lines
Log Message:
Select/deselct works properly now.

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