ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/Requirements.pm
(Generate patch)

Comparing COMP/SCRAM/src/BuildSystem/Requirements.pm (file contents):
Revision 1.8 by sashby, Thu Nov 29 12:56:11 2001 UTC vs.
Revision 1.23 by sashby, Tue Feb 27 11:59:44 2007 UTC

# Line 15 | Line 15
15   # distributionurl(tool,version) : return the dist info url for the tool
16  
17   package BuildSystem::Requirements;
18 +
19 + BEGIN
20 +   {
21 +   die "\n\n".__PACKAGE__.": this package has been moved to Configuration::Requirements. This one is obsolete and can be removed.\n\n";
22 +   }
23 +
24   use ActiveDoc::ActiveDoc;
25   use Utilities::Verbose;
26  
27   require 5.004;
28   @ISA=qw(Utilities::Verbose);
29 + $BuildSystem::Requirements::self;
30  
31 < sub new {
32 <        my $class=shift;
33 <        my $self={};
34 <        bless $self, $class;
35 <        $self->{dbstore}=shift;
36 <        $self->{file}=shift;
37 <        $self->{cache}=$self->{dbstore}->cache();
38 <        if ( @_ ) {
39 <          $self->arch(shift);
40 <        }
41 <        $self->verbose("Initialising a new Requirements Doc");
42 <        $self->{mydocversion}="2.0";
43 <        $self->{Arch}=1;
44 <        push @{$self->{ARCHBLOCK}}, $self->{Arch};
45 <        $self->init($self->{file});
46 <        return $self;
47 < }
48 <
49 < sub url {
50 <        my $self=shift;
51 <        if ( @_ ) {
52 <          $self->{file}=shift;
53 <        }
54 <        return $self->{file}
55 < }
31 > sub new
32 >   {
33 >   my $class=shift;
34 >   # Initialise the global package variable:
35 >   no strict 'refs';
36 >   $self = defined $self ? $self
37 >      : (bless {}, $class );
38 >   $self->{dbstore}=shift;
39 >   $self->{file}=shift;
40 >   $self->{cache}=$self->{dbstore}->cache();
41 >
42 >   if ( @_ )
43 >      {
44 >      $self->arch(shift);
45 >      }
46 >   $self->verbose("Initialising a new Requirements Doc");
47 >   $self->{mydoctype} = "BuildSystem::Requirements";
48 >   $self->{mydocversion}="2.0";
49 >   # Counter for downloaded tools: zero it here. It will
50 >   # be auto-incremented as each tool is selected:
51 >   $self->{selectcounter}=0;
52 >  
53 >   $self->{Arch}=1;
54 >   push @{$self->{ARCHBLOCK}}, $self->{Arch};
55 >   $self->init($self->{file});
56 >   return $self;
57 >   }
58  
59 < sub setup
59 > sub toolmanager
60     {
61     my $self=shift;
62 <   my $toolbox=shift;
63 <   my $tool;
62 >  
63 >   @_ ? $self->{toolmanagerobject} = shift
64 >      : $self->{toolmanagerobject};
65 >  
66 >   }
67  
68 <   foreach $tool ( $self->selectedtools() )
68 > sub configversion
69 >   {
70 >   my $self=shift;
71 >   @_ ? $self->{configversion} = shift
72 >      : $self->{configversion};
73 >   }
74 >
75 > sub url
76 >   {
77 >   my $self=shift;
78 >  
79 >   if ( @_ )
80        {
81 <      $self->verbose("Setting Up Tool $tool");
59 <      $toolbox->toolsetup($tool, $self->version($tool), $self->toolurl($tool));
81 >      $self->{file}=shift;
82        }
83 +   return $self->{file};
84 +   }
85 +
86 + sub tools
87 +   {
88 +   my $self=shift;
89 +   return @{$self->{tools}};
90 +   }
91 +
92 + sub toolcomment
93 +   {
94 +   my $self=shift;
95 +   my $tool=shift;
96 +   my $version=shift;
97 +  
98 +   return $self->{reqtext}{$tool}{$version};
99 +   }
100 +
101 + sub distributionurl
102 +   {
103 +   my $self=shift;
104 +   my $tool=shift;
105 +   my $version=shift;
106 +  
107 +   return ( defined $self->{dist}{$tool}{$version})?
108 +      $self->{dist}{$tool}{$version}:undef;
109 +   }
110 +
111 + sub version
112 +   {
113 +   my $self=shift;
114 +   my $tool=shift;
115 +   return $self->{'version'}{$tool};
116     }
117  
118 < sub tools {
119 <        my $self=shift;
120 <        return @{$self->{tools}};
121 < }
118 > sub toolurl
119 >   {
120 >   my $self=shift;
121 >   my $tool=shift;
122 >   return $self->{'url'}{$tool};
123 >   }
124  
125 < sub selectedtools
125 > sub init
126     {
127     my $self=shift;
128 <   my @toollist=();
128 >   my $url=shift;
129 >   my $scramdoc=ActiveDoc::ActiveDoc->new($self->{dbstore});
130 >   $scramdoc->verbosity($self->verbosity());
131 >   $scramdoc->url($url);  
132 >   $scramdoc->newparse("ordering",$self->{mydoctype},'Subs');
133 >   $self->{reqcontext}=0;
134 >   $self->{scramdoc}=$scramdoc;
135 >   undef $self->{restrictstack};
136 >   @{$self->{tools}}=();
137 >   @{$self->{ArchStack}}=();
138 >   $self->verbose("Initial Document Parse");
139 >   $self->{scramdoc}->parse("ordering");
140 >   # Set the config version. If there isn't a version, it means that we
141 >   # have a stand-alone repository for the toolbox, rather than a CVS
142 >   # one. Hence, no CVS tag (== version):
143 >   ($scramdoc->{configurl}->param('version') eq '') ?
144 >      $self->configversion("STANDALONE") :
145 >      $self->configversion($scramdoc->{configurl}->param('version'));
146 >   }
147  
148 <   foreach $tool (  @{$self->{tools}} )
148 > sub arch
149 >   {
150 >   my $self=shift;
151 >   # $self->arch is the SCRAM_ARCH value:
152 >   if ( @_ )
153 >      {
154 >      $self->{arch}=shift;
155 >      }
156 >   else
157        {
158 <      if ( $self->{selected}{$tool} eq "SELECTED" )
158 >      if ( ! defined $self->{arch} )
159           {
160 <         push @toollist, $tool;
160 >         $self->{arch}="";
161           }
162        }
163 <   return @toollist;
163 >   return $self->{arch};
164     }
165  
166 < sub toolcomment {
167 <        my $self=shift;
168 <        my $tool=shift;
169 <        my $version=shift;
170 <
171 <        return $self->{reqtext}{$tool}{$version};
172 < }
173 <
174 < sub distributionurl {
175 <        my $self=shift;
176 <        my $tool=shift;
177 <        my $version=shift;
178 <
179 <        return ( defined $self->{dist}{$tool}{$version})?
180 <                        $self->{dist}{$tool}{$version}:undef;
181 < }
182 <
183 < sub version {
184 <        my $self=shift;
185 <        my $tool=shift;
186 <        return $self->{'version'}{$tool};
187 < }
188 <
189 < sub toolurl {
190 <        my $self=shift;
191 <        my $tool=shift;
192 <        return $self->{'url'}{$tool};
193 < }
194 <
195 < sub init {
196 <        my $self=shift;
197 <        my $url=shift;
198 <
199 <        my $switch=ActiveDoc::ActiveDoc->new($self->{dbstore});
200 <        $switch->verbosity($self->verbosity());
201 <        $switch->url($url);
202 <        $switch->newparse("ordering");
203 <        $switch->addbasetags("ordering");
204 <        $switch->addtag("ordering","Architecture",
205 <                                        \&Arch_Start,$self,
206 <                                        "", $self,
207 <                                        \&Arch_End, $self);
208 <        $switch->addtag("ordering","Restrict",
209 <                                        \&Restrict_start,$self,
210 <                                        "", $self,
211 <                                        \&Restrict_end, $self);
212 <        $switch->addtag("ordering","deselect",
213 <                                        \&deselect_start,$self,
214 <                                        "", $self,
215 <                                        "", $self);
216 <        $switch->addtag("ordering","select",
217 <                                        \&select_start,$self,
218 <                                        "", $self,
219 <                                        "", $self);
220 <        $switch->addtag("ordering","distribution",
221 <                                        \&disttag,$self);
222 <        $switch->grouptag("Architecture","ordering");
223 <        $switch->addtag("ordering","require",
224 <                                        \&require_start,$self,
225 <                                        \&require_text, $self,
226 <                                        \&require_end, $self);
227 <
228 <        $self->{reqcontext}=0;
229 <        $self->{switch}=$switch;
230 <        undef $self->{restrictstack};
231 <        @{$self->{tools}}=();
232 <        
233 <        my($doctype,$docversion)=$switch->doctype();
234 <        # -- for backwards compatability only parse if we have a docversion
235 <        #    defined
236 <        if ( defined $docversion ) {
237 <          if ( $docversion eq $self->{mydocversion} ) {
238 <            @{$self->{ArchStack}}=();
239 <            $self->verbose("Initial Document Parse");
240 <            $self->{switch}->parse("ordering");
241 <          }
242 <          else {
243 <            $self->verbose("wrong doc version - not parsing");
244 <          }
245 <        }
246 <        else {
247 <          $self->verbose("wrong doc type - not parsing");
248 <        }
249 < }
250 <
251 < sub arch {
252 <        my $self=shift;
253 <        if ( @_ ) {
254 <          $self->{arch}=shift
255 <        }
256 <        else {
257 <          if ( ! defined $self->{arch} ) {
258 <            $self->{arch}="";
259 <          }
260 <        }
261 <        return $self->{arch};
262 < }
263 <
264 < sub archlist {
265 <        my $self=shift;
266 <        return @{$self->{ArchStack}};
267 < }
268 <
269 < sub getreqforarch {
270 <        my $self=shift;
271 <        my $arch=shift;
272 <
273 <        if ( ! defined $self->{reqsforarch}{$arch} ) {
274 <          $self->{reqsforarch}{$arch}=
275 <                BuildSystem::Requirements->new($self->{dbstore},$self->{file},
276 <                                                $arch);
277 <        }
278 <        return $self->{reqsforarch}{$arch};
279 < }
280 <
281 <
282 < sub download {
283 <        my $self=shift;
284 <
285 <        my $tool;
286 <        foreach $tool ( $self->tools() ) {
287 <          $self->verbose("Downloading ".$self->toolurl($tool));
288 <          # get into the cache
289 <          $self->{switch}->urlget($self->toolurl($tool));
290 <        }
291 < }
292 <
293 < sub _autoselect {
294 <        my $self=shift;
295 <        if ( @_ ) {
296 <          $self->{autoselect}=shift;
297 <        }
298 <        # -- default is true
299 <        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 < }
166 > sub archlist
167 >   {
168 >   my $self=shift;
169 >   return @{$self->{ArchStack}};
170 >   }
171 >
172 > sub getreqforarch
173 >   {
174 >   my $self=shift;
175 >   my $arch=shift;
176 >  
177 >   if ( ! defined $self->{reqsforarch}{$arch} )
178 >      {
179 >      $self->{reqsforarch}{$arch}=
180 >         BuildSystem::Requirements->new($self->{dbstore},$self->{file},
181 >                                        $arch);
182 >      }
183 >   return $self->{reqsforarch}{$arch};
184 >   }
185 >
186 > sub download
187 >   {
188 >   my $self=shift;
189 >   my $tool;
190 >   $| = 1; # Unbuffer the output
191 >
192 >   print  "Downloading tool descriptions....","\n";
193 >   print  " ";
194 >   foreach $tool ( $self->tools() )
195 >      {
196 >      print "#";
197 >      $self->verbose("Downloading ".$self->toolurl($tool));
198 >      # get into the cache:
199 >      $self->{scramdoc}->urlget($self->toolurl($tool));
200 >      }
201 >   print "\nDone.","\n";
202 >   # So now add the list of downloaded tools, and which were
203 >   # selected, to tool cache:
204 >   print "Tool info cached locally.","\n","\n";
205 >
206 >   # Now copy required info from this object to ToolManager (ToolCache):
207 >   $self->toolmanager()->downloadedtools($self->{tools});
208 >   $self->toolmanager()->defaultversions($self->{version});
209 >   $self->toolmanager()->toolurls($self->{url});
210 >   $self->toolmanager()->selected($self->{selected});
211 >   }
212 >
213 > #sub _autoselect
214 > #   {
215 > #   my $self=shift;
216 > #   if ( @_ )
217 > #      {
218 > #      $self->{autoselect}=shift;
219 > #      }
220 > #   # -- default is true
221 > #   return ((defined $self->{autoselect})?$self->{autoselect}:1);
222 > #   }
223 >
224 > sub require()
225 >   {
226 >   my $self=shift;
227 >   my $name=shift;
228 >   my $hashref=shift;
229 >  
230 >   $self->{scramdoc}->checktag( $name, $hashref, 'version');
231 >   $self->{scramdoc}->checktag( $name, $hashref, 'name');
232 >   $self->{scramdoc}->checktag( $name, $hashref, 'url');
233 >  
234 >   if ( $self->{reqcontext} == 1 )
235 >      {
236 >      $self->{scramdoc}->parseerror(
237 >                                  "Open new $name context without previous </$name>");
238 >      }
239 >   $self->{reqcontext}=1;
240 >   $$hashref{'name'}=~tr[A-Z][a-z];
241 >  
242 >   # Add protection so that architecture tags are obeyed during download:
243 >   if ( $self->{Arch} )
244 >      {
245 >      # Add tool to the tool array:
246 >      push @{$self->{tools}}, $$hashref{'name'};
247 >      
248 >      # If the tool already has an entry, modify the version string to
249 >      # include both versions. The versions can later be separated and
250 >      # parsed as normal:
251 >      if (defined $self->{version}{$$hashref{'name'}})
252 >         {
253 >         # Don't need an extra entry for this tool onto tool array:
254 >         pop @{$self->{tools}}, $$hashref{'name'};
255 >         # Modify the version string to append the other tool version.
256 >         # Separate using a colon:
257 >         my $newversion=$self->{version}{$$hashref{'name'}}.":".$$hashref{'version'};
258 >         $self->{version}{$$hashref{'name'}}=$newversion;
259 >         }
260 >      else
261 >         {
262 >         $self->{version}{$$hashref{'name'}}=$$hashref{'version'};
263 >         }
264 >      # -- make sure the full url is taken
265 >      my $urlobj=$self->{scramdoc}->expandurl($$hashref{'url'});
266 >      $self->{url}{$$hashref{'name'}}=$urlobj->url();
267 >
268 >      $self->{creqtool}=$$hashref{'name'};
269 >      $self->{creqversion}=$$hashref{'version'};
270 >      $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}="";
271 >      }
272 >   }
273 >
274 > sub require_text
275 >   {
276 >   my $self=shift;
277 >   my $name=shift;
278 >   my $string=shift;
279 >  
280 >   chomp $string;
281 >   $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}=
282 >      $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}.
283 >      $string;  
284 >   }
285 >
286 > sub require_end
287 >   {
288 >   my $self=shift;
289 >   my $name=shift;
290 >  
291 >   if ( $self->{reqcontext} != 1 )
292 >      {
293 >      $self->{scramdoc}->parseerror("No matching tag for </$name>");
294 >      }
295 >   else
296 >      {
297 >      $self->{reqcontext}=0;
298 >      }
299 >   }
300  
301   sub select_start
302     {
# Line 311 | Line 304 | sub select_start
304     my $name=shift;
305     my $hashref=shift;
306  
307 <   $self->{switch}->checktag( $name, $hashref, 'name');
307 >   $self->{scramdoc}->checktag( $name, $hashref, 'name');
308     $$hashref{'name'}=~tr[A-Z][a-z];
309     if ( $self->{Arch} )
310        {
311        $self->verbose("Selecting ".$$hashref{'name'});
312 <      $self->{selected}{$$hashref{'name'}} = "SELECTED";
313 <      $self->verbose(">> Tool select flag = ".$self->{selected}{$$hashref{'name'}}."\n");
312 >      # Increment counter:
313 >      $self->{selectcounter}++;
314 >      $self->{selected}{$$hashref{'name'}}=$self->{selectcounter};
315        }
316     }
317  
318 < sub deselect_start
318 > sub Arch_Start
319     {
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} )
324 >   # Check the architecture tag:
325 >   $self->{scramdoc}->checktag($name, $hashref,'name');  
326 >   ( ($self->arch()=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
327 >      : ($self->{Arch}=0);
328 >  
329 >   $self->verbose(($self->{Arch}?"OK":"skipping")." ".$$hashref{name});
330 >   push @{$self->{ARCHBLOCK}}, $self->{Arch};
331 >   push @{$self->{ArchStack}}, $$hashref{'name'};
332 >   }
333 >
334 > sub Arch_End
335 >   {
336 >   my $self=shift;
337 >   my $name=shift;
338 >   pop @{$self->{ARCHBLOCK}};
339 >   $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
340 >   }
341 >
342 > sub disttag
343 >   {
344 >   my $self=shift;
345 >   my $name=shift;
346 >   my $hashref=shift;
347 >  
348 >   if ( exists $$hashref{'url'} )
349        {
350 <      $self->verbose("Deselecting ".$$hashref{'name'});
351 <      $self->{selected}{$$hashref{'name'}} = "DESELECTED";
336 <      $self->verbose(">> Tool select flag = ".$self->{selected}{$$hashref{'name'}}."\n");
350 >      $self->{dist}{$self->{creqtool}}{$self->{creqversion}}=
351 >         $$hashref{'url'};
352        }
353     }
354  
355 < sub Arch_Start {
356 <        my $self=shift;
357 <        my $name=shift;
358 <        my $hashref=shift;
359 <
360 <        $self->{switch}->checktag($name, $hashref,'name');
361 <        
362 <        ( ($self->arch()=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
363 <                                                : ($self->{Arch}=0);
364 <        $self->verbose(($self->{Arch}?"OK":"skipping")." ".$$hashref{name});
365 <        push @{$self->{ARCHBLOCK}}, $self->{Arch};
366 <        push @{$self->{ArchStack}}, $$hashref{'name'};
367 < }
368 <
369 < sub Arch_End {
370 <        my $self=shift;
371 <        my $name=shift;
372 <
373 <        pop @{$self->{ARCHBLOCK}};
374 <        $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 < }
355 > sub select()
356 >   {
357 >   my ($xmlparser,$name,%attributes)=@_;
358 > #   print "Selecting ".$attributes{'name'},"\n";
359 >   }
360 >
361 > sub select_()
362 >   {}
363 >
364 > sub AUTOLOAD()
365 >   {
366 >   my ($xmlparser,$name,%attributes)=@_;
367 >   return if $AUTOLOAD =~ /::DESTROY$/;
368 >   my $name=$AUTOLOAD;
369 >   $name =~ s/.*://;
370 >   # Delegate missing function calls to the doc parser class:
371 >   $self->{scramdoc}->$name(%attributes);
372 >   }
373 >
374 > 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines