Distribconf.pm

filter: Statementstmt 85.5% 172 / 201 Branchbran 75.8% 94 / 124 Conditioncond 70.0% 28 / 40 MC/DCmcdc 45.4% 10 / 22 Subroutinesub 95.4% 21 / 22 Podpod 94.4% 17 / 18 totaltotal 80.0% 342 / 427 SCAR 49.3
CC
85
Cov
81%
getvalue
44.2
parse_version
12.0
parse_hdlists
11.9
CRAP 138.2
« Distribconf/Checks.pm ↑ Summary Distribconf/Utils.pm »
1 package MDV::Distribconf;
2  
3 # $Id: Distribconf.pm 232708 2007-12-30 04:28:14Z nanardon $
4  
5 5 our $VERSION = '3.14';
6  
7 =head1 NAME
8  
9 MDV::Distribconf - Read and write config of a Mandriva Linux distribution tree
10  
11 =head1 SYNOPSIS
12  
13 use MDV::Distribconf;
14  
15 my $d = MDV::Distribconf->new("/path/to/the/distribution/root");
16 $d->load()
17 or die "This doesn't seem to be a distribution tree\n";
18  
19 print $d->getpath(undef, "root") ."\n";
20 foreach ($d->listmedia) {
21 printf "%s -> %s\n", $d->getpath($_, "hdlist"), $d->getpath($_, path);
22 }
23  
24 =head1 DESCRIPTION
25  
26 MDV::Distribconf is a module to get or write the configuration of a Mandriva
27 Linux distribution tree. This configuration is stored in a file called
28 F<media.cfg>, aimed at replacing the old-style F<hdlists> file.
29  
30 The format of the F<hdlists> file is limited and doesn't allow to add new
31 values without breaking compatibility, while F<media.cfg> is designed for
32 extensibility. To keep compatibility with old tools, this module is able
33 to generate an F<hdlists> file based on F<media.cfg>.
34  
35 This module is able to manage both configuration of old-style trees
36 (F<Mandrake/base/> for OS versions 10.0 and older) and of new-style ones
37 (F<media/media_info/> for 10.1 and newer).
38  
39 =head1 media.cfg
40  
41 The F<media.cfg> is structured like a classical F<.ini> file. All
42 parameters are optional; this means that a readable empty file is ok, if
43 this is what you want :)
44  
45 F<media.cfg> contains sections, each section corresponding to a media,
46 except the C<[media_info]> section wich is used to store global info. The
47 section name is the (relative) path where the rpms are located. It is
48 sufficient to uniquely identify a media.
49  
50 Some values have specific signification:
51  
52 =over 4
53  
54 =item media specific values:
55  
56 =over 4
57  
58 =item B<hdlist>
59  
60 The path or basename of the hdlist. By default, this is
61 C<hdlist_mediapath.cz>, with slashes and spaces being replaced by '_'.
62  
63 =item B<synthesis>
64  
65 The path or basename of the synthesis. By default, this is the hdlist
66 name prefixed by C<synthesis>.
67  
68 =item B<pubkey>
69  
70 The path or basename of the gpg public key file. By default, this is
71 the media name prefixed by C<pubkey_>.
72  
73 =item B<name>
74  
75 A human-readable name for the media. By default this is the media path
76 (that is, the section name), where slashes have been replaced by
77 underscores.
78  
79 =back
80  
81 =item global specific values:
82  
83 =over 4
84  
85 =item B<version>
86  
87 OS version.
88  
89 =item B<branch>
90  
91 OS branch (cooker, etc.)
92  
93 =item B<arch>
94  
95 Media target architecture.
96  
97 =item B<root>
98  
99 The root path of the distribution tree. This value is not set in
100 F<media.cfg>, can't be owerwritten, and is only used internally.
101  
102 =item B<mediadir>
103  
104 The default path relative to the 'root' path where media are
105 located. MDV::Distribconf is supposed to configure this automatically
106 to C<Mandrake> or to C<media>, depending on the OS version.
107  
108 =item B<infodir>
109  
110 The default path relative to the 'root' path where distrib metadata
111 are located. MDV::Distribconf is supposed to configure this automatically
112 to C<Mandrake/base> or to C<media/media_info>, depending on the OS
113 version.
114  
115 =back
116  
117 =back
118  
119 For the paths of the hdlist and synthesis files, if only a basename is
120 provided, the path is assumed to be relative to the mediadir or infodir.
121 (hdlist and synthesis are created in both directories.) If it's a complete
122 path, it's assumed to be relative to the 'root'. For example,
123  
124 hdlist.cz -> <root>/<infodir>/hdlist.cz
125 ./hdlist.cz -> <root>/./hdlist.cz
126  
127 Here's a complete example of a F<media.cfg> file:
128  
129 # Comment
130 [media_info]
131 # some tools can use those values
132 version=2006.0
133 branch=cooker
134  
135 [main]
136 hdlist=hdlist_main.cz
137 name=Main
138  
139 [../SRPMS/main]
140 hdlist=hdlist_main.src.cz
141 name=Main Sources
142 noauto=1
143  
144 [contrib]
145 hdlist=hdlist_contrib.cz
146 name=Contrib
147  
148 [../SRPMS/contrib]
149 hdlist=hdlist_contrib.src.cz
150 name=Contrib Sources
151 noauto=1
152  
153 =head1 METHODS
154  
155 =cut
156  
157 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
158 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
159 5 ▶use Config::IniFiles;
Subroutine BEGIN: called CC=1 SCAR=0.0
160  
161 sub mymediacfg_version {
162 88 ▶ $VERSION =~ /^(\d+)\./;
Subroutine mymediacfg_version: called CC=1 SCAR=0.0
Pod undocumented
163 88 $1
164 }
165  
166 =head2 MDV::Distribconf->new($root)
167  
168 Returns a new MDV::Distribconf object, C<$root> being the top level
169 directory of the tree.
170  
171 =cut
172  
173 sub new {
174 49 ▶ my ($class, $path, $mediacfg_version) = @_;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
175 49 my $distrib = {
176 root => $path,
177 infodir => '',
178 mediadir => '',
179 type => '', # mdk vs mdv
180 mediainfodir => '',
181 cfg => new Config::IniFiles(-default => 'media_info', -allowcontinue => 1),
182 };
183  
184 49 ▶ if (!defined($mediacfg_version)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mediacfg_version) 46 3 49
185 46 $distrib->{cfg}->newval('media_info', 'mediacfg_version', mymediacfg_version());
186 }
187  
188 49 bless($distrib, $class)
189 }
190  
191 =head2 $distrib->load()
192  
193 Finds and loads the configuration of the distrib: locate the path where
194 information is found; if available loads F<media.cfg>, if available loads
195 F<hdlists>.
196  
197 Returns 1 on success, 0 error (that is, if no directory containing media
198 information is found, or if no F<media.cfg>, neither F<hdlists> files are
199 found).
200  
201 See also L<loadtree>, L<parse_hdlists> and L<parse_mediacfg>.
202  
203 =cut
204  
205 sub load {
206 44 ▶ my ($distrib) = @_;
Subroutine load: called CC=4 SCAR=14.1
Pod documented
207 44 ▶ $distrib->loadtree() or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$distrib->loadtree or return 0 1 43 44
208 43 ▶ $distrib->parse_mediacfg() || $distrib->parse_hdlists() or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$distrib->parse_mediacfg or $distrib->parse_hdlists or return 0 0 43 43
Condition66%2/3
$distrib->parse_mediacfg or $distrib->parse_hdlists
l!l&&r!l&&!r
20230
MC/DC0%0/2
$distrib->parse_mediacfg or $distrib->parse_hdlists
$distrib->parse_mediacfg $distrib->parse_hdlists
Truth table66%2/3
A or B
A= $distrib->parse_mediacfgB= $distrib->parse_hdlists
ABresult
1X1
011
000
209 43 return 1;
210 }
211  
212 =head2 $distrib->loadtree()
213  
214 Tries to find a valid media information directory, and set infodir and
215 mediadir. Returns 1 on success, 0 if no media information directory was
216 found.
217  
218 =cut
219  
220 sub loadtree {
221 44 ▶ my ($distrib) = @_;
Subroutine loadtree: called CC=3 SCAR=11.0
Pod documented
222  
223 44 ▶ if (-d "$distrib->{root}/media/media_info") {
Branch: 2 branches
BranchTrueFalseTotal
if (-d "$distrib->{'root'}/media/media_info") { } 29 15 44
elsif (-d "$distrib->{'root'}/Mandrake/base") { } 14 1 15
224 29 $distrib->{infodir} = 'media/media_info';
225 29 $distrib->{mediadir} = 'media';
226 29 $distrib->{mediainfodir} = '/media_info';
227 29 $distrib->{type} = 'mandriva';
228 } elsif (-d "$distrib->{root}/Mandrake/base") {
229 14 $distrib->{infodir} = 'Mandrake/base';
230 14 $distrib->{mediadir} = 'Mandrake';
231 14 $distrib->{mediainfodir} = '';
232 14 $distrib->{type} = 'mandrake';
233 } else {
234 1 return 0;
235 }
236 43 return 1;
237 }
238  
239 =head2 check_mediacfg_version($wanted_version)
240  
241 Check that the current distrib uses this version or lesser, which means it is
242 supported.
243  
244 =cut
245  
246 sub check_mediacfg_version {
247 21 ▶ my ($distrib, $wanted_version) = @_;
Subroutine check_mediacfg_version: called CC=3 SCAR=11.4
Pod documented
248  
249 # Check wanted version is <= than the module
250 # Otherwise the module can't properly handle it
251 21 ▶ return 0 if (mymediacfg_version() < $wanted_version);
Branch: 1 branch
BranchTrueFalseTotal
if mymediacfg_version() < $wanted_version 0 21 21
252  
253 21 ▶ return 0 if ($wanted_version < $distrib->getvalue(undef, 'mediacfg_version'));
Branch: 1 branch
BranchTrueFalseTotal
if $wanted_version < $distrib->getvalue(undef, "mediacfg_version") 0 21 21
254  
255 21 return 1
256 }
257  
258 =head2 $distrib->settree($spec)
259  
260 Virtual set the internal structure of the distrib.
261  
262 $spec can be 'mandrake' or 'mandriva' to automatically load a know structure
263 (old and new fascion, or a hashref:
264  
265 mediadir => 'media',
266 infodir => 'media/media_info',
267  
268 =cut
269  
270 sub settree {
271 4 ▶ my ($distrib, $spec) = @_;
Subroutine settree: called CC=6 SCAR=17.9
Pod documented
272  
273 4 ▶ if (ref($spec) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $spec eq 'HASH') { } 1 3 4
elsif ($spec and $spec =~ /mandrake/i) { } 1 2 3
274 1 foreach (qw(infodir mediadir mediainfodir)) {
275 3 ▶ $distrib->{$_} = $spec->{$_} || '';
Condition100%2/2
$spec->{$_} || ''
l!l
21
MC/DC100%1/1
$spec->{$_} || ''
$spec->{$_}
Truth table100%2/2
A
A= $spec->{$_}
Aresult
11
00
276 }
277 ▶ } elsif ($spec && $spec =~ /mandrake/i) {
Condition100%3/3
$spec and $spec =~ /mandrake/i
!ll&&!rl&&r
111
MC/DC100%2/2
$spec and $spec =~ /mandrake/i
$spec $spec =~ /mandrake/i
Truth table100%3/3
A and B
A= $specB= $spec =~ /mandrake/i
ABresult
0X0
100
111
278 1 $distrib->{infodir} = 'Mandrake/base';
279 1 $distrib->{mediadir} = 'Mandrake';
280 1 $distrib->{type} = 'mandrake';
281 1 $distrib->{mediainfodir} = '';
282 } else { # finally it can be everything, we do not care
283 2 $distrib->{infodir} = 'media/media_info';
284 2 $distrib->{mediadir} = 'media';
285 2 $distrib->{mediainfodir} = '/media_info';
286 2 $distrib->{type} = 'mandriva';
287 }
288 }
289  
290  
291 =head2 $distrib->parse_hdlists($hdlists)
292  
293 Reads the F<hdlists> file whose path is given by the parameter $hdlist,
294 or, if no parameter is specified, the F<hdlists> file found in the media
295 information directory of the distribution. Returns 1 on success, 0 if no
296 F<hdlists> can be found or parsed.
297  
298 =cut
299  
300 sub parse_hdlists {
301 23 ▶ my ($distrib, $hdlists) = @_;
Subroutine parse_hdlists: called CC=11 SCAR=24.8
Pod documented
302 23 ▶ $hdlists ||= "$distrib->{root}/$distrib->{infodir}/hdlists";
Condition50%1/2
$hdlists ||= qq[$distrib->{"root"}/$distrib->{"infodir"}/hdlists]
l!l
023
MC/DC0%0/1
$hdlists ||= qq[$distrib->{"root"}/$distrib->{"infodir"}/hdlists]
$hdlists
Truth table50%1/2
A
A= $hdlists
Aresult
11
00
303  
304 23 ▶ open my $h_hdlists, "<", $hdlists
Branch: 1 branch
BranchTrueFalseTotal
open my $h_hdlists, "<", $hdlists or return 0 0 23 23
305 or return 0;
306 23 $distrib->{cfg} = new Config::IniFiles( -default => 'media_info', -allowcontinue => 1);
307 23 my $i = 0;
308 23 foreach (<$h_hdlists>) {
309 56 s/#.*//; s/^\s*//;
310 56 chomp;
311 56 ▶ length or next;
Branch: 1 branch
BranchTrueFalseTotal
length $_ or next 0 56 56
312 56 my ($options, %media);
313 56 ($options, @media{qw(hdlist path name size)}) = /^\s*(?:(.*):)?(\S+)\s+(\S+)\s+([^(]*)(?:\s+\((\w+)\))?$/;
314 56 ▶ if (!$media{hdlist}) { # Hack because hdlists format really sucks
Branch: 1 branch
BranchTrueFalseTotal
unless ($media{"hdlist"}) 3 53 56
315 3 ($options, @media{qw(hdlist path name size)}) = /^\s*(?:(.*):)?(\S+)\s+(\S+)\s+(.*)$/;
316 }
317 56 ▶ if ($options) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options) 0 56 56
318 0 $media{$_} = 1 foreach split /:/, $options;
319 }
320 56 $media{name} =~ s/\s*$//;
321 56 $media{path} =~ s!^$distrib->{mediadir}/+!!;
322 56 ▶ foreach (qw(hdlist name size), $options ? split(/:/, $options) : ()) {
Branch: 1 branch
BranchTrueFalseTotal
$options ? : 0 56 56
323 168 ▶ $distrib->{cfg}->newval($media{path}, $_, $media{$_})
Branch: 1 branch
BranchTrueFalseTotal
$distrib->{"cfg"}->newval($media{"path"}, $_, $media{$_}) or die "Can't set value [$_]\n" 0 168 168
324 or die "Can't set value [$_]\n";
325 }
326 }
327 23 close($h_hdlists);
328  
329 23 return 1;
330 }
331  
332 =head2 $distrib->parse_version($fversion)
333  
334 Reads the F<VERSION> file whose path is given by the parameter $fversion,
335 or, if no parameter is specified, the F<VERSION> file found in the media
336 information directory of the distribution. Returns 1 on success, 0 if no
337 F<VERSION> can be found or parsed.
338  
339 =cut
340  
341 sub parse_version {
342 0 ▶ my ($distrib, $fversion) = @_;
Subroutine parse_version: not called CC=3 SCAR=24.8
Pod documented
343 0 ▶ $fversion ||= $distrib->getfullpath(undef, 'VERSION');
Condition0%0/3
$fversion ||= $distrib->getfullpath(undef, "VERSION")
l!l&&r!l&&!r
000
MC/DC0%0/2
$fversion ||= $distrib->getfullpath(undef, "VERSION")
$fversion $distrib->getfullpath(undef, "VERSION")
Truth table0%0/3
A ||= B
A= $fversionB= $distrib->getfullpath(undef, "VERSION")
ABresult
1X1
011
000
344 0 ▶ open my $h_ver, "<", $fversion
Branch: 1 branch
BranchTrueFalseTotal
open my $h_ver, "<", $fversion or return 0 0 0 0
345 or return 0;
346 0 my $l = <$h_ver>;
347 0 close $h_ver;
348 0 chomp $l;
349 # XXX heuristics ahead. This breaks regularly.
350 0 my ($version, $branch, $product, $arch) = $l =~ /^(?:mandrake|mandriva) ?linux\s+(\w+)\s+([^- ]*)-([^- ]*)-([^- ]*)/i;
351 0 $distrib->{cfg}->newval('media_info', 'version', $version);
352 0 $distrib->{cfg}->newval('media_info', 'branch', $branch);
353 0 $distrib->{cfg}->newval('media_info', 'product', $product);
354 0 $distrib->{cfg}->newval('media_info', 'arch', $arch);
355 0 return 1;
356 }
357  
358 =head2 $distrib->parse_mediacfg($mediacfg)
359  
360 Reads the F<media.cfg> file whose path is given by the parameter
361 $mediacfg, or, if no parameter is specified, the F<media.cfg> file found
362 in the media information directory of the distribution. Returns 1 on
363 success, 0 if no F<media.cfg> can be found or parsed.
364  
365 =cut
366  
367 sub parse_mediacfg {
368 44 ▶ my ($distrib, $mediacfg) = @_;
Subroutine parse_mediacfg: called CC=5 SCAR=16.6
Pod documented
369 44 ▶ $mediacfg ||= "$distrib->{root}/$distrib->{infodir}/media.cfg";
Condition100%2/2
$mediacfg ||= qq[$distrib->{"root"}/$distrib->{"infodir"}/media.cfg]
l!l
143
MC/DC100%1/1
$mediacfg ||= qq[$distrib->{"root"}/$distrib->{"infodir"}/media.cfg]
$mediacfg
Truth table100%2/2
A
A= $mediacfg
Aresult
11
00
370 (-f $mediacfg && -r _) &&
371 44 ▶ ($distrib->{cfg} = new Config::IniFiles( -file => $mediacfg, -default => 'media_info', -allowcontinue => 1))
Branch: 1 branch
BranchTrueFalseTotal
-f $mediacfg and -r _ and $distrib->{"cfg"} = "Config::IniFiles"->new("-file", $mediacfg, "-default", "media_info", "-allowcontinue", 1) or return 0 0 21 21
Condition66%4/6
-f $mediacfg and -r _ and $distrib->{"cfg"} = "Config::IniFiles"->new("-file", $mediacfg, "-default", "media_info", "-allowcontinue", 1)
!ll&&!rl&&r
23021
-f $mediacfg and -r _
!ll&&!rl&&r
23021
MC/DC33%1/3
-f $mediacfg and -r _ and $distrib->{"cfg"} = "Config::IniFiles"->new("-file", $mediacfg, "-default", "media_info", "-allowcontinue", 1)
-f $mediacfg -r _ $distrib->{"cfg"} = "Config::IniFiles"->new("-file", $mediacfg, "-default", "media_info", "-allowcontinue", 1)
Truth table50%2/4
A and B and C
A= -f $mediacfgB= -r _C= $distrib->{"cfg"} = "Config::IniFiles"->new("-file", $mediacfg, "-default", "media_info", "-allowcontinue", 1)
ABCresult
0XX0
10X0
1100
1111
372 or return 0;
373  
374 21 return $distrib->check_mediacfg_version(mymediacfg_version());
375 }
376  
377 =head2 $distrib->listmedia()
378  
379 Returns an array of existing media in the configuration
380  
381 =cut
382  
383 sub listmedia {
384 89 ▶ my ($distrib) = @_;
Subroutine listmedia: called CC=1 SCAR=0.0
Pod documented
385 89 return grep { $_ ne 'media_info' } $distrib->{cfg}->Sections;
386 }
387  
388 =head2 $distrib->mediaexists($media)
389  
390 Return true if $media exists
391  
392 =cut
393  
394 sub mediaexists {
395 1772 ▶ my ($distrib, $media) = @_;
Subroutine mediaexists: called CC=3 SCAR=11.0
Pod documented
396 1772 ▶ $media ||= 'media_info';
Condition100%2/2
$media ||= "media_info"
l!l
1504268
MC/DC100%1/1
$media ||= "media_info"
$media
Truth table100%2/2
A
A= $media
Aresult
11
00
397 1772 ▶ return ($media eq 'media_info' || $distrib->{cfg}->SectionExists($media));
Condition66%2/3
$media eq 'media_info' || $distrib->{'cfg'}->SectionExists($media)
l!l&&r!l&&!r
11915810
MC/DC0%0/2
$media eq 'media_info' || $distrib->{'cfg'}->SectionExists($media)
$media eq 'media_info' $distrib->{'cfg'}->SectionExists($media)
Truth table66%2/3
A || B
A= $media eq 'media_info'B= $distrib->{'cfg'}->SectionExists($media)
ABresult
1X1
011
000
398 }
399  
400 sub _expand {
401 296 ▶ my ($self, $media, $value, $level) = @_;
Subroutine _expand: called CC=8 SCAR=20.8
402 296 ▶ $value or return $value; # being lazy
Branch: 1 branch
BranchTrueFalseTotal
$value or return $value 40 256 296
403 # unsupported if < 3
404 256 ▶ $self->getvalue(undef, 'mediacfg_version') < 3 and return $value;
Branch: 1 branch
BranchTrueFalseTotal
$self->getvalue(undef, "mediacfg_version") < 3 and return $value 223 33 256
405 33 ▶ $media ||= 'media_info';
Condition100%2/2
$media ||= "media_info"
l!l
312
MC/DC100%1/1
$media ||= "media_info"
$media
Truth table100%2/2
A
A= $media
Aresult
11
00
406 33 ▶ $level ||= 0; # avoid infinite loop
Condition100%2/2
$level ||= 0
l!l
231
MC/DC100%1/1
$level ||= 0
$level
Truth table100%2/2
A
A= $level
Aresult
11
00
407 33 ▶ ++$level >= 15 and return $value;
Branch: 1 branch
BranchTrueFalseTotal
++$level >= 15 and return $value 0 33 33
408  
409 33 $value =~ s@\%{(\w+)}@
410 3 ▶ $self->getvalue($media, $1) || '%{' . $1 . '}';
Branch: 1 branch
BranchTrueFalseTotal
$self->getvalue($media, $1) or '%{' . $1 . '}' 1 2 3
411 @eg;
412 33 $value =~ s@\${(\w+)}@
413 2 ▶ $self->getvalue('media_info', $1, $level) || '${' . $1 . '}';
Branch: 1 branch
BranchTrueFalseTotal
$self->getvalue("media_info", $1, $level) or '${' . $1 . '}' 0 2 2
414 @eg;
415  
416 33 $value
417 }
418  
419 =head2 $distrib->getvalue($media, $var)
420  
421 Returns the $var value for $media, or C<undef> if the value is not set.
422  
423 If $var is "name", "hdlist" or "synthesis", and if the value is not explicitly
424 defined, the return value is expanded from $media.
425  
426 If $media is "media_info" or C<undef>, you'll get the global value.
427  
428 This function doesn't cares about path, see L<getpath> for that.
429  
430 =cut
431  
432 sub getvalue {
433 1257 ▶ my ($distrib, $media, $var, $level) = @_;
Subroutine getvalue: called CC=32 SCAR=37.9
Pod documented
434 1257 ▶ $media ||= 'media_info';
Condition100%2/2
$media ||= "media_info"
l!l
398859
MC/DC100%1/1
$media ||= "media_info"
$media
Truth table100%2/2
A
A= $media
Aresult
11
00
435  
436 1257 ▶ $distrib->mediaexists($media) or return;
Branch: 1 branch
BranchTrueFalseTotal
$distrib->mediaexists($media) or return 0 1257 1257
437  
438 1257 my $default = "";
439 1257 for ($var) {
440 1257 ▶ /^synthesis$/ and $default = 'synthesis.' . lc($distrib->getvalue($media, 'hdlist', $level));
Branch: 1 branch
BranchTrueFalseTotal
/^synthesis$/ and $default = 'synthesis.' . lc($distrib->getvalue($media, "hdlist", $level)) 2 1255 1257
441 1257 ▶ /^hdlist$/ and $default = 'hdlist_' . lc($distrib->getvalue($media, 'name', $level)) . '.cz';
Branch: 1 branch
BranchTrueFalseTotal
/^hdlist$/ and $default = 'hdlist_' . lc($distrib->getvalue($media, "name", $level)) . '.cz' 47 1210 1257
442 1257 ▶ /^pubkey$/ and $default = 'pubkey_' . lc($distrib->getvalue($media, 'name', $level));
Branch: 1 branch
BranchTrueFalseTotal
/^pubkey$/ and $default = 'pubkey_' . lc($distrib->getvalue($media, "name", $level)) 4 1253 1257
443 1257 ▶ /^(pubkey|hdlist|synthesis)$/ and do {
Branch: 1 branch
BranchTrueFalseTotal
/^(pubkey|hdlist|synthesis)$/ and do { $default =~ s[[/ ]+][_]g } 53 1204 1257
444 53 $default =~ s![/ ]+!_!g;
445 };
446 1257 ▶ /^name$/ and do {
Branch: 1 branch
BranchTrueFalseTotal
/^name$/ and do { $default = $media; $default =~ s[[/ ]+][_]g; last } 61 1196 1257
447 61 $default = $media;
448 61 $default =~ s![/ ]+!_!g;
449 61 last;
450 };
451 1196 ▶ /^productid$/ and do {
Branch: 1 branch
BranchTrueFalseTotal
/^productid$/ and do { return join(",", map({"$_=" . ($distrib->getvalue(undef, $_) || "");} "vendor", "distribution", "type", "version", "branch", "release", "arch", "product")) } 0 1196 1196
452 0 ▶ return join(',', map { "$_=" . ($distrib->getvalue(undef, $_) || '') }
Condition0%0/2
$distrib->getvalue(undef, $_) || ''
l!l
00
MC/DC0%0/1
$distrib->getvalue(undef, $_) || ''
$distrib->getvalue(undef, $_)
Truth table0%0/2
A
A= $distrib->getvalue(undef, $_)
Aresult
11
00
453 qw(vendor distribution type version branch release arch product));
454 };
455 1196 ▶ /^path$/ and return $media;
Branch: 1 branch
BranchTrueFalseTotal
/^path$/ and return $media 187 1009 1196
456 1009 ▶ /^root$/ and return $distrib->{root};
Branch: 1 branch
BranchTrueFalseTotal
/^root$/ and return $distrib->{"root"} 245 764 1009
457 /^mediacfg_version$/ and
458 764 ▶ return $distrib->{cfg}->val('media_info', 'mediacfg_version') || 1;
Branch: 1 branch
BranchTrueFalseTotal
/^mediacfg_version$/ and return $distrib->{"cfg"}->val("media_info", "mediacfg_version") || 1 533 231 764
Condition100%2/2
$distrib->{'cfg'}->val('media_info', 'mediacfg_version') || 1
l!l
253280
MC/DC100%1/1
$distrib->{'cfg'}->val('media_info', 'mediacfg_version') || 1
$distrib->{'cfg'}->val('media_info', 'mediacfg_version')
Truth table100%2/2
A
A= $distrib->{'cfg'}->val('media_info', 'mediacfg_version')
Aresult
11
00
459 231 ▶ /^VERSION$/ and do { $default = 'VERSION'; last };
Branch: 1 branch
BranchTrueFalseTotal
/^VERSION$/ and do { $default = "VERSION"; last } 4 227 231
460 227 ▶ /^product.id$/ and do { $default = 'product.id'; last };
Branch: 1 branch
BranchTrueFalseTotal
/^product.id$/ and do { $default = "product.id"; last } 0 227 227
461 227 ▶ /^product$/ and do { $default = 'Download'; last };
Branch: 1 branch
BranchTrueFalseTotal
/^product$/ and do { $default = "Download"; last } 0 227 227
462 /^(MD5SUM|depslist.ordered|compss|provides)$/
463 227 ▶ and do { $default = $_; last };
Branch: 1 branch
BranchTrueFalseTotal
/^(MD5SUM|depslist.ordered|compss|provides)$/ and do { $default = $_; last } 0 227 227
464 227 ▶ /^(?:tag|branch)$/ and do { $default = ''; last };
Branch: 1 branch
BranchTrueFalseTotal
/^(?:tag|branch)$/ and do { $default = ""; last } 0 227 227
465 227 ▶ /^(?:media|info)dir$/ and do { $default = $distrib->{$var}; last };
Branch: 1 branch
BranchTrueFalseTotal
/^(?:media|info)dir$/ and do { $default = $distrib->{$var}; last } 8 219 227
466 219 ▶ /^os$/ and do { $default = 'linux'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/^os$/ and do { $default = "linux"; last } 19 200 219
467 200 ▶ /^gnu$/ and do { $default = 1; last; };
Branch: 1 branch
BranchTrueFalseTotal
/^gnu$/ and do { $default = 1; last } 19 181 200
468 181 ▶ /^vendor$/ and do { $default = $distrib->{type}; last; };
Branch: 1 branch
BranchTrueFalseTotal
/^vendor$/ and do { $default = $distrib->{"type"}; last } 19 162 181
469 162 ▶ /^arch$/ and do { $default = undef; last; };
Branch: 1 branch
BranchTrueFalseTotal
/^arch$/ and do { $default = undef; last } 57 105 162
470 105 ▶ /^platform$/ and do {
Branch: 1 branch
BranchTrueFalseTotal
/^platform$/ and do { my $arch = $distrib->getvalue($media, "arch"); $default = defined $arch ? sprintf("%s-%s-%s%s", $arch, $distrib->getvalue($media, "vendor"), $distrib->getvalue($media, "os"), $distrib->getvalue($media, "gnu") ? "-gnu" : "") : undef; last } 19 86 105
471 19 my $arch = $distrib->getvalue($media, 'arch');
472 19 ▶ $default = defined($arch) ? sprintf('%s-%s-%s%s',
Branch: 2 branches
BranchTrueFalseTotal
defined $arch ? : 19 0 19
$distrib->getvalue($media, 'gnu') ? : 19 0 19
473 $arch,
474 $distrib->getvalue($media, 'vendor'),
475 $distrib->getvalue($media, 'os'),
476 $distrib->getvalue($media, 'gnu') ? '-gnu' : '',
477 ) : undef;
478 19 last;
479 };
480 86 ▶ /^rpmsrate$/ and do { $default = 'rpmsrate'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/^rpmsrate$/ and do { $default = "rpmsrate"; last } 0 86 86
481 86 ▶ /^description$/ and do { $default = 'description'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/^description$/ and do { $default = "description"; last } 4 82 86
482 82 ▶ /^provide$/ and do { $default = 'description'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/^provide$/ and do { $default = "description"; last } 0 82 82
483 82 ▶ /^depslist.ordered$/ and do { $default = 'description'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/^depslist.ordered$/ and do { $default = "description"; last } 0 82 82
484 }
485 292 return $distrib->_expand($media, $distrib->{cfg}->val($media, $var, $default), $level);
486 }
487  
488 =head2 $distrib->getpath($media, $var)
489  
490 Gives relative path of $var from the root of the distrib. This function is
491 useful to know where files are actually located. It takes care of location
492 of media, location of index files, and paths set in the configuration.
493  
494 =cut
495  
496 sub getpath {
497 513 ▶ my ($distrib, $media, $var) = @_;
Subroutine getpath: called CC=8 SCAR=20.8
Pod documented
498 513 ▶ $distrib->mediaexists($media) or return;
Branch: 1 branch
BranchTrueFalseTotal
$distrib->mediaexists($media) or return 0 513 513
499 513 ▶ $var ||= ""; # Avoid undef value
Condition50%1/2
$var ||= ""
l!l
5130
MC/DC0%0/1
$var ||= ""
$var
Truth table50%1/2
A
A= $var
Aresult
11
00
500 513 my $val = $distrib->getvalue($media, $var);
501 513 ▶ $var =~ /^(?:root|VERSION|product\.id|(?:media|info)dir)$/ and return $val;
Branch: 1 branch
BranchTrueFalseTotal
$var =~ /^(?:root|VERSION|product\.id|(?:media|info)dir)$/ and return $val 257 256 513
502 256 ▶ my $thispath = $var eq 'path' ? $distrib->{mediadir} : $distrib->{infodir};
Branch: 1 branch
BranchTrueFalseTotal
$var eq 'path' ? : 187 69 256
503 256 ▶ if ($distrib->getvalue(undef, 'mediacfg_version') >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distrib->getvalue(undef, 'mediacfg_version') >= 2) { } 135 121 256
504 135 return $thispath . '/' . $val;
505 } else {
506 return ($val =~ m!/! ? "" :
507 ($var eq 'path' ? $distrib->{mediadir} : $distrib->{infodir} )
508 121 ▶ . "/") . $val;
Branch: 2 branches
BranchTrueFalseTotal
$val =~ m[/] ? : 13 108 121
$var eq 'path' ? : 54 54 108
509 }
510 }
511  
512 =head2 $distrib->getmediapath($media, $var)
513  
514 This function does the same than getpath except it return the path proper
515 to the media for files having doble location (index for example).
516  
517 =cut
518  
519  
520 sub getmediapath {
521 177 ▶ my ($distrib, $media, $var) = @_;
Subroutine getmediapath: called CC=2 SCAR=7.0
Pod documented
522 177 my %files = (
523 pubkey => 'pubkey',
524 hdlist => 'hdlist.cz',
525 synthesis => 'synthesis.hdlist.cz',
526 MD5SUM => 'MD5SUM',
527 infodir => '',
528 );
529 177 ▶ $var eq 'path' and return $distrib->getpath($media, 'path');
Branch: 1 branch
BranchTrueFalseTotal
$var eq "path" and return $distrib->getpath($media, "path") 0 177 177
530 177 return $distrib->getpath($media, 'path') . $distrib->{mediainfodir} . "/$files{$var}";
531 }
532  
533 =head2 $distrib->getfullpath($media, $var)
534  
535 Does the same thing than getpath(), but the return value will be
536 prefixed by the 'root' path. This is a shortcut for:
537  
538 $distrib->getpath(undef, 'root') . '/' . $distrib->getpath($media, $var).
539  
540 =cut
541  
542 sub getfullpath {
543 22 ▶ my $distrib = shift;
Subroutine getfullpath: called CC=4 SCAR=14.9
Pod documented
544 22 ▶ my $path = $distrib->getpath(@_) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $path = $distrib->getpath(@_) or return 0 22 22
545 22 ▶ return $distrib->getpath(undef, 'root') if (($_[1] || '') eq 'root');
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] || "") eq "root" 0 22 22
Condition50%1/2
$_[1] || ''
l!l
220
MC/DC0%0/1
$_[1] || ''
$_[1]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
546 22 return $distrib->getpath(undef, 'root') . '/' . $path;
547 }
548  
549 =head2 $distrib->getfullmediapath($media, $var)
550  
551 This function does the same than getpath except it return the path proper
552 to the media for files having doble location (index for example).
553  
554 =cut
555  
556 sub getfullmediapath {
557 10 ▶ my $distrib = shift;
Subroutine getfullmediapath: called CC=2 SCAR=7.1
Pod documented
558 10 ▶ my $path = $distrib->getmediapath(@_) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $path = $distrib->getmediapath(@_) or return 0 10 10
559 10 return $distrib->getpath(undef, 'root') . '/' . $path;
560 }
561  
562 =head2 $distrib->getdpath($media, $var)
563  
564 Does the same thing than getpath(), but the return always return the best for
565 file having twice location (index).
566  
567 You may want to use this function to ensure you allways the good value.
568  
569 =cut
570  
571 sub getdpath {
572 213 ▶ my ($distrib, $media, $var) = @_;
Subroutine getdpath: called CC=3 SCAR=11.0
Pod documented
573  
574 213 ▶ if ($var =~ /^(hdlist|synthesis|pubkey|MD5SUM)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var =~ /^(hdlist|synthesis|pubkey|MD5SUM)$/) { } 197 16 213
575 197 ▶ if ($distrib->{type} eq 'mandriva') {
Branch: 1 branch
BranchTrueFalseTotal
if ($distrib->{'type'} eq 'mandriva') { } 163 34 197
576 163 return $distrib->getmediapath($media, $var);
577 } else {
578 34 return $distrib->getpath($media, $var);
579 }
580 } else {
581 16 return $distrib->getpath($media, $var);
582 }
583 }
584  
585 =head2 $distrib->getfulldpath($media, $var)
586  
587 Does the same thing than getfullpath(), but the return always return the best
588 for file having twice location (index).
589  
590 You may want to use this function to ensure you allways the good value.
591  
592 =cut
593  
594 sub getfulldpath {
595 197 ▶ my $distrib = shift;
Subroutine getfulldpath: called CC=2 SCAR=7.1
Pod documented
596 197 ▶ my $path = $distrib->getdpath(@_) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $path = $distrib->getdpath(@_) or return 0 197 197
597 197 return $distrib->getpath(undef, 'root') . '/' . $path;
598 }
599  
600  
601 5 1;
602  
603 __END__
« Distribconf/Checks.pm ↑ Summary Distribconf/Utils.pm »