diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2007-02-08 14:09:51 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2007-02-08 14:09:51 +0000 |
commit | ae36465402ce2e515d413f34e642a605cdd13a72 (patch) | |
tree | bd214b51ddc61ceec9ab683ac17ef0f0dabb88e9 | |
parent | 1afef6369d7690f5e3e2fcede85bea2b238ea0c7 (diff) | |
download | mga-youri-submit-ae36465402ce2e515d413f34e642a605cdd13a72.tar mga-youri-submit-ae36465402ce2e515d413f34e642a605cdd13a72.tar.gz mga-youri-submit-ae36465402ce2e515d413f34e642a605cdd13a72.tar.bz2 mga-youri-submit-ae36465402ce2e515d413f34e642a605cdd13a72.tar.xz mga-youri-submit-ae36465402ce2e515d413f34e642a605cdd13a72.zip |
This action plugin unpack package files somewhere.
When unpack_inside_distribution_root is set, dest_directory is relative to the distribution root.
When the package is a noarch, the wanted files are unpacked in distribution root of each archs.
eg:
unpack_installer_images:
class: Youri::Submit::Action::Unpack
options:
name: drakx-installer-images
source_subdir: /usr/lib*/drakx-installer-images
dest_directory: .
unpack_inside_distribution_root: 1
-rw-r--r-- | lib/Youri/Submit/Action/Unpack.pm | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/lib/Youri/Submit/Action/Unpack.pm b/lib/Youri/Submit/Action/Unpack.pm new file mode 100644 index 0000000..96c77f7 --- /dev/null +++ b/lib/Youri/Submit/Action/Unpack.pm @@ -0,0 +1,81 @@ +# $Id: Unpack.pm 115370 2007-01-30 09:59:07Z pixel $ +package Youri::Submit::Action::Unpack; + +=head1 NAME + +Youri::Submit::Action::Unpack - unpack package files + +=head1 DESCRIPTION + +This action plugin unpack package files somewhere. +When unpack_inside_distribution_root is set, dest_directory is relative to the distribution root. +When the package is a noarch, the wanted files are unpacked in distribution root of each archs. + +=cut + +use warnings; +use strict; +use Carp; +use File::Temp qw/tempdir/; +use base qw/Youri::Submit::Action/; + +sub _init { + my ($self, %options) = @_; + + croak "undefined package name" unless $options{name}; + croak "undefined source sub directory" unless $options{source_subdir}; + croak "undefined destination directory" unless $options{dest_directory}; + + foreach my $var ('name', 'dest_directory', 'source_subdir', 'unpack_inside_distribution_root') { + $self->{"_$var"} = $options{$var}; + } + + return $self; +} + +sub run { + my ($self, $package, $repository, $target, $define) = @_; + croak "Not a class method" unless ref $self; + + $package->get_name eq $self->{_name} or return; + + my @dests = $self->{_unpack_inside_distribution_root} ? + (map { "$_/$self->{_dest_directory}" } $repository->get_distribution_roots($package, $target)) + : $self->{_dest_directory}; + my $file = $package->as_file; + print "Unpacking rpm $file$self->{_source_subdir} to @dests\n" if $self->{_verbose}; + + my $tempdir = tempdir(CLEANUP => 1); + + my $cmd = "rpm2cpio $file | (cd $tempdir ; cpio -id)"; + print "Submit::Action::Unpack: doing $cmd\n" if $self->{_verbose}; + if (!$self->{_test} && system($cmd) != 0) { + print "Submit::Action::Unpack: failed!\n" if $self->{_verbose}; + return; + } + + foreach my $dest (@dests) { + my $cmd = "cd $tempdir/$self->{_source_subdir}; find -type f | cpio -pdu $dest"; + print "Submit::Action::Unpack: doing $cmd\n" if $self->{_verbose}; + if (!$self->{_test}) { + my @l = glob("$tempdir/$self->{_source_subdir}"); + if (@l == 1 && -d $l[0]) { + if (system($cmd) != 0) { + print "Submit::Action::Unpack: failed!\n" if $self->{_verbose}; + } + } else { + print "Submit::Action::Unpack: directory $self->{_source_subdir} doesn't exist in package $self->{_name}\n"; + } + } + } +} + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2002-2006, YOURI project + +This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. + +=cut + +1; |