#!/usr/bin/perl use Getopt::Long; use Pod::Usage; my %options; GetOptions( "l" => sub { $options{local} = 1 }, ) or pod2usage(1); my ($action, @args) = @ARGV; my $mdvsoft = MDV::Soft->new(%options); if ($mdvsoft->can($action)) { $mdvsoft->$action(@args); } else { pod2usage(1); } exit(0); package MDV::Soft; use SVN::Client; use File::Temp qw(tempdir); use MDK::Common; sub new { my ($class, %options) = @_; bless { svn => SVN::Client->new, branch => 'trunk', root => 'svn+ssh://svn.mandriva.com/svn/soft', opts => \%options, }, $class; } sub export { my ($self, $name, $o_destdir) = @_; unless ($name) { warn "Can't export without a module name"; return; } my $module_url = $self->{opts}{local} ? $ENV{PWD} : $self->{root} . '/' . $name . '/' . $self->{branch}; my $tmp_dir = tempdir(CLEANUP => 1); my $export_dir = $tmp_dir . '/' . $name; $self->{svn}->export($module_url, $export_dir, undef, undef) or die "Can't checkout $module_url"; my $config = read_config($export_dir); my $distname = $config->{NAME} . '-' . $config->{VERSION}; $distname .= '-' . $config->{RELEASE} if $config->{RELEASE} > 1; rename($export_dir, $tmp_dir . '/' . $distname); my $tarball = $distname . '.tar.bz2'; $tarball = $o_destdir . '/' . $tarball if -d $o_destdir; system('tar', '-C', $tmp_dir, '-cjf', $tarball, $distname) == 0 or die "Can't compress $distname"; print "Exported $tarball\n"; 1; } sub read_config { my ($config_dir) = @_; my $config = {}; my @mandatory_vars = qw(NAME VERSION); my @config_vars = (@mandatory_vars, qw(RELEASE)); my $config_name = 'Makefile'; foreach my $line (cat_($config_dir . '/' . $config_name)) { foreach my $var (@config_vars) { $line =~ /^$var\s*:?=\s*([^#]+)/ and $config->{$var} = chomp_($1); } } foreach (@mandatory_vars) { $config->{$_} or die "Can't find config variable $_ in $config_name"; } $config; } 1;