ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/Requirements.pm
Revision: 1.6
Committed: Thu Nov 15 21:18:15 2001 UTC (23 years, 5 months ago) by sashby
Content type: text/plain
Branch: MAIN
Changes since 1.5: +4 -1 lines
Log Message:
Committing the days changes.

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