diff options
author | Olivier Thauvin <nanardon@mandriva.org> | 2006-08-21 21:17:54 +0000 |
---|---|---|
committer | Olivier Thauvin <nanardon@mandriva.org> | 2006-08-21 21:17:54 +0000 |
commit | f54fb53b07ecaced9bfbe450c6b2dc982a6d9fb7 (patch) | |
tree | 66c825ff5006181cb8aa9401e71c9d91a8cead73 | |
parent | 2e2452a00630e69c1abe5df015cb4574f9cc10ac (diff) | |
download | perl-MDV-Distribconf-f54fb53b07ecaced9bfbe450c6b2dc982a6d9fb7.tar perl-MDV-Distribconf-f54fb53b07ecaced9bfbe450c6b2dc982a6d9fb7.tar.gz perl-MDV-Distribconf-f54fb53b07ecaced9bfbe450c6b2dc982a6d9fb7.tar.bz2 perl-MDV-Distribconf-f54fb53b07ecaced9bfbe450c6b2dc982a6d9fb7.tar.xz perl-MDV-Distribconf-f54fb53b07ecaced9bfbe450c6b2dc982a6d9fb7.zip |
- on the road for 3.023.02
-rw-r--r-- | lib/MDV/Distribconf.pm | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/lib/MDV/Distribconf.pm b/lib/MDV/Distribconf.pm index fc7c5cc..87f33c3 100644 --- a/lib/MDV/Distribconf.pm +++ b/lib/MDV/Distribconf.pm @@ -2,7 +2,7 @@ package MDV::Distribconf; # $Id$ -our $VERSION = '2.03'; +our $VERSION = '3.02'; =head1 NAME @@ -375,6 +375,37 @@ sub listmedia { return grep { $_ ne 'media_info' } $distrib->{cfg}->Sections; } +=head2 $distrib->mediaexists($media) + +Return true if $media exists + +=cut + +sub mediaexists { + my ($distrib, $media) = @_; + $media ||= 'media_info'; + return ($media eq 'media_info' || $distrib->{cfg}->SectionExists($media)); +} + +sub _expand { + my ($self, $media, $value, $level) = @_; + $value or return $value; # being lazy + # unsupported if < 3 + $self->getvalue(undef, 'mediacfg_version') < 3 and return $value; + $media ||= 'media_info'; + $level ||= 0; # avoid infinite loop + ++$level >= 15 and return $value; + + $value =~ s[\%{(\w+)}][ + $self->getvalue($media, $1) || '%{' . $1 . '}'; + ]eg; + $value =~ s[\${(\w+)}][ + $self->getvalue('media_info', $1, $level) || '${' . $1 . '}'; + ]eg; + + $value +} + =head2 $distrib->getvalue($media, $var) Returns the $var value for $media, or C<undef> if the value is not set. @@ -389,25 +420,28 @@ This function doesn't cares about path, see L<getpath> for that. =cut sub getvalue { - my ($distrib, $media, $var) = @_; + my ($distrib, $media, $var, $level) = @_; $media ||= 'media_info'; + $distrib->mediaexists($media) or return; + my $default = ""; for ($var) { - /^synthesis$/ and $default = 'synthesis.' . lc($distrib->getvalue($media, 'hdlist')); - /^hdlist$/ and $default = 'hdlist_' . lc($distrib->getvalue($media, 'name')) . '.cz'; - /^pubkey$/ and $default = 'pubkey_' . lc($distrib->getvalue($media, 'name')); + /^synthesis$/ and $default = 'synthesis.' . lc($distrib->getvalue($media, 'hdlist', $level)); + /^hdlist$/ and $default = 'hdlist_' . lc($distrib->getvalue($media, 'name', $level)) . '.cz'; + /^pubkey$/ and $default = 'pubkey_' . lc($distrib->getvalue($media, 'name', $level)); /^name$/ and $default = $media; $default =~ s![/ ]+!_!g; /^path$/ and return $media; /^root$/ and return $distrib->{root}; - /^mediacfg_version$/ and do { $default = '1'; last }; + /^mediacfg_version$/ and + return $distrib->{cfg}->val('media_info', 'mediacfg_version') || 1; /^VERSION$/ and do { $default = 'VERSION'; last }; /^product$/ and do { $default = 'Download'; last }; /^(?:tag|branch)$/ and do { $default = ''; last }; /^(?:media|info)dir$/ and do { $default = $distrib->{$var}; last }; } - return $distrib->{cfg}->val($media, $var, $default); + return $distrib->_expand($media, $distrib->{cfg}->val($media, $var, $default), $level); } =head2 $distrib->getpath($media, $var) @@ -420,6 +454,7 @@ of media, location of index files, and paths set in the configuration. sub getpath { my ($distrib, $media, $var) = @_; + $distrib->mediaexists($media) or return; $var ||= ""; # Avoid undef value my $val = $distrib->getvalue($media, $var); $var =~ /^(?:root|VERSION)$/ and return $val; @@ -444,7 +479,8 @@ prefixed by the 'root' path. This is a shortcut for: sub getfullpath { my $distrib = shift; - return $distrib->getpath(undef, 'root') . '/' . $distrib->getpath(@_); + my $path = $distrib->getpath(@_) or return; + return $distrib->getpath(undef, 'root') . '/' . $path; } 1; @@ -454,6 +490,9 @@ __END__ =head1 SEE ALSO gendistrib(1) +L<MDV::Distribconf::Build> +L<MDV::Distribconf::MediaCFG> +L<MDV::Distribconf::Checks> =head1 AUTHOR |