summaryrefslogtreecommitdiffstats
path: root/zarb-ml/mageia-dev/attachments/20110128/77feba8c/attachment.ksh
diff options
context:
space:
mode:
Diffstat (limited to 'zarb-ml/mageia-dev/attachments/20110128/77feba8c/attachment.ksh')
-rw-r--r--zarb-ml/mageia-dev/attachments/20110128/77feba8c/attachment.ksh88
1 files changed, 88 insertions, 0 deletions
diff --git a/zarb-ml/mageia-dev/attachments/20110128/77feba8c/attachment.ksh b/zarb-ml/mageia-dev/attachments/20110128/77feba8c/attachment.ksh
new file mode 100644
index 000000000..34ba18f85
--- /dev/null
+++ b/zarb-ml/mageia-dev/attachments/20110128/77feba8c/attachment.ksh
@@ -0,0 +1,88 @@
+#!/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;