From a6defb55277c59d89931a33838220284c82bbf3a Mon Sep 17 00:00:00 2001 From: Florent Villard Date: Fri, 11 Aug 2006 13:49:36 +0000 Subject: add pre/post and reject queues --- bin/youri-upload.in | 221 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 167 insertions(+), 54 deletions(-) (limited to 'bin/youri-upload.in') diff --git a/bin/youri-upload.in b/bin/youri-upload.in index 3534be3..374e301 100755 --- a/bin/youri-upload.in +++ b/bin/youri-upload.in @@ -16,8 +16,11 @@ youri-upload [options] Options: --config use file as config file - --skip-check skip check + --skip-pre
       skip pre 
     --skip-action  skip action 
+    --skip-check    skip check 
+    --skip-post      skip post 
+    --skip-reject  skip reject 
     --define = pass additional values
     --list-targets         list available targets
     --list-checks  list configured checks for for 
@@ -42,6 +45,10 @@ passed to a list of action plugins, depending also on given upload target.
 
 Use given file as configuration, instead of normal one.
 
+=item B<--skip-pre> I
+
+Skip pre transaction plugin with given identity
+
 =item B<--skip-check> I
 
 Skip check plugin with given identity.
@@ -50,6 +57,14 @@ Skip check plugin with given identity.
 
 Skip action plugin with given identity.
 
+=item B<--skip-post> I
+
+Skip post transaction plugin with given identity.
+
+=item B<--skip-reject> I
+
+Skip reject action plugin with given identity.
+
 =item B<--define> =
 
 Define additional parameters, to be used by plugins.
@@ -151,14 +166,18 @@ use Pod::Usage;
 my $config = Youri::Config->new(
     command_spec => [
         'config=s',
+        'skip-pre=s@',
         'skip-check=s@',
         'skip-action=s@',
+        'skip-post=s@',
+        'skip-reject=s@',
         'list-targets!',
         'list-checks=s',
         'list-actions=s',
         'define=s%',
         'help|h!',
         'test|t!',
+	'server|s',
         'verbose|v!'
     ],
     file_spec => [
@@ -189,8 +208,6 @@ if ($config->get('list-targets')) {
 
 pod2usage(-verbose => 0, -message => "No target specified, aborting\n")
     unless @ARGV > 0;
-pod2usage(-verbose => 0, -message => "No packages specified, aborting\n")
-    unless @ARGV > 1;
 
 # convenient global flags
 my $test    = $config->get('test');
@@ -216,28 +233,17 @@ eval {
 };
 die "Failed to create repository $repository_id: $@\n" if $@;
 
-# create packages
-my @packages;
-foreach my $file (@ARGV) {
-    push(
-        @packages,
-        create_instance(
-            'Youri::Package',
-            class => $repository->get_package_class(),
-            file => $file
-        )
-    );
-}
-
-# check all packages pass all tests
-my %skip_checks = map { $_ => 1 } @{$config->get('skip-check')};
-foreach my $id (@{$target{checks}}) {
-    next if $skip_checks{$id};
-    print "Creating check $id\n" if $verbose;
-    my $check;
+# perfrom pre action
+my %skip_pres = map { $_ => 1 } @{$config->get('skip-pre')};
+my $pre_packages = [];
+my $ok = 1;
+foreach my $id (@{$target{pre}}) {
+    next if $skip_pres{$id};
+    print "Creating pre $id\n" if $verbose;
+    my $pre;
     eval {
-        $check = create_instance(
-            'Youri::Upload::Check',
+        $pre = create_instance(
+            'Youri::Upload::Pre',
             id       => $id,
             test     => $test,
             verbose  => $verbose > 0 ? $verbose - 1 : 0,
@@ -245,45 +251,152 @@ foreach my $id (@{$target{checks}}) {
         );
     };
     if ($@) {
-        print STDERR "Failed to create check $id: $@\n";
+	print STDERR "Failed to create pre $id: $@\n";
     } else {
-        foreach my $package (@packages) {
-            print "running check $id on package $package\n" if $verbose;
-            unless ($check->run($package, $repository, $target, $config->get('define'))) {
-                print STDERR "Error: " . $check->get_error() . ", aborting\n";
-                exit(1);
-            }
-        }
+	print "running pre $id\n" if $verbose;
+	unless ($pre->run($pre_packages, $repository, $target, $config->get('define'))) {
+	    print STDERR "Error: " . $pre->get_error() . "\n";
+	    $ok = 0;
+	}
     }
 }
+exit(1) unless $ok;
+
+# create packages group
+my @packages_group;
+foreach my $group ([ { }, \@ARGV ], @$pre_packages) {
+    my @packages;
+    my ($opt, $pkg) = @$group;
+    foreach my $file (@$pkg) {
+	push(
+	    @packages,
+	    create_instance(
+		'Youri::Package',
+		class => $repository->get_package_class(),
+		file => $file,
+		%$opt
+	    )
+	);
+    }
+    @packages or next;
+
+# check all packages pass all tests
+    my %skip_checks = map { $_ => 1 } @{$config->get('skip-check')};
+    my $ok = 1;
+    my @error;
+    foreach my $id (@{$target{checks}}) {
+	next if $skip_checks{$id};
+	print "Creating check $id\n" if $verbose;
+	my $check;
+	eval {
+	    $check = create_instance(
+		'Youri::Upload::Check',
+		id       => $id,
+		test     => $test,
+		verbose  => $verbose > 0 ? $verbose - 1 : 0,
+		$config->get_section($id)
+	    );
+	};
+	if ($@) {
+	    print STDERR "Failed to create check $id: $@\n";
+	} else {
+	    foreach my $package (@packages) {
+		print "running check $id on package $package\n" if $verbose;
+		unless ($check->run($package, $repository, $target, $config->get('define'))) {
+		    my $err = $check->get_error();
+		    print STDERR "Error: $err\n";
+		    push @error, $err;
+		    $ok = 0
+		}
+	    }
+
+	}
+    }
+    if (!$ok) {
+	# reject the packages
+	my %skip_rejects = map { $_ => 1 } @{$config->get('skip-reject')};
+	foreach my $id (@{$target{rejects}}) {
+	    next if $skip_rejects{$id};
+	    print "Creating reject $id\n" if $verbose;
+	    my $reject;
+	    eval {
+		$reject = create_instance(
+		    'Youri::Upload::Reject',
+		    id       => $id,
+		    test     => $test,
+		    verbose  => $verbose > 0 ? $verbose - 1 : 0,
+		    $config->get_section($id)
+		);
+	    };
+	    if ($@) {
+		print STDERR "Failed to create reject $id: $@\n";
+	    } else {
+		foreach my $package (@packages) {
+		    print "running reject $id on package $package\n" if $verbose;
+		    eval {
+			$reject->run($package, \@error, $repository, $target, $config->get('define'));
+		    };
+		    if ($@) {
+			print STDERR "Failed to run action $id on package $package: $@\n";
+		    }
+		}
+	    }
+	}
+	next
+    } 
 
 # proceed further
-my %skip_actions = map { $_ => 1 } @{$config->get('skip-action')};
-foreach my $id (@{$target{actions}}) {
-    next if $skip_actions{$id};
-    print "Creating action $id\n" if $verbose;
-    my $action;
+    my %skip_actions = map { $_ => 1 } @{$config->get('skip-action')};
+    foreach my $id (@{$target{actions}}) {
+	next if $skip_actions{$id};
+	print "Creating action $id\n" if $verbose;
+	my $action;
+	eval {
+	    $action = create_instance(
+		'Youri::Upload::Action',
+		id       => $id,
+		test     => $test,
+		verbose  => $verbose > 0 ? $verbose - 1 : 0,
+		$config->get_section($id)
+	    );
+	};
+	if ($@) {
+	    print STDERR "Failed to create action $id: $@\n";
+	} else {
+	    foreach my $package (@packages) {
+		print "running action $id on package $package\n" if $verbose;
+		eval {
+		    $action->run($package, $repository, $target, $config->get('define'));
+		};
+		if ($@) {
+		    print STDERR "Failed to run action $id on package $package: $@\n";
+		}
+	    }
+	}
+    }
+}
+# perfrom post action
+my %skip_posts = map { $_ => 1 } @{$config->get('skip-post')};
+foreach my $id (@{$target{post}}) {
+    next if $skip_posts{$id};
+    print "Creating post $id\n" if $verbose;
+    my $post;
     eval {
-        $action = create_instance(
-            'Youri::Upload::Action',
-            id       => $id,
-            test     => $test,
-            verbose  => $verbose > 0 ? $verbose - 1 : 0,
-            $config->get_section($id)
-        );
+	$post = create_instance(
+	    'Youri::Upload::Post',
+	    id       => $id,
+	    test     => $test,
+	    verbose  => $verbose > 0 ? $verbose - 1 : 0,
+	    $config->get_section($id)
+	);
     };
     if ($@) {
-        print STDERR "Failed to create action $id: $@\n";
+	print STDERR "Failed to create post $id: $@\n";
     } else {
-        foreach my $package (@packages) {
-            print "running action $id on package $package\n" if $verbose;
-            eval {
-                $action->run($package, $repository, $target, $config->get('define'));
-                };
-            if ($@) {
-                print STDERR "Failed to run action $id on package $package: $@\n";
-            }
-        }
+	print "running post $id\n" if $verbose;
+	unless ($post->run($repository, $target, $config->get('define'))) {
+	    print STDERR "Error: " . $post->get_error() . "\n";
+	}
     }
 }
 
-- 
cgit v1.2.1