aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Youri/Submit/Action/RebuildPackage.pm
blob: d5a88a4cd32af6785be656eb74868510ac0cb379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# $Id$
package Youri::Submit::Action::RebuildPackage;

=head1 NAME

Youri::Submit::Action::RebuildPackage - rebuild packages dependant on this one

=head1 DESCRIPTION

This action plugin rebuilds some packages dependant on this one

=cut

use warnings;
use strict;
use Carp;
use Cwd;
use File::Temp;
use Youri::Package::RPM::Updater;
use base qw/Youri::Submit::Action/;

sub _init {
    my $self   = shift;
    my %options = (@_);

    $self->{'rules'} = $options{'rules'};

    return $self;
}

sub run {
    my ($self, $package, $repository, $target, $define) = @_;
    croak "Not a class method" unless ref $self;

    $package->is_source or return 1;

    my $prefix;
    if ($package->get_file_name() =~ m/^(\d{14}\..*)_/) {
	$prefix = $1;
    }

    my $srpm_name = $package->get_canonical_name;
    my $packages = $self->{rules}{$srpm_name} or return 1;
    my $svn = $repository->get_svn_url();
    my $updater = Youri::Package::RPM::Updater->new;
    my $oldcwd = getcwd();
    foreach my $pkg (@$packages) {
	my $tmpdir = File::Temp->newdir;
	chdir $tmpdir->dirname;
	system('svn', 'co', "${svn}/${pkg}/current");
	chdir 'current';
	$updater->update_from_spec(glob('SPECS/*.spec'));
	system('svn', 'ci', '-m', "Rebuild for new $srpm_name");
	chdir $oldcwd;
	# Ugly but we don't have complete dependecy support yet :(
	if ($prefix && 0) {
	    system("mgarepo submit --define dependencies=$prefix $pkg &");
	} else {
	    system("(sleep 1800; mgarepo submit $pkg)&");
	}
    }
}

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2013, Mageia project

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

=cut

1;