diff options
author | Olivier Thauvin <nanardon@mandriva.org> | 2007-07-11 14:46:40 +0000 |
---|---|---|
committer | Olivier Thauvin <nanardon@mandriva.org> | 2007-07-11 14:46:40 +0000 |
commit | ec1cd1c50853b5204b9daffc57110ac81dbb15b5 (patch) | |
tree | af9270b1e3b008d94adc6fc2625919e13ff4122d /bin | |
parent | c90e8aa6258dea5391341e435b82bc22e895e86c (diff) | |
download | perl-MDV-Distribconf-ec1cd1c50853b5204b9daffc57110ac81dbb15b5.tar perl-MDV-Distribconf-ec1cd1c50853b5204b9daffc57110ac81dbb15b5.tar.gz perl-MDV-Distribconf-ec1cd1c50853b5204b9daffc57110ac81dbb15b5.tar.bz2 perl-MDV-Distribconf-ec1cd1c50853b5204b9daffc57110ac81dbb15b5.tar.xz perl-MDV-Distribconf-ec1cd1c50853b5204b9daffc57110ac81dbb15b5.zip |
- add a tools to edit media
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/editdistrib | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/bin/editdistrib b/bin/editdistrib new file mode 100755 index 0000000..1e9203b --- /dev/null +++ b/bin/editdistrib @@ -0,0 +1,99 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Getopt::Long; +use MDV::Distribconf::Build; +use Text::ParseWords; + +Getopt::Long::Configure("pass_through"); + +GetOptions( +); + +Getopt::Long::Configure("no_pass_through"); + +my %commandes = ( + addmedia => \&addmedia, + setvalue => \&setvalue, +); + +my $distribpath = shift(@ARGV); + +my $distrib = MDV::Distribconf::Build->new( + $distribpath +); + +if (!$distrib->load()) { + warn "cannot load distrib\n"; + $distrib->init(); +} + +if (@ARGV) { + parse_cmd(@ARGV); +} else { + # shellwords + die "interactive command not yet implemented\n"; +} + +exit(dwrite()); + +sub dwrite { + return (!( + $distrib->write_mediacfg() && + $distrib->write_hdlists() && + $distrib->write_version() && + $distrib->write_productid() +)); +} + +sub parse_cmd { + my ($cmd, @oth) = @_; + + if (! exists($commandes{$cmd})) { + return 1; + } + + @ARGV = @oth; + + my %parsed_options = (); + my %options = ( + addmedia => { + 'n|name=s' => \$parsed_options{name}, + 'arch|a=s' => \$parsed_options{arch}, + 'rpms=s' => \$parsed_options{rpms}, + 'srpms=s' => \$parsed_options{srpms}, + 'debug_for=s' => \$parsed_options{debug_for}, + }, + setvalue => { + 'm|media=s' => \$parsed_options{media}, + } + ); + + GetOptions( + %{$options{$cmd} || {}} + ); + + $commandes{$cmd}(\%parsed_options, @ARGV); +} + +sub addmedia { + my ($options, @argument) = @_; + if (!$distrib->create_media($argument[0])) { + warn "Cannot create media\n"; + return; + } + + foreach my $setting (qw(name arch rpms srpms debug_for)) { + $distrib->setvalue($argument[0], $setting, $options->{$setting}) + if ($options->{$setting}); + } +} + +sub setvalue { + my ($options, @argument) = @_; + $distrib->setvalue( + $options->{media}, + @argument, + ); +} |