aboutsummaryrefslogtreecommitdiffstats
path: root/emi
diff options
context:
space:
mode:
authorFlorent Villard <warly@mandriva.com>2006-08-06 17:43:19 +0000
committerFlorent Villard <warly@mandriva.com>2006-08-06 17:43:19 +0000
commita0a97847c27bb3f1830615a9dcf8d90410d3031f (patch)
treef7f8a00ec9013224def2d3352d73361a17a3c21c /emi
parent47ca895db2662f8c05512d37729a67f0eb262691 (diff)
downloadiurt-a0a97847c27bb3f1830615a9dcf8d90410d3031f.tar
iurt-a0a97847c27bb3f1830615a9dcf8d90410d3031f.tar.gz
iurt-a0a97847c27bb3f1830615a9dcf8d90410d3031f.tar.bz2
iurt-a0a97847c27bb3f1830615a9dcf8d90410d3031f.tar.xz
iurt-a0a97847c27bb3f1830615a9dcf8d90410d3031f.zip
call youri and redirect the output for reference
Diffstat (limited to 'emi')
-rwxr-xr-xemi120
1 files changed, 105 insertions, 15 deletions
diff --git a/emi b/emi
index 141f7c6..4c4631f 100755
--- a/emi
+++ b/emi
@@ -25,24 +25,22 @@
# - take the packages in done/ and upload them with youri in queue/
# - check that the mandatory architectures are present
#
+# PREFIX : sprintf "$year%02d%02d%02d%02d%02d.$user.$host.${$}_", $mon, $mday, $hour, $min, $sec;
use strict;
-use Iurt::Config qw(config_usage get_date config_init);
+use Iurt::Config qw(config_usage get_date config_init dump_cache init_cache);
+use Iurt::Process qw(check_pid);
+use Iurt::File qw(check_upload_tree);
+use Data::Dumper;
+my %run;
my $program_name = 'emi';
+$run{program_name} = $program_name;
-my %run;
open(my $LOG, ">&STDERR");
$run{LOG} = $LOG;
my $HOME = $ENV{HOME};
-my $configfile = "$HOME/.emi.conf";
-
-my $config;
-if (-f $configfile) {
- $config = do $configfile or die "FATAL $program_name: syntax error in $configfile";
-} else {
- $config = {}
-}
+my $configfile = "$HOME/.upload.conf";
my %config_usage = (
arch => {
@@ -51,19 +49,111 @@ my %config_usage = (
},
mandatory_arch => {
desc => 'List of mandatory architecture to be able to upload',
- default => { i596 => 1, x86_64 => 1 },
+ default => [ 'i586', 'x86_64' ],
},
tmp => { desc => "Temporary directory", default => "$HOME/tmp/"},
+ root => { desc => 'Architecture root dir', default => "/mnt/BIG/dis/" },
+ cache_home => { desc => 'Where to store the cache files', default => "$HOME/.bugs" },
+ upload_user => { desc => 'User who is uploading packages', default => 'mandrake' },
+ queue => { desc => 'root directory of the various upload queues', default => '/home/mandrake/uploads/'},
);
-config_usage(\%config_usage, $config) if $run{config_usage};
-print {$run{LOG}} "$program_name\n";
+my $config;
+if (-f $configfile) {
+ $config = do $configfile or die "FATAL $program_name: syntax error in $configfile";
+} else {
+ $config = {}
+}
+
+config_usage(\%config_usage, $config) if $run{config_usage};
config_init(\%config_usage, $config, \%run);
$run{pidfile_home} = $config->{tmp};
-$run{pidfile} = "ulri";
+$run{pidfile} = "upload";
my $pidfile = check_pid(\%run);
+#my $cache = init_cache(\%run, $config, { arch => {} });
+my $cache = { arch => {} };
+
+my ($fulldate, $daydate) = get_date();
+$run{daydate} = $daydate;
+print {$run{LOG}} "$program_name\n";
+
+my $done = "$config->{queue}/done/";
+my $reject = "$config->{queue}/rejected/";
+
+my %pkg_tree;
+check_upload_tree(\%run, $done,
+ sub {
+ my ($todo, $f, $m, $s, $r) = @_;
+ if ($r =~ /(\d{14}\.\w+\.\w+\.\d+)_(.*\.([^.]+)\.rpm)$/) {
+ my ($prefix, $rpm, $arch) = ($1, $2, $3);
+ print {$run{LOG}} "$program_name: found rpm $rpm ($prefix)\n";
+ $pkg_tree{$prefix}{path} = "/$f/$m/$s";
+ $pkg_tree{$prefix}{arch}{$arch} = 1;
+ $pkg_tree{$prefix}{target} = $f;
+ push @{$pkg_tree{$prefix}{srpms}}, $rpm if ($arch eq 'src');
+ push @{$pkg_tree{$prefix}{rpms}} , $rpm;
+ } elsif ($r =~ /(\d{14}\.\w+\.\w+\.\d+)_(.*)\.done$/) {
+ my ($prefix, $arch) = ($1, $2);
+ $cache->{arch}{$prefix}{$arch} = 1
+ }
+ },
+);
+
+foreach my $prefix (keys %pkg_tree) {
+ my $ok = 1;
+ my $target = $pkg_tree{$prefix}{target};
+ my $path = $pkg_tree{$prefix}{path};
+ print {$run{LOG}} "$program_name: processing $prefix in $path\n";
+ my %missing;
+ foreach my $mandatory_arch (@{$config->{mandatory_arch}}, 'src') {
+ print {$run{LOG}} "$program_name: checking if mandatory architecture $mandatory_arch is present\n";
+ if (!$pkg_tree{$prefix}{arch}{$mandatory_arch} ){
+ if (!$cache->{arch}{$prefix}{$mandatory_arch}) {
+ $missing{$mandatory_arch} = 1;
+ $ok = 0
+ }
+ }
+ }
+ if ($ok) {
+ # upload
+ my @packages;
+ my ($user) = $prefix =~ /\d{14}\.(\w+)\.\w+\.\d+_.*$/;
+ foreach my $rpm (@{$pkg_tree{$prefix}{rpms}}) {
+ push @packages, "$done/$path/${prefix}_$rpm"
+ }
+ my $command = "/usr/bin/sudo -H -u $config->{upload_user} /usr/bin/perl -I/usr/local/lib/perl/ /usr/local/bin/youri-upload --verbose --test --config /etc/youri/upload-queue.conf --define user=$user,prefix=$prefix $target @packages &> $done/$path/$prefix.youri";
+ print {$run{LOG}} "$program_name: running $command\n";
+ if (!system($command)) {
+ my $all_uploaded = 1;
+ foreach my $arch (@{$config->{arch}}) {
+ if (!$cache->{arch}{$prefix}{$arch}) {
+ $all_uploaded = 0
+ }
+ }
+ if ($all_uploaded) {
+ print {$run{LOG}} "Cleaning upload tree for $prefix\n"
+ }
+ } else {
+ # should send a mail or something
+ print {$run{LOG}} "$program_name: upload failed, rejecting files in $reject/$path/\n";
+ foreach my $rpm (@packages) {
+ my $err = link $rpm, "$reject/$path/";
+ print {$run{LOG}} "ERROR $program_name: link of $rpm failed ($!)\n"
+ }
+ link "$done/$path/$prefix.youri", "$reject/$path/$prefix.youri"
+ # should delete the files
+ }
+ } else {
+ print {$run{LOG}} "WARNING $program_name: mandatory arch (", join(' ', keys %missing),") are missing for $prefix, waiting\n"
+ }
+}
+
+#dump_cache(\%run);
+unlink $pidfile;
+exit;
+
+
-exit