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