aboutsummaryrefslogtreecommitdiffstats
path: root/emi
blob: e697e4ab08dca316c22325412dc15e95c992a4c0 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/perl
#
# Copyright (C) 2005,2006 Mandriva
# 
# Author: Florent Villard <warly@mandriva.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# upload packages in queue when all the mandatory architectures are done
#
# PREFIX : sprintf "$year%02d%02d%02d%02d%02d.$user.$host.${$}_", $mon, $mday, $hour, $min, $sec;

use strict;
use Iurt::Config qw(config_usage config_init);
use Iurt::Process qw(check_pid);
use Iurt::Queue qw(get_upload_tree_state);
use Iurt::Util qw(plog_init plog);
use Iurt::Emi qw(find_prefixes_ready_to_upload record_uploaded_packages upload_prefix_in_media);
use MDK::Common qw(cat_);

my %run;
my $program_name = 'emi';
$run{program_name} = $program_name;

my $LOG;
if (!$ENV{EMI_LOG_FILE} || !open($LOG, '>>', $ENV{EMI_LOG_FILE})) {
    open($LOG, ">&STDERR");
}

plog_init($program_name, $LOG, 7, 1);

my $HOME = $ENV{HOME};

my $configfile = "$HOME/.upload.conf";
my $sysconfigfile = "/etc/iurt/upload.conf";

my $config = {};
foreach my $f ($configfile, $sysconfigfile) {
    plog('DEBUG', "load config: $f");
    if (-f $f) {
        $config = eval(cat_($f))
          or die "FATAL $program_name: syntax error in $f";
        last;
    }
}

my %config_usage = ( 
    admin => {
	desc => 'mail address of the bot administrator',
	default => 'distrib-admin@mandrivalinux.org'
    },
    'arch' => {  
	desc => "List of arch",
	default => [ 'i586', 'x86_64', 'ppc' , 'sparcv9' ]
    },
    'arch_translation' => {  
	desc => "Renaming of arch",
	default => { 'sparc64' => 'sparcv9' }
    },
    http_queue => {
	desc => 'Address where log can be consulted',
	default => 'http://kenobi.mandriva.com/queue/'
    },
    mandatory_arch => {
	desc => 'List of mandatory architecture to be able to upload',
	default => [ 'i586', 'x86_64' ]
    },
    tmp => {
	desc => "Temporary directory",
	default => "$HOME/tmp"
    },
    queue => {
	desc => 'root directory of the various upload queues',
	default => "$HOME/uploads"
    },
);

config_usage(\%config_usage, $config) if $run{config_usage};
config_init(\%config_usage, $config, \%run);

$run{pidfile_home} = $config->{tmp};
$run{pidfile} = "upload";
my $pidfile = check_pid(\%run);

my $todo = "$config->{queue}/todo";
my $done = "$config->{queue}/done";
my $reject = "$config->{queue}/rejected";

my %pkg_tree = get_upload_tree_state($config);
my %targets = find_prefixes_ready_to_upload($config, %pkg_tree);

foreach my $target (keys %targets) {
    foreach my $media (keys %{$targets{$target}}) {
    	my %is_finisher;
	
	foreach (values %{$targets{$target}{$media}{arch_finisher}}) {
	    $is_finisher{$_} = 1;
	}

	# TODO: We should run several of those in parallel
	foreach my $prefix (@{$targets{$target}{$media}{to_upload}}) {
	    next if $is_finisher{$prefix};
	    upload_prefix_in_media($config, \%pkg_tree, $prefix, $media);
	}

	foreach my $prefix (keys %is_finisher) {
	    upload_prefix_in_media($config, \%pkg_tree, $prefix, $media, 1);
	}

	# Now that the finishers are done, metadata was updated so the packages are available
	foreach my $prefix (@{$targets{$target}{$media}{to_upload}}) {
	    my $path = $pkg_tree{$prefix}{media}{$media}{path};
	    record_uploaded_packages($config, \%pkg_tree, $prefix, $media) unless -f "$reject/$path/$prefix.youri";;
	}
    }
}

unlink($pidfile);
exit();