From 6cbb51a6bf5f4ccfc3388ce39a3bbd5b14a91217 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Fri, 29 Jun 2007 13:30:24 +0000 Subject: prepare merge --- ChangeLog | 17 ++ Makefile.am | 8 + README | 41 +++++ TODO | 8 + bin/Makefile.am | 38 +++++ bin/youri-submit-proxy.in | 82 ++++++++++ bin/youri-submit-restricted.in | 69 +++++++++ bin/youri-submit.in | 301 ++++++++++++++++++++++++++++++++++++ configure.ac | 19 +++ etc/Makefile.am | 5 + etc/submit.conf | 131 ++++++++++++++++ etc/youri-submit | 60 +++++++ lib/Makefile.am | 34 ++++ lib/Youri/Submit/Action/Archive.pm | 73 +++++++++ lib/Youri/Submit/Action/Bugzilla.pm | 78 ++++++++++ lib/Youri/Submit/Action/CVS.pm | 136 ++++++++++++++++ lib/Youri/Submit/Action/Clean.pm | 42 +++++ lib/Youri/Submit/Action/Install.pm | 74 +++++++++ lib/Youri/Submit/Action/Link.pm | 79 ++++++++++ lib/Youri/Submit/Action/Mail.pm | 143 +++++++++++++++++ lib/Youri/Submit/Action/RSS.pm | 117 ++++++++++++++ lib/Youri/Submit/Action/Reorder.pm | 37 +++++ lib/Youri/Submit/Action/Sign.pm | 60 +++++++ lib/Youri/Submit/Step.pm | 125 +++++++++++++++ lib/Youri/Submit/Test/History.pm | 65 ++++++++ lib/Youri/Submit/Test/Precedence.pm | 60 +++++++ lib/Youri/Submit/Test/Recency.pm | 50 ++++++ lib/Youri/Submit/Test/Rpmlint.pm | 97 ++++++++++++ lib/Youri/Submit/Test/Set.pm | 79 ++++++++++ lib/Youri/Submit/Test/Tag.pm | 58 +++++++ t/Makefile.am | 8 + t/gpghome/pubring.gpg | Bin 0 -> 565 bytes t/gpghome/random_seed | Bin 0 -> 600 bytes t/gpghome/secring.gpg | Bin 0 -> 628 bytes t/gpghome/trustdb.gpg | Bin 0 -> 1280 bytes t/install.t | 51 ++++++ t/perlcritic.t | 32 ++++ t/set.t | 124 +++++++++++++++ t/sign.t | 57 +++++++ t/tags.t | 55 +++++++ 40 files changed, 2513 insertions(+) create mode 100644 ChangeLog create mode 100644 Makefile.am create mode 100644 README create mode 100644 TODO create mode 100644 bin/Makefile.am create mode 100755 bin/youri-submit-proxy.in create mode 100755 bin/youri-submit-restricted.in create mode 100755 bin/youri-submit.in create mode 100644 configure.ac create mode 100644 etc/Makefile.am create mode 100644 etc/submit.conf create mode 100644 etc/youri-submit create mode 100644 lib/Makefile.am create mode 100644 lib/Youri/Submit/Action/Archive.pm create mode 100644 lib/Youri/Submit/Action/Bugzilla.pm create mode 100644 lib/Youri/Submit/Action/CVS.pm create mode 100644 lib/Youri/Submit/Action/Clean.pm create mode 100644 lib/Youri/Submit/Action/Install.pm create mode 100644 lib/Youri/Submit/Action/Link.pm create mode 100644 lib/Youri/Submit/Action/Mail.pm create mode 100644 lib/Youri/Submit/Action/RSS.pm create mode 100644 lib/Youri/Submit/Action/Reorder.pm create mode 100644 lib/Youri/Submit/Action/Sign.pm create mode 100644 lib/Youri/Submit/Step.pm create mode 100644 lib/Youri/Submit/Test/History.pm create mode 100644 lib/Youri/Submit/Test/Precedence.pm create mode 100644 lib/Youri/Submit/Test/Recency.pm create mode 100644 lib/Youri/Submit/Test/Rpmlint.pm create mode 100644 lib/Youri/Submit/Test/Set.pm create mode 100644 lib/Youri/Submit/Test/Tag.pm create mode 100644 t/Makefile.am create mode 100644 t/gpghome/pubring.gpg create mode 100644 t/gpghome/random_seed create mode 100644 t/gpghome/secring.gpg create mode 100644 t/gpghome/trustdb.gpg create mode 100755 t/install.t create mode 100755 t/perlcritic.t create mode 100755 t/set.t create mode 100755 t/sign.t create mode 100755 t/tags.t diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..a0bdf33 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,17 @@ +2007-04-22 Guillaume Rousse 0.10 + * internal changes: + - large code cleanup + - namespace changes: + . Youri::Upload::Check -> Youri::Submit::Test + . Youri::Upload::Action -> Youri::Submit::Action + * installation: + - autotools based installation system + - modules are now installed under private directory + * YAML-based configuration + * binaries: + - youri-upload is now youri-submit + - new wrappers youri-submit-proxy and youri-submit-restricted + - --list option for runtime configuration + +2006-04-23 Guillaume Rousse 0.9 + * initial release diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..6d69457 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,8 @@ +SVNPATH = svn+ssh://youri.zarb.org/home/projects/youri/svn/soft/submit + +SUBDIRS = bin lib etc t + +svntag: + svn copy -m 'new release $(VERSION)'\ + $(SVNPATH)/trunk \ + $(SVNPATH)/tags/release-$(VERSION) diff --git a/README b/README new file mode 100644 index 0000000..3c84b66 --- /dev/null +++ b/README @@ -0,0 +1,41 @@ +youri-submit +------------ + +YOURI stands for "Youri Offers an Upload & Repository Infrastucture". It aims +to build tools making management of a coherent set of packages easier. + +youri-submit is a generic package submission tool. It first runs a list of +tests on each submitted package, and if no one fails, runs a list of actions on +those packages. + +youri-submit-restricted and youri-submit-proxy are additional wrappers intended +for collaborative work, allowing to run submission process with restricted +permissions and under another identity. + +Dependencies +------------ +The following perl modules are required: +- Youri::Config +- Youri::Repository +- Youri::Package +- Youri::Utils + +Depending on exact list of tests and actions, other modules may be needed also. + +Installation +------------ +To install, just use: +./configure +make +make install + +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. + +Authors +------- +Guillaume Rousse , diff --git a/TODO b/TODO new file mode 100644 index 0000000..da66ff6 --- /dev/null +++ b/TODO @@ -0,0 +1,8 @@ +1.0 Goals +========= +- svn action plugin +- change plugin granularity to handle a set of packages +- drop arbitrary distinction between tests and actions +- make plugins able to modify their input +- automatic bugzilla ticket closing on upload +- more customizable (template based ?) mail notification diff --git a/bin/Makefile.am b/bin/Makefile.am new file mode 100644 index 0000000..41dcd32 --- /dev/null +++ b/bin/Makefile.am @@ -0,0 +1,38 @@ +bin_SCRIPTS = youri-submit youri-submit-restricted youri-submit-proxy +man1_MANS = youri-submit.1 youri-submit-restricted.1 youri-submit-proxy.1 + +CLEANFILES = $(bin_SCRIPTS) $(man1_MANS) +EXTRA_DIST = youri-submit.in youri-submit-restricted.in youri-submit-proxy.in + +youri-submit: youri-submit.in + $(PERL) -pi \ + -e 's|\@sysconfdir\@|$(sysconfdir)|;' \ + -e 's|\@bindir\@|$(bindir)|;' \ + -e 's|\@perllibdir\@|$(perllibdir)|;' \ + < $< > $@ + +youri-submit-restricted: youri-submit-restricted.in + $(PERL) -pi \ + -e 's|\@sysconfdir\@|$(sysconfdir)|;' \ + -e 's|\@bindir\@|$(bindir)|;' \ + -e 's|\@perllibdir\@|$(perllibdir)|;' \ + < $< > $@ + +youri-submit-proxy: youri-submit-proxy.in + $(PERL) -pi \ + -e 's|\@sysconfdir\@|$(sysconfdir)|;' \ + -e 's|\@bindir\@|$(bindir)|;' \ + -e 's|\@perllibdir\@|$(perllibdir)|;' \ + < $< > $@ + +youri-submit.1: youri-submit + $(POD2MAN) $< $@ + +youri-submit-restricted.1: youri-submit-restricted + $(POD2MAN) $< $@ + +youri-submit-proxy.1: youri-submit-proxy + $(POD2MAN) $< $@ + + + diff --git a/bin/youri-submit-proxy.in b/bin/youri-submit-proxy.in new file mode 100755 index 0000000..e563044 --- /dev/null +++ b/bin/youri-submit-proxy.in @@ -0,0 +1,82 @@ +#!/usr/bin/perl +# $Id: youri-submit-proxy.in 1530 2007-03-08 20:42:13Z guillomovitch $ + +=head1 NAME + +youri-submit-proxy - proxy wrapper over youri-submit-restricted + +=head1 VERSION + +Version 1.0 + +=head1 SYNOPSIS + +youri-submit-proxy [options] + +=head1 DESCRIPTION + +youri-submit-proxy is a proxy wrapper over youri-submit-restricted, intended to +be used in collaborative work to change uid before calling it through sudo. + +=head1 SEE ALSO + +youri-submit-restricted(1), youri-submit(1) + +=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 + +use strict; +use warnings; +use lib '@perllibdir@'; + +use Fcntl ':mode'; +use File::Basename; + +my ($uid, $gid); +if (-l $0) { + # this is a symlink, get uid and gid from it + ($uid, $gid) = (lstat($0))[4, 5]; +} else { + ($uid, $gid) = (stat($0))[4, 5]; +} +my $user = getpwuid($uid) or die "unknown uid $uid\n"; +my $prog = '@bindir@/youri-submit-restricted'; + +my %dirs; +my @options; +foreach my $arg (@ARGV) { + if (-f $arg) { + # push parent dir in list + my $parent = dirname($arg); + $dirs{$parent}++; + } + push(@options, $arg); +} + +foreach my $dir (keys %dirs) { + # save original perms and gid + my ($orig_mode, $orig_gid) = (stat($dir))[2,5]; + $dirs{$dir} = { + mode => $orig_mode, + gid => $orig_gid + }; + # ensure correct perms and gid + chown -1, $gid, $dir; + chmod $orig_mode|S_IRGRP|S_IWGRP, $dir; +} + +# call wrapped program +my $status = system('sudo', '-H', '-u', $user, $prog, @options); + +foreach my $dir (keys %dirs) { + # restore original perms and gid + chown -1, $dirs{$dir}->{gid}, $dir; + chmod $dirs{$dir}->{mode}, $dir; +} + +exit($status >> 8); diff --git a/bin/youri-submit-restricted.in b/bin/youri-submit-restricted.in new file mode 100755 index 0000000..360faf8 --- /dev/null +++ b/bin/youri-submit-restricted.in @@ -0,0 +1,69 @@ +#!/usr/bin/perl -T +# $Id: youri-submit-restricted.in 1530 2007-03-08 20:42:13Z guillomovitch $ + +=head1 NAME + +youri-submit-restricted - filtering wrapper over youri-submit + +=head1 VERSION + +Version 1.0 + +=head1 SYNOPSIS + +youri-submit-restricted [options] + +=head1 DESCRIPTION + +youri-submit-restricted is just a filtering wrapper over youri-submit, intended +to be used in collaborative work to sanitize environment and options before +calling it. + +=head1 SEE ALSO + +youri-submit(1) + +=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 + +use strict; +use warnings; +use lib '@perllibdir@'; + +my $prog = '@bindir@/youri-submit'; +my @prohibited_options = qw/--config --skip-check --skip-action/; +my %prohibited_options = map { $_ => 1 } @prohibited_options; +my @prohibited_envvars = qw/ + ENV BASH_ENV IFS CDPATH + PERLLIB PERL5LIB PERL5OPT PERLIO + PERLIO_DEBUG PERL5DB PERL_ENCODING + PERL_HASH_SEED PERL_SIGNALS PERL_UNICODE +/; + +my @options; +while (my $arg = shift @ARGV) { + if ($prohibited_options{$arg}) { + # drop prohibited options + print STDERR "prohibited option $arg, skipping\n"; + shift @ARGV; + } else { + # untaint everything else + $arg =~ /(.*)/; + push(@options, $1); + } +} + +# secure ENV +$ENV{PATH} = "/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"; +delete $ENV{$_} foreach @prohibited_envvars; + +# call wrapped program +my $status = system($prog, @options); + +# return wrapped program original exit status +exit($status >> 8); diff --git a/bin/youri-submit.in b/bin/youri-submit.in new file mode 100755 index 0000000..70e6fb8 --- /dev/null +++ b/bin/youri-submit.in @@ -0,0 +1,301 @@ +#!/usr/bin/perl +# $Id: youri-submit.in 1687 2007-06-28 22:44:07Z guillomovitch $ + +=head1 NAME + +youri-submit - package submission tool + +=head1 VERSION + +Version 2.0 + +=head1 SYNOPSIS + +youri-submit [options] + +youri-submit --list [target] + +youri-submit --help [category] [item] + +Options: + + --config use file as config file + --skip-step skip step + --define = pass additional values + --clean delete package after success + --verbose verbose run + --test test run + --list list items from given category + --help [category] display contextual help + +=head1 DESCRIPTION + +B allows to submit packages to a repository. + +All packages given on command lines are passed to a list of test plugins, +depending on given upload target. If none of them fails, all packages are +passed to a list of action plugins, depending also on given upload target. + +=head1 OPTIONS + +=over + +=item B<--config> I + +Use given file as configuration, instead of normal one. + +=item B<--skip-step> I + +Skip step with given identity. + +=item B<--define> = + +Define additional parameters, to be used by plugins. + +=item B<--clean> + +Delete submited packages upon successfull submission. + +=item B<--verbose> + +Produce more verbose output (can be used more than once) + +=item B<--test> + +Don't perform any modification. + +=item B<--list> I + +List available items from given category and exits. Category must be either +B, B or B. A target is needed for the two last ones. + +=item B<--help> I + +Display help for given category and exits. Category must be either +B, B or B. An item is needed for the two last ones. +If no category given, display standard help. + +=back + +=head1 CONFIGURATION + +Configuration is read from the first file found among: + +=over + +=item * the one specified by B<--config> option on command-line + +=item * $HOME/.youri/submit.conf + +=item * @sysconfdir@/youri/submit.conf + +=back + +The configuration file should be a YAML-format files, with the following +mandatory top-level directives: + +=over + +=item B + +The definition of repository plugin to be used. + +=item B + +The list of available submission targets, each one being composed from the +following keys: + +=over + +=item B + +The list of steps to use for this target. + +=back + +=item B + +The definitions of steps, indexed by their identity. + +=back + +=head1 SEE ALSO + +Youri::Config, for additional details about configuration file format. + +Each used plugin man page, for available options. + +=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 + +use strict; +use warnings; +use lib '@perllibdir@'; + +use Youri::Config; +use Youri::Utils 0.002; +use Pod::Usage; + +my $config = Youri::Config->new( + args => { + 'skip-step' => '=s@', + 'define' => '=s%', + 'timestamp' => '!', + 'clean' => '!', + 'test' => '|t!', + 'list' => '|l!' + }, + directories => [ "$ENV{HOME}/.youri", '@sysconfdir@/youri' ], + file => 'submit.conf', +); + +if ($config->get_arg('list')) { + my $category = $ARGV[0]; + pod2usage(-verbose => 0, -message => "No category specified, aborting\n") + unless $category; + if ($category eq 'targets') { + print join(' ', keys %{$config->get_param('targets')}); + } elsif ($category eq 'steps') { + my $target = $ARGV[1]; + pod2usage(-verbose => 0, -message => "No target specified, aborting\n") + unless $target; + my $steps = $config->get_param('targets')->{$target}->{steps}; + print join(' ', @{$steps}) if $steps; + } else { + pod2usage(-verbose => 0, -message => "Invalid category $category, aborting\n") + } + print "\n"; + exit 0; +} + +if ($config->get_arg('help')) { + my $category = $ARGV[0]; + my ($item, $section); + if ($category eq 'repository') { + $section = $config->get_param('repository'); + pod2usage( + -verbose => 0, + -message => "No repository defined, aborting\n" + ) unless $section; + } elsif ($category eq 'step') { + $item = $ARGV[1]; + pod2usage( + -verbose => 0, + -message => "No item specified, aborting\n" + ) unless $item; + $section = $config->get_param('steps')->{$item}; + pod2usage( + -verbose => 0, + -message => "No such step $item defined, aborting\n" + ) unless $section; + } else { + pod2usage(-verbose => 0, -message => "Invalid category $category, aborting\n") + } + my $file = $section->{class} . '.pm'; + $file =~ s/::/\//g; + pod2usage( + -verbose => 99, + -sections => 'NAME|DESCRIPTION', + -input => $file, + -pathlist => \@INC + ); +} + + +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_arg('test'); +my $verbose = $config->get_arg('verbose'); +my $timestamp = $config->get_arg('timestamp'); + +# test target +my $target = shift @ARGV; +my $target_conf = $config->get_param('targets')->{$target}; + +# create repository +my $repository; +my $repository_conf = $config->get_param('repository'); +die "No repository declared\n" unless $repository_conf; +log_message("Creating repository", $timestamp) if $verbose; +eval { + $repository = create_instance( + 'Youri::Repository', + $repository_conf, + { + test => $test, + verbose => $verbose > 0 ? $verbose - 1 : 0, + targets => [ keys %{$config->get_param('targets')} ], + } + ); +}; +die "Failed to create repository: $@\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 %errors; +my $skip_step = $config->get_arg('skip-step'); +my %skip_step = $skip_step ? map { $_ => 1 } @{$skip_step} : (); +eval { + foreach my $id (@{$target_conf->{steps}}) { + next if $skip_step{$id}; + my $step_conf = $config->get_param('steps')->{$id}; + + die "Invalid configuration, step $id is not defined\n" + unless $step_conf; + + log_message("Creating step $id", $timestamp) if $verbose; + my $step; + $test = create_instance( + 'Youri::Submit::Step', + $step_conf, + { + id => $id, + test => $test, + verbose => $verbose > 0 ? $verbose - 1 : 0, + } + ); + + log_message("Running step $id", $timestamp) if $verbose; + $step->run( + \@packages + $repository, + $target, + $config->get_arg('define'), + ); + } +}; +if ($@) { + die "Error during submission: $@\n"; +} + +if ($config->get_arg('clean')) { + foreach my $package (@packages) { + log_message("cleaning file $package", $timestamp) if $verbose; + unlink $package->as_file(); + } +} diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..0170347 --- /dev/null +++ b/configure.ac @@ -0,0 +1,19 @@ +AC_PREREQ(2.59) +AC_INIT([youri-submit], [0.10]) +AM_INIT_AUTOMAKE([-Wall -Werror foreign]) + +AC_PATH_PROG([PERL],[perl]) +if test -z $PERL; then + AC_MSG_ERROR([perl not found, aborting]) +fi + +AC_PATH_PROG([POD2MAN],[pod2man]) +if test -z $POD2MAN; then + AC_MSG_ERROR([pod2man not found, aborting]) +fi + +perllibdir=$datadir/youri/lib +AC_SUBST(perllibdir) + +AC_CONFIG_FILES([Makefile bin/Makefile lib/Makefile etc/Makefile t/Makefile]) +AC_OUTPUT diff --git a/etc/Makefile.am b/etc/Makefile.am new file mode 100644 index 0000000..3ffc811 --- /dev/null +++ b/etc/Makefile.am @@ -0,0 +1,5 @@ +yourisysconfdir = $(sysconfdir)/youri +completiondir = $(sysconfdir)/bash_completion.d + +dist_yourisysconf_DATA = submit.conf +dist_completion_SCRIPTS = youri-submit diff --git a/etc/submit.conf b/etc/submit.conf new file mode 100644 index 0000000..a7fbf16 --- /dev/null +++ b/etc/submit.conf @@ -0,0 +1,131 @@ +# youri-submit sample configuration file +# $Id: submit.conf 1671 2007-06-28 22:41:51Z guillomovitch $ +# vim:ft=yaml:et:sw=4 + +# helper variables +home: /home/user + +# repository definition +repository: + class: Youri::Repository::PLF + options: + install_root: ${home}/ftp/mandriva + version_root: ${home}/cvs + archive_root: ${home}/backup/mandriva + noarch: i586 + +# targets definitions +targets: + cooker: + steps: + - check-tag + - check-recency + - check-history + - do-sign + - do-install + - do-link + - do-archive + - do-clean + - do-bugzilla + - do-cvs + - do-mail + - do-rss + + 2006.0: + steps: + - check-type + - check-tag + - check-recency + - check-history + - check-precedence + - do-sign + - do-install + - do-link + - do-archive + - do-clean + +# steps definitions +steps: + check-tag: + class: Youri::Submit::Check::Tag + options: + tags: + release: 'plf$' + packager: '<\w+@zarb\.org>$' + distribution: '^Mandriva Linux$' + vendor: '^Penguin Liberation Front$' + + check-recency: + class: Youri::Submit::Check::Recency + + check-history: + class: Youri::Submit::Check::History + + check-precedence: + class: Youri::Submit::Check::Precedence + options: + target: cooker + + check-type: + class: Youri::Submit::Check::Type + type: binary + + do-sign: + class: Youri::Submit::Action::Sign + options: + name: plf@zarb.org + path: ${home}/.gnupg + passphrase: s3kr3t + + do-install: + class: Youri::Submit::Action::Install + + do-link: + class: Youri::Submit::Action::Link + + do-archive: + class: Youri::Submit::Action::Archive + + do-clean: + class: Youri::Submit::Action::Clean + + do-mail: + class: Youri::Submit::Action::Mail + options: + mta: /usr/sbin/sendmail + to: plf-announce@zarb.org + reply_to: plf-discuss@zarb.org + from: plf@zarb.org + prefix: RPM + cc: + hot-base: david@dindinx.org bellamy@neverland.net + dcgui: mathen@ketelhot.de + dclib: mathen@ketelhot.de + Video-DVDRip: dvdrip-users@exit1.org + hackVideo-DVDRip: dvdrip-users@exit1.org + goosnes: tak@bard.sytes.net + avidemux: fixounet@free.fr + vobcopy: robos@muon.de + drip: drip-devel@lists.sourceforge.net + libdscaler: vektor@dumbterm.net + xawdecode: pingus77@ifrance.com + + do-rss: + class: Youri::Submit::Action::RSS + options: + file: ${home}/www/changelog.rss + title: PLF packages updates + link: http://plf.zarb.org/ + description: ChangeLog for PLF packages + + do-cvs: + class: Youri::Submit::Action::CVS + + do-bugzilla: + class: Youri::Submit::Action::Bugzilla + options: + host: localhost + base: plf_bugs + user: plf + pass: s3kr3t + contact: plf@zarb.org diff --git a/etc/youri-submit b/etc/youri-submit new file mode 100644 index 0000000..6feb2c7 --- /dev/null +++ b/etc/youri-submit @@ -0,0 +1,60 @@ +# youri-submit completion +# $Id$ + +_youri-submit() +{ + + local cur prev config + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + --config) + _filedir + return 0 + ;; + --list) + COMPREPLY=( $( compgen -W 'targets steps' -- $cur ) ) + return 0 + ;; + --help) + COMPREPLY=( $( compgen -W 'repository steps' -- $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--define --clean -l --list -h --help -t \ + --test -v --verbose' -- $cur ) ) + # add dangereous option for main command + if [[ ${COMP_WORDS[0]} == youri-submit ]]; then + COMPREPLY=( $( compgen -W '${COMPREPLY[@]} --config --skip-step' \ + -- $cur ) ) + fi + else + _count_args + case $args in + 1) + _find_config + COMPREPLY=( $( compgen -W '$( youri-submit $config --list targets )' -- $cur ) ) + ;; + *) + _filedir + ;; + esac + fi + +} +complete -F _youri-submit youri-submit youri-submit-restricted youri-submit-proxy + +_find_config() +{ + for (( i=1; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" == --config ]]; then + config="--config ${COMP_WORDS[i+1]}" + break + fi + done +} diff --git a/lib/Makefile.am b/lib/Makefile.am new file mode 100644 index 0000000..40ae36a --- /dev/null +++ b/lib/Makefile.am @@ -0,0 +1,34 @@ +nobase_perllib_DATA = Youri/Submit/Test/Rpmlint.pm \ + Youri/Submit/Test/Recency.pm \ + Youri/Submit/Test/Tag.pm \ + Youri/Submit/Test/Precedence.pm \ + Youri/Submit/Test/History.pm \ + Youri/Submit/Test/Type.pm \ + Youri/Submit/Action.pm \ + Youri/Submit/Plugin.pm \ + Youri/Submit/Test.pm \ + Youri/Submit/Action/Install.pm \ + Youri/Submit/Action/RSS.pm \ + Youri/Submit/Action/Bugzilla.pm \ + Youri/Submit/Action/CVS.pm \ + Youri/Submit/Action/Link.pm \ + Youri/Submit/Action/Sign.pm \ + Youri/Submit/Action/Archive.pm \ + Youri/Submit/Action/Clean.pm \ + Youri/Submit/Action/Mail.pm + +EXTRA_DIST = $(nobase_perllib_DATA) + +install-data-hook: + $(INSTALL) -d -m 755 $(DESTDIR)$(mandir)/man3 + for file in $(nobase_perllib_DATA); do \ + page=`echo $$file | sed -e 's/\//::/g' -e 's/\.pm$$/.3pm/'`; \ + $(POD2MAN) --section=3 $(srcdir)/$$file \ + $(DESTDIR)$(mandir)/man3/$$page; \ + done + +uninstall-hook: + for file in $(nobase_perllib_DATA); do \ + page=`echo $$file | sed -e 's/\//::/g' -e 's/\.pm$$/.3pm/'`; \ + rm -f $(DESTDIR)$(mandir)/man3/$$page; \ + done diff --git a/lib/Youri/Submit/Action/Archive.pm b/lib/Youri/Submit/Action/Archive.pm new file mode 100644 index 0000000..75e69cb --- /dev/null +++ b/lib/Youri/Submit/Action/Archive.pm @@ -0,0 +1,73 @@ +# $Id: Archive.pm 1689 2007-06-28 22:44:24Z guillomovitch $ +package Youri::Submit::Action::Archive; + +=head1 NAME + +Youri::Submit::Action::Archive - Old revisions archiving + +=head1 DESCRIPTION + +This action plugin ensures archiving of old package revisions. + +=cut + +use warnings; +use strict; +use Carp; +use base qw/Youri::Submit::Step/; + +sub _init { + my $self = shift; + my %options = ( + perms => 644, + @_ + ); + + $self->{_perms} = $options{perms}; +} + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + foreach my $package (@$packages) { + foreach my $replaced_package ( + $repository->get_replaced_packages($package, $target, $context) + ) { + my $file = $replaced_package->as_file(); + my $dest = $repository->get_archive_dir($package, $target, $context); + + print "archiving file $file to $dest\n" if $self->{_verbose}; + + unless ($self->{_test}) { + # create destination dir if needed + if (! -d $dest) { + eval { + mkpath($dest, 0, ($self->{_perms} + 111)); + }; + if ($@) { + croak "Unable to create directory $dest: $@"; + } + } + + # copy file to new location + copy($file, $dest) + or croak "Unable to copy file $file to $dest: $!"; + + # set permissions + chmod oct($self->{_perms}), $dest . '/' . basename($file) + or croak "Unable to set perms of file $file to $self->{_perms}: $!"; + } + } + } +} + +=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; diff --git a/lib/Youri/Submit/Action/Bugzilla.pm b/lib/Youri/Submit/Action/Bugzilla.pm new file mode 100644 index 0000000..a8ad5ce --- /dev/null +++ b/lib/Youri/Submit/Action/Bugzilla.pm @@ -0,0 +1,78 @@ +# $Id: Bugzilla.pm 1689 2007-06-28 22:44:24Z guillomovitch $ +package Youri::Submit::Action::Bugzilla; + +=head1 NAME + +Youri::Submit::Action::Bugzilla - Bugzilla synchronisation + +=head1 DESCRIPTION + +This action ensures synchronisation with Bugzilla. It assumes given package set +is canonical, with source package first. + +=cut + +use warnings; +use strict; +use Carp; +use Youri::BTS::Bugzilla; +use base qw/Youri::Submit::Step/; + +sub _init { + my $self = shift; + my %options = ( + lib => undef, + project => undef, + contact => undef, + @_ + ); + + $self->{_bugzilla} = Youri::BTS::Bugzilla->new( + $options{lib} ? (lib => $options{lib}) : (), + $options{project} ? (project => $options{project}) : (), + ); + $self->{_contact} = $options{contact}; +} + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + my $package = $packages->[0]; + + my $name = $package->get_name(); + my $version = $package->get_version(); + my $summary = $package->get_summary(); + my $packager = $package->get_packager(); + $packager =~ s/.*<(.*)>/$1/; + + if ($self->{_bugzilla}->has_package($name)) { + my %versions = + map { $_ => 1 } + $self->{_bugzilla}->get_versions($name); + unless ($versions{$version}) { + print "adding version $version to bugzilla\n" if $self->{_verbose}; + $self->{_bugzilla}->add_version($name, $version) + unless $self->{_test}; + } + } else { + print "adding package $name to bugzilla\n" if $self->{_verbose}; + $self->{_bugzilla}->add_package( + $name, + $summary, + $version, + $packager, + $self->{_contact} + ) unless $self->{_test}; + } +} + +=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; diff --git a/lib/Youri/Submit/Action/CVS.pm b/lib/Youri/Submit/Action/CVS.pm new file mode 100644 index 0000000..48e3eae --- /dev/null +++ b/lib/Youri/Submit/Action/CVS.pm @@ -0,0 +1,136 @@ +# $Id: CVS.pm 1689 2007-06-28 22:44:24Z guillomovitch $ +package Youri::Submit::Action::CVS; + +=head1 NAME + +Youri::Submit::Action::CVS - CVS versionning + +=head1 DESCRIPTION + +This action ensures CVS versionning of package sources. It assumes given +package set is canonical, with source package first. + +=cut + +use warnings; +use strict; +use Carp; +use Cwd; +use File::Temp qw/tempdir/; +use base qw/Youri::Submit::Step/; + +sub _init { + my $self = shift; + my %options = ( + exclude => '\.(tar(\.(gz|bz2))?|zip)$', + perms => 644, + @_ + ); + + $self->{_exclude} = $options{exclude}; + $self->{_perms} = $options{perms}; +} + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + my $package = $packages->[0]; + + my $name = $package->get_name(); + my $version = $package->get_version(); + my $release = $package->get_release(); + + my $root = $repository->get_version_root(); + my $path = $repository->get_version_path($package, $target, $define); + + # remember original directory + my $original_dir = cwd(); + + # get a safe temporary directory + my $dir = tempdir( CLEANUP => 1 ); + chdir $dir; + + # first checkout base directory only + system("cvs -Q -d $root co -l $path"); + + # try to checkout package directory + my $dest = $path . '/' . $name; + system("cvs -Q -d $root co $dest"); + + # create directory if previous import failed + unless (-d $dest) { + print "adding directory $dest\n" if $self->{_verbose}; + system("install -d -m " . ($self->{_perms} + 111) . " $dest"); + system("cvs -Q -d $root add $dest"); + } + + chdir $dest; + + # remove all files + unlink grep { -f } glob '*'; + + # extract all rpm files locally + $package->extract(); + + # remove excluded files + if ($self->{_exclude}) { + unlink grep { -f && /$self->{_exclude}/ } glob '*'; + } + + # uncompress all compressed files + system("bunzip2 *.bz2 2>/dev/null"); + system("gunzip *.gz 2>/dev/null"); + + my (@to_remove, @to_add, @to_add_binary); + foreach my $line (`cvs -nq update`) { + if ($line =~ /^\? (\S+)/) { + if (-B $1) { + push(@to_add_binary, $1); + } else { + push(@to_add, $1); + } + } + if ($line =~ /^U (\S+)/) { + push(@to_remove, $1); + } + } + if (@to_remove) { + my $to_remove = join(' ', @to_remove); + print "removing file(s) $to_remove\n" if $self->{_verbose}; + system("cvs -Q remove $to_remove"); + } + if (@to_add) { + my $to_add = join(' ', @to_add); + print "adding text file(s) $to_add\n" if $self->{_verbose}; + system("cvs -Q add $to_add"); + } + if (@to_add_binary) { + my $to_add_binary = join(' ', @to_add_binary); + print "adding binary file(s) $to_add_binary\n" if $self->{_verbose}; + system("cvs -Q add -kb $to_add_binary"); + } + + print "committing current directory\n" if $self->{_verbose}; + system("cvs -Q commit -m $version-$release") unless $self->{_test}; + + # tag new release + my $tag = "r$version-$release"; + $tag =~ s/\./_/g; + print "tagging current directory as $tag\n" if $self->{_verbose}; + system("cvs -Q tag $tag") unless $self->{_test}; + + # get back to original directory + chdir $original_dir; + +} + +=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; diff --git a/lib/Youri/Submit/Action/Clean.pm b/lib/Youri/Submit/Action/Clean.pm new file mode 100644 index 0000000..110326a --- /dev/null +++ b/lib/Youri/Submit/Action/Clean.pm @@ -0,0 +1,42 @@ +# $Id: Clean.pm 1689 2007-06-28 22:44:24Z guillomovitch $ +package Youri::Submit::Action::Clean; + +=head1 NAME + +Youri::Submit::Action::Clean - Old revisions cleanup + +=head1 DESCRIPTION + +This action plugin ensures cleanup of old package revisions. + +=cut + +use warnings; +use strict; +use Carp; +use base qw/Youri::Submit::Step/; + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + foreach my $package (@$packages) { + foreach my $replaced_package ( + $repository->get_replaced_packages($package, $target, $define) + ) { + my $file = $replaced_package->as_file(); + print "deleting file $file\n" if $self->{_verbose}; + unlink $file unless $self->{_test}; + } + } +} + +=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; diff --git a/lib/Youri/Submit/Action/Install.pm b/lib/Youri/Submit/Action/Install.pm new file mode 100644 index 0000000..c9a419f --- /dev/null +++ b/lib/Youri/Submit/Action/Install.pm @@ -0,0 +1,74 @@ +# $Id: Install.pm 1689 2007-06-28 22:44:24Z guillomovitch $ +package Youri::Submit::Action::Install; + +=head1 NAME + +Youri::Submit::Action::Install - Package installation + +=head1 DESCRIPTION + +This action plugin ensures installation of new package revisions. + +=cut + +use warnings; +use strict; +use Carp; +use File::Copy; +use File::Path; +use File::Basename; +use base qw/Youri::Submit::Step/; + +sub _init { + my $self = shift; + my %options = ( + perms => 644, + @_ + ); + + $self->{_perms} = $options{perms}; + + return $self; +} + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + foreach my $package (@$packages) { + my $file = $package->as_file(); + my $dest = $repository->get_install_dir($package, $target, $context); + + print "installing file $file to $dest\n" if $self->{_verbose}; + + unless ($self->{_test}) { + # create destination dir if needed + if (! -d $dest) { + eval { + mkpath($dest, 0, ($self->{_perms} + 111)); + }; + if ($@) { + croak "Unable to create directory $dest: $@"; + } + } + + # copy file to new location + copy($file, $dest) + or croak "Unable to copy file $file to $dest: $!"; + + # set permissions + chmod oct($self->{_perms}), $dest . '/' . basename($file) + or croak "Unable to set perms of file $file to $self->{_perms}: $!"; + } + } +} + +=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; diff --git a/lib/Youri/Submit/Action/Link.pm b/lib/Youri/Submit/Action/Link.pm new file mode 100644 index 0000000..940f7d7 --- /dev/null +++ b/lib/Youri/Submit/Action/Link.pm @@ -0,0 +1,79 @@ +# $Id: Link.pm 1689 2007-06-28 22:44:24Z guillomovitch $ +package Youri::Submit::Action::Link; + +=head1 NAME + +Youri::Submit::Action::Link - Noarch packages linking + +=head1 DESCRIPTION + +This action plugin ensures linking of noarch packages between arch-specific +directories. + +=cut + +use warnings; +use strict; +use Carp; +use Cwd; +use File::Spec; +use base qw/Youri::Submit::Step/; + +sub _init { + my $self = shift; + my %options = ( + symbolic => 0, # use symbolic linking + @_ + ); + + $self->{_symbolic} = $options{symbolic}; +} + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + foreach my $package (@$packages) { + # only needed for noarch packages + next unless $package->get_arch() eq 'noarch'; + + my $default_dir = $repository->get_install_dir($package, $target, $define); + my $file = $package->get_file_name(); + + foreach my $arch ($repository->get_extra_arches()) { + # compute installation target, forcing arch + my $other_dir = $repository->get_install_dir( + $package, + $target, + $context, + { arch => $arch } + ); + + if (! $self->{_test} && -d $other_dir) { + my $current_dir = cwd(); + chdir $other_dir + or croak "Can't change directory to $other_dir: $!"; + my $default_file = File::Spec->abs2rel($default_dir) . '/' . $file; + if ($self->{_symbolic}) { + symlink $default_file, $file + or croak "Can't symlink $default_file to $file: $!"; + } else { + link $default_file, $file + or croak "Can't link $default_file to $file: $!"; + } + chdir $current_dir + or croak "Can't change directory to $current_dir: $!"; + } + } + } +} + +=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; diff --git a/lib/Youri/Submit/Action/Mail.pm b/lib/Youri/Submit/Action/Mail.pm new file mode 100644 index 0000000..4e39ef8 --- /dev/null +++ b/lib/Youri/Submit/Action/Mail.pm @@ -0,0 +1,143 @@ +# $Id: Mail.pm 1689 2007-06-28 22:44:24Z guillomovitch $ +package Youri::Submit::Action::Mail; + +=head1 NAME + +Youri::Submit::Action::Mail - Mail notification + +=head1 DESCRIPTION + +This action ensures mail notification of new package revisions. It assumes +given package set is canonical, with source package first. + +=cut + +use warnings; +use strict; +use MIME::Entity; +use Encode qw/from_to/; +use Carp; +use Youri::Package; +use base qw/Youri::Submit::Step/; + +sub _init { + my $self = shift; + my %options = ( + mta => '/usr/sbin/sendmail', + to => '', + from => '', + cc => '', + prefix => '', + encoding => 'quoted-printable', + charset => 'iso-8859-1', + @_ + ); + + croak "undefined mail MTA" unless $options{mta}; + croak "invalid mail MTA $options{mta}" unless -x $options{mta}; + croak "undefined to" unless $options{to}; + if ($options{cc}) { + croak "cc should be an hashref" unless ref $options{cc} eq 'HASH'; + } + croak "invalid charset $options{charset}" + unless Encode::resolve_alias($options{charset}); + + $self->{_mta} = $options{mta}; + $self->{_to} = $options{to}; + $self->{_from} = $options{from}; + $self->{_cc} = $options{cc}; + $self->{_prefix} = $options{prefix}; + $self->{_encoding} = $options{encoding}; + $self->{_charset} = $options{charset}; +} + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + my $package = $packages->[0]; + + my $from = $package->get_packager(); + + # force from adress if defined + $from =~ s/<.*>/<$self->{_from}>/ if $self->{_from}; + + my $subject = $self->get_subject($package, $repository, $target, $define); + my $content = $self->get_content($package, $repository, $target, $define); + + # ensure proper codeset conversion + # for informations coming from package + my $charset = $repository->get_package_charset(); + from_to($content, $charset, $self->{_charset}); + from_to($subject, $charset, $self->{_charset}); + + my $mail = MIME::Entity->build( + Type => 'text/plain', + Charset => $self->{_charset}, + Encoding => $self->{_encoding}, + From => $from, + To => $self->{_to}, + Subject => $subject, + Data => $content, + ); + + if ($self->{_cc}) { + my $cc = $self->{_cc}->{$package->get_name()}; + $mail->head()->add('cc', $cc) if $cc; + } + + if ($self->{_test}) { + $mail->print(\*STDOUT); + } else { + my $command = "$self->{_mta} -t -oi -oem"; + open(my $output, '|-', $command) or croak "Can't run $command: $!"; + $mail->print($output); + close $output; + } + +} + +sub get_subject { + my ($self, $package, $repository, $target, $define) = @_; + croak "Not a class method" unless ref $self; + + return + ($self->{_prefix} ? '[' . $self->{_prefix} . '] ' : '' ) . + $package->as_formated_string('%{name}-%{version}-%{release}'); +} + +sub get_content { + my ($self, $package, $repository, $target, $define) = @_; + croak "Not a class method" unless ref $self; + + my $information = $package->as_formated_string(<get_last_change(); + + return $last_change ? + $information . "\n" . + $last_change->get_author() . ":\n" . + $last_change->get_raw_text() : + $information; +} + + +=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; diff --git a/lib/Youri/Submit/Action/RSS.pm b/lib/Youri/Submit/Action/RSS.pm new file mode 100644 index 0000000..11fb5b5 --- /dev/null +++ b/lib/Youri/Submit/Action/RSS.pm @@ -0,0 +1,117 @@ +# $Id: RSS.pm 1689 2007-06-28 22:44:24Z guillomovitch $ +package Youri::Submit::Action::RSS; + +=head1 NAME + +Youri::Submit::Action::RSS - RSS notification + +=head1 DESCRIPTION + +This action ensures RSS notification of new package revisions. It assumes given package set is canonical, with source package first. + +=cut + +use warnings; +use strict; +use XML::RSS; +use Encode qw/from_to/; +use Carp; +use base qw/Youri::Submit::Step/; + +sub _init { + my $self = shift; + my %options = ( + file => '', + title => '', + link => '', + description => '', + charset => 'iso-8859-1', + max_items => 10, + @_ + ); + + croak "undefined rss file" unless $options{file}; + croak "invalid charset $options{charset}" + unless Encode::resolve_alias($options{charset}); + + $self->{_file} = $options{file}; + $self->{_title} = $options{title}; + $self->{_link} = $options{link}; + $self->{_description} = $options{description}; + $self->{_charset} = $options{charset}; + $self->{_max_items} = $options{max_items}; +} + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + my $package = $packages->[0]; + + my $subject = $package->as_formated_string('%{name}-%{version}-%{release}'); + my $content = $package->as_formated_string(</mg; + + # ensure proper codeset conversion + # for informations coming from package + my $charset = $repository->get_package_charset(); + from_to($content, $charset, $self->{_charset}); + from_to($subject, $charset, $self->{_charset}); + + my $rss = XML::RSS->new( + encoding => $self->{_charset}, + encode_output => 1 + ); + + my $file = $self->{_file}; + if (-e $file) { + eval { + $rss->parsefile($file); + }; + if ($@) { + croak "Unable to parse RSS file $file: $@"; + } + splice(@{$rss->{items}}, $self->{_max_items}) + if @{$rss->{items}} >= $self->{_max_items}; + } else { + $rss->channel( + title => $self->{_title}, + link => $self->{_link}, + description => $self->{_description}, + language => 'en' + ); + } + + $rss->add_item( + title => $subject, + description => $content, + mode => 'insert' + ); + + if ($self->{_test}) { + print $rss->as_string(); + } else { + $rss->save($file); + } +} + +=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; diff --git a/lib/Youri/Submit/Action/Reorder.pm b/lib/Youri/Submit/Action/Reorder.pm new file mode 100644 index 0000000..a6ed3da --- /dev/null +++ b/lib/Youri/Submit/Action/Reorder.pm @@ -0,0 +1,37 @@ +# $Id: Reorder.pm 1688 2007-06-28 22:44:16Z guillomovitch $ +package Youri::Submit::Action::Reorder; + +=head1 NAME + +Youri::Submit::Action::Reorder - Reorder packages with source first + +=head1 DESCRIPTION + +This action ensures that the source package is the first in the list. + +=cut + +use warnings; +use strict; +use Carp; +use base qw/Youri::Submit::Step/; + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + $packages = [ + grep { $_->is_source() } @$packages, + grep { !$_->is_source() } @$packages, + ]; +} + +=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; diff --git a/lib/Youri/Submit/Action/Sign.pm b/lib/Youri/Submit/Action/Sign.pm new file mode 100644 index 0000000..ce8f4a9 --- /dev/null +++ b/lib/Youri/Submit/Action/Sign.pm @@ -0,0 +1,60 @@ +# $Id: Sign.pm 1689 2007-06-28 22:44:24Z guillomovitch $ +package Youri::Submit::Action::Sign; + +=head1 NAME + +Youri::Submit::Action::Sign - GPG signature + +=head1 DESCRIPTION + +This action plugin ensures GPG signature of packages. + +=cut + +use warnings; +use strict; +use Carp; +use base qw/Youri::Submit::Step/; + +sub _init { + my $self = shift; + my %options = ( + name => '', + path => $ENV{HOME} . '/.gnupg', + passphrase => '', + @_ + ); + + croak "undefined name" unless $options{name}; + croak "undefined path" unless $options{path}; + croak "invalid path $options{path}" unless -d $options{path}; + + $self->{_name} = $options{name}; + $self->{_path} = $options{path}; + $self->{_passphrase} = $options{passphrase}; +} + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + return if $self->{_test}; + + foreach my $package (@$packages) { + $package->sign( + $self->{_name}, + $self->{_path}, + $self->{_passphrase} + ); + } +} + +=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; diff --git a/lib/Youri/Submit/Step.pm b/lib/Youri/Submit/Step.pm new file mode 100644 index 0000000..0085277 --- /dev/null +++ b/lib/Youri/Submit/Step.pm @@ -0,0 +1,125 @@ +# $Id: Step.pm 1687 2007-06-28 22:44:07Z guillomovitch $ +package Youri::Submit::Step; + +=head1 NAME + +Youri::Submit::Step - Abstract submission step + +=head1 DESCRIPTION + +This abstract class defines youri-submit plugin interface. + +=cut + +use warnings; +use strict; +use Carp; + +=head1 CLASS METHODS + +=head2 new(%args) + +Creates and returns a new Youri::Submit::Plugin object. + +Generic parameters: + +=over + +=item skip $skip + +List of packages for which to skip this plugin + +=over + +Warning: do not call directly, call subclass constructor instead. + +=cut + +sub new { + my $class = shift; + croak "Abstract class" if $class eq __PACKAGE__; + + my %options = ( + id => '', # object id + test => 0, # test mode + verbose => 0, # verbose mode + skip => undef, + @_ + ); + + croak "skip should be an arrayref" + if $options{skip} and ref $options{skip} ne 'ARRAY'; + + + my $self = bless { + _id => $options{id}, + _test => $options{test}, + _verbose => $options{verbose}, + _skip => { map { $_ => 1 } @{$options{skip}} } + }, $class; + + $self->_init(%options); + + return $self; +} + +sub _init { + # do nothing +} + +=head1 INSTANCE METHODS + +=head2 get_id() + +Returns plugin identity. + +=cut + +sub get_id { + my ($self) = @_; + croak "Not a class method" unless ref $self; + + return $self->{_id}; +} + +=head2 run($packages, $repository, $target, $context) + +Execute action on given L object. + +=cut + +sub run { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + croak "packages is not an array reference" unless ref $packages eq 'ARRAY'; + + # filter exceptions + $packages = [ + grep { !$self->{_skip}->{$_->get_canonical_name()} } + @$packages + ]; + + $self->process_packages($repository, $packages, $target, $context) + if @$packages; +} + + +=head1 SUBCLASSING + +The following methods have to be implemented: + +=over + +=item run + +=back + +=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; diff --git a/lib/Youri/Submit/Test/History.pm b/lib/Youri/Submit/Test/History.pm new file mode 100644 index 0000000..b4b7969 --- /dev/null +++ b/lib/Youri/Submit/Test/History.pm @@ -0,0 +1,65 @@ +# $Id: History.pm 1687 2007-06-28 22:44:07Z guillomovitch $ +package Youri::Submit::Test::History; + +=head1 NAME + +Youri::Submit::Test::History - Non-linear history test + +=head1 DESCRIPTION + +This test rejects packages whose history does not include last available +revision one. It assumes given set of package is canonical, and only check +first one. + +=cut + +use warnings; +use strict; +use Carp; +use Youri::Package; +use List::MoreUtils qw/none/; +use base qw/Youri::Submit::Step/; + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + my $errors; + my $package = $packages->[0]; + my $current_package = + $repository->get_last_older_revision($package, $target, $context); + + # new package + return unless $current_package; + + # skip the test if last revision has been produced from another + # source package, as it occurs during package split/merges + return + if $current_package->get_canonical_name() + ne $package->get_canonical_name(); + + my $last_change_author = + $current_package->get_last_change()->get_author(); + + if ( + none { $last_change_author eq $_ } + map { $_->get_author() } + $package->get_changes() + ) { + $errors .= + "last changelog entry $last_change_author from current package " + . "$current_package missing from changelog"; + } + + croak $errors if $errors; +} + +=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; diff --git a/lib/Youri/Submit/Test/Precedence.pm b/lib/Youri/Submit/Test/Precedence.pm new file mode 100644 index 0000000..4cd35a6 --- /dev/null +++ b/lib/Youri/Submit/Test/Precedence.pm @@ -0,0 +1,60 @@ +# $Id: Precedence.pm 1687 2007-06-28 22:44:07Z guillomovitch $ +package Youri::Submit::Test::Precedence; + +=head1 NAME + +Youri::Submit::Test::Precedence - Release test against another test + +=head1 DESCRIPTION + +This test rejects packages whose an older revision already exists for another +upload target. It assumes given set of package is canonical, and only check +first one. + + +=cut + +use warnings; +use strict; +use Carp; +use base qw/Youri::Submit::Step/; + +sub _init { + my $self = shift; + my %options = ( + _target => undef, # mandatory targets + @_ + ); + + croak "undefined target" unless $options{target}; + + $self->{_target} = $options{target}; +} + +sub process_package { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + my $errors; + my $package = $packages->[0]; + + my @older_revisions = + $repository->get_older_revisions($package, $self->{_target}, $context); + $errors .= + "older revisions still exists for $self->{_target}: " + . join(', ', @older_revisions) + if @older_revisions; + } + + croak $errors if $errors; +} + +=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; diff --git a/lib/Youri/Submit/Test/Recency.pm b/lib/Youri/Submit/Test/Recency.pm new file mode 100644 index 0000000..db6ba59 --- /dev/null +++ b/lib/Youri/Submit/Test/Recency.pm @@ -0,0 +1,50 @@ +# $Id: Recency.pm 1687 2007-06-28 22:44:07Z guillomovitch $ +package Youri::Submit::Test::Recency; + +=head1 NAME + +Youri::Submit::Test::Recency - Release test against current target + +=head1 DESCRIPTION + +This test rejects packages whose a current or newer revision already exists for +current upload target. It assumes given set of package is canonical, and only +check first one. + +=cut + +use warnings; +use strict; +use Carp; +use base qw/Youri::Submit::Step/; + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + my $errors; + my $package = $packages->[0]; + + my $file = $repository->get_install_file($package, $target, $context); + $errors .= "current revision already exists for $target\n" + if -f $file; + + my @newer_revisions = + $repository->get_newer_revisions($package, $target, $define); + $errors .= + "newer revisions already exists for $target: " + . join(', ', @newer_revisions) . "\n" + if @newer_revisions; + + croak $errors if $errors; +} + +=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; diff --git a/lib/Youri/Submit/Test/Rpmlint.pm b/lib/Youri/Submit/Test/Rpmlint.pm new file mode 100644 index 0000000..170d4c3 --- /dev/null +++ b/lib/Youri/Submit/Test/Rpmlint.pm @@ -0,0 +1,97 @@ +# $Id: Rpmlint.pm 1687 2007-06-28 22:44:07Z guillomovitch $ +package Youri::Submit::Test::Rpmlint; + +=head1 NAME + +Youri::Submit::Test::Rpmlint - Rpmlint-based test + +=head1 DESCRIPTION + +This test plugin wraps rpmlint, and reject packages triggering results +declared as fatal. + +=cut + +use warnings; +use strict; +use Carp; +use base qw/Youri::Submit::Step/; + +=head2 new(%args) + +Creates and returns a new Youri::Submit::Test::Rpmlint object. + +Specific parameters: + +=over + +=item results $results + +List of rpmlint result id considered as fatal. + +=item path $path + +Path to the rpmlint executable (default: /usr/bin/rpmlint) + +=item config $config + +Specific rpmlint configuration. + +=back + +=cut + + +sub _init { + my $self = shift; + my %options = ( + results => undef, + path => '/usr/bin/rpmlint', + config => '', + @_ + ); + + croak "no results to test" unless $options{results}; + croak "results should be an arrayref" unless ref $options{results} eq 'ARRAY'; + + $self->{_results} = map { $_ => 1 } @{$options{results}}; + $self->{_path} = $options{path}; + $self->{_config} = $options{config}; +} + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + my $errors; + + foreach my $package (@$packages) { + my $command = + $self->{_path} . ' ' . + ($self->{_config} ? "-f $self->{_config} " : '' ) . + $package->as_file(); + + open(my $input, '-|', $command) or croak "Can't run $command: $!"; + my $pattern = qr/^[EW]: \S+ (\S+) (.*)$/; + while (my $line = <$input>) { + next unless $line =~ $pattern; + my $id = $1; + my $value = $2; + $errors .= "$id $value" + if $self->{_results}->{$id}; + } + close $input; + } + + croak $errors if $errors; +} +=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; diff --git a/lib/Youri/Submit/Test/Set.pm b/lib/Youri/Submit/Test/Set.pm new file mode 100644 index 0000000..2ed4994 --- /dev/null +++ b/lib/Youri/Submit/Test/Set.pm @@ -0,0 +1,79 @@ +# $Id: Set.pm 1687 2007-06-28 22:44:07Z guillomovitch $ +package Youri::Submit::Test::Set; + +=head1 NAME + +Youri::Submit::Test::Set - Packages set test + +=head1 DESCRIPTION + +This test rejects non-canonical packages set, meaning packages generated from +different sources packages, checking expected number or source and binaries +packages. + +=cut + +use warnings; +use strict; +use Carp; +use List::MoreUtils qw/all/; +use base qw/Youri::Submit::Step/; + +sub _init { + my $self = shift; + my %options = ( + min_sources => 1, + max_sources => 1, + min_binaries => 1, + max_binaries => undef, + @_ + ); + + $self->{_min_sources} = $options{min_sources}; + $self->{_max_sources} = $options{max_sources}; + $self->{_min_binaries} = $options{min_binaries}; + $self->{_max_binaries} = $options{max_binaries}; +} + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + my $errors; + + if (@$packages > 1) { + my $name = $packages->[0]->get_canonical_name(); + $errors .= "not a canonical package set\n" + unless + all { $_->get_canonical_name() eq $name } + @$packages; + } + + my $sources = grep { $_->is_source() } @$packages; + + $errors .= "number of source packages > $self->{_max_sources}\n" + if defined $self->{_max_sources} && $sources > $self->{_max_sources}; + + $errors .= "number of source packages < $self->{_min_sources}\n" + if defined $self->{_min_sources} && $sources < $self->{_min_sources}; + + my $binaries = grep { $_->is_binary() } @$packages; + + $errors .= "number of binary packages > $self->{_max_binaries}\n" + if defined $self->{_max_binaries} && $binaries > $self->{_max_binaries}; + + $errors .= "number of binary packages < $self->{_min_binaries}\n" + if defined $self->{_min_binaries} && $binaries < $self->{_min_binaries}; + + croak $errors if $errors; +} + +=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; diff --git a/lib/Youri/Submit/Test/Tag.pm b/lib/Youri/Submit/Test/Tag.pm new file mode 100644 index 0000000..59342e4 --- /dev/null +++ b/lib/Youri/Submit/Test/Tag.pm @@ -0,0 +1,58 @@ +# $Id: Tag.pm 1687 2007-06-28 22:44:07Z guillomovitch $ +package Youri::Submit::Test::Tag; + +=head1 NAME + +Youri::Submit::Test::Tag - Incorrect tag values test + +=head1 DESCRIPTION + +This test plugin rejects packages with incorrect tag values, based on regular +expressions. + +=cut + +use warnings; +use strict; +use Carp; +use base qw/Youri::Submit::Step/; + +sub _init { + my $self = shift; + my %options = ( + tags => undef, # expected tag values + @_ + ); + + croak "no tags to test" unless $options{tags}; + croak "tag should be an hashref" unless ref $options{tags} eq 'HASH'; + + $self->{_tags} = $options{tags}; +} + +sub process_packages { + my ($self, $packages, $repository, $target, $context) = @_; + croak "Not a class method" unless ref $self; + + my $errors; + + foreach my $package (@$packages) { + foreach my $tag (keys %{$self->{_tags}}) { + my $value = $package->get_tag($tag); + $errors .= "invalid value $value for tag $tag" + if $value !~ /$self->{_tags}->{$tag}/; + } + } + + croak $errors if $errors; +} + +=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; diff --git a/t/Makefile.am b/t/Makefile.am new file mode 100644 index 0000000..0fd009c --- /dev/null +++ b/t/Makefile.am @@ -0,0 +1,8 @@ +TESTS = perlcritic.t \ + install.t \ + sign.t \ + tags.t + +TESTS_ENVIRONMENT = perl -I $(top_srcdir)/lib + +EXTRA_DIST = $(TESTS) gpghome diff --git a/t/gpghome/pubring.gpg b/t/gpghome/pubring.gpg new file mode 100644 index 0000000..fcfc0e3 Binary files /dev/null and b/t/gpghome/pubring.gpg differ diff --git a/t/gpghome/random_seed b/t/gpghome/random_seed new file mode 100644 index 0000000..1b0201e Binary files /dev/null and b/t/gpghome/random_seed differ diff --git a/t/gpghome/secring.gpg b/t/gpghome/secring.gpg new file mode 100644 index 0000000..9017e4d Binary files /dev/null and b/t/gpghome/secring.gpg differ diff --git a/t/gpghome/trustdb.gpg b/t/gpghome/trustdb.gpg new file mode 100644 index 0000000..30712a3 Binary files /dev/null and b/t/gpghome/trustdb.gpg differ diff --git a/t/install.t b/t/install.t new file mode 100755 index 0000000..69113ff --- /dev/null +++ b/t/install.t @@ -0,0 +1,51 @@ +#!/usr/bin/perl +# $Id: install.t 1426 2006-12-17 21:00:25Z guillomovitch $ + +use Test::More tests => 3; +use Test::Exception; +use Youri::Repository::Test; +use Youri::Package::RPM::Generator; +use Youri::Package::RPM::URPM; +use Youri::Submit::Action::Install; + +my $writable_repository = Youri::Repository::Test->new(perms => '755'); +my $unwritable_repository = Youri::Repository::Test->new(perms => '000'); + +my $action = Youri::Submit::Action::Install->new( + skip => [ 'cheater' ] +); + +dies_ok { + $action->run( + Youri::Package::RPM::URPM->new( + file => Youri::Package::RPM::Generator->new()->get_source(), + ), + $unwritable_repository, + undef, + undef + ) +} 'installing in a non-writable directory'; + +lives_ok { + $action->run( + Youri::Package::RPM::URPM->new( + file => Youri::Package::RPM::Generator->new(tags => { + name => 'cheater', + })->get_source(), + ), + $unwritable_repository, + undef, + undef + ) +} 'installing in a non-writable directory with an exception'; + +lives_ok { + $action->run( + Youri::Package::RPM::URPM->new( + file => Youri::Package::RPM::Generator->new()->get_source(), + ), + $writable_repository, + undef, + undef + ) +} 'installing in a writable directory'; diff --git a/t/perlcritic.t b/t/perlcritic.t new file mode 100755 index 0000000..e929713 --- /dev/null +++ b/t/perlcritic.t @@ -0,0 +1,32 @@ +#!/usr/bin/perl +# $Id: perlcritic.t 1530 2007-03-08 20:42:13Z guillomovitch $ + +use strict; +use warnings; +use Test::More; +use File::Basename; +use File::Spec; + +if (!$ENV{TEST_AUTHOR}) { + plan( + skip_all => 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.' + ); +} + +eval { + require Test::Perl::Critic; +}; + +if ($@) { + plan( + skip_all => 'Test::Perl::Critic not installed, skipping' + ); +} + +Test::Perl::Critic->import(); +my $libdir = File::Spec->catdir( + dirname($0), + File::Spec->updir(), + 'lib' +); +all_critic_ok($libdir); diff --git a/t/set.t b/t/set.t new file mode 100755 index 0000000..ae44e3a --- /dev/null +++ b/t/set.t @@ -0,0 +1,124 @@ +#!/usr/bin/perl +# $Id: /local/youri/soft/submit/trunk/t/tags.t 3062 2007-06-28T16:21:35.624871Z guillaume $ + +use Test::More tests => 7; +use Test::Exception; +use Youri::Package::RPM::Test; +use Youri::Submit::Test::Set; + +my $test = Youri::Submit::Test::Set->new( + skip => [ 'bar' ] +); + +lives_ok { + $test->run( + undef, + undef, + undef, + [ + Youri::Package::RPM::Test->new(tags => { + arch => 'noarch' + }), + Youri::Package::RPM::Test->new(tags => { + arch => 'src', + }) + ] + ) +} 'one source and one binary package from the same source succeed'; + +throws_ok { + $test->run( + undef, + undef, + undef, + [ + Youri::Package::RPM::Test->new(tags => { + arch => 'src' + }), + Youri::Package::RPM::Test->new(tags => { + arch => 'noarch', + sourcerpm => 'other-1-1.src.rpm', + }) + ] + ) +} qr/not a canonical package set/, +'one source and one binary packages from different sources fails'; + +throws_ok { + $test->run( + undef, + undef, + undef, + [ + Youri::Package::RPM::Test->new(tags => { + arch => 'noarch' + }) + ] + ) +} qr/number of source packages < 1/, +'just one source binary fails'; + +throws_ok { + $test->run( + undef, + undef, + undef, + [ + Youri::Package::RPM::Test->new(tags => { + arch => 'src' + }) + ] + ) +} qr/number of binary packages < 1/, +'just one source binary fails'; + +throws_ok { + $test->run( + undef, + undef, + undef, + [ + Youri::Package::RPM::Test->new(tags => { + arch => 'src' + }), + Youri::Package::RPM::Test->new(tags => { + arch => 'src' + }), + ] + ) +} qr/number of source packages > 1/, +'two source packages fails'; + +lives_ok { + $test->run( + undef, + undef, + undef, + [ + Youri::Package::RPM::Test->new(tags => { + arch => 'src' + }), + Youri::Package::RPM::Test->new(tags => { + arch => 'noarch' + }), + Youri::Package::RPM::Test->new(tags => { + arch => 'noarch' + }) + ] + ) +} +'one source and two binary packages succedd'; + +lives_ok { + $test->run( + undef, + undef, + undef, + [ + Youri::Package::RPM::Test->new(tags => { + name => 'bar', + release => '1mdk' + }) + ] + ) +} 'non-compliant package with exception succeed'; diff --git a/t/sign.t b/t/sign.t new file mode 100755 index 0000000..db6f619 --- /dev/null +++ b/t/sign.t @@ -0,0 +1,57 @@ +#!/usr/bin/perl +# $Id: sign.t 1407 2006-12-03 12:02:02Z guillomovitch $ + +use Test::More tests => 3; +use Test::Exception; +use File::Basename; +use Youri::Package::RPM::Generator; +use Youri::Package::RPM::URPM; +use Youri::Submit::Action::Sign; + +my $action1 = Youri::Submit::Action::Sign->new( + name => 'Youri', + path => dirname($0) . '/gpghome', + passphrase => 'Youri sux', + skip => [ 'cheater' ] +); + +dies_ok { + $action1->run( + Youri::Package::RPM::URPM->new( + file => Youri::Package::RPM::Generator->new()->get_source(), + ), + undef, + undef, + undef + ) +} 'signing with wrong key'; + +lives_ok { + $action1->run( + Youri::Package::RPM::URPM->new( + file => Youri::Package::RPM::Generator->new(tags => { + name => 'cheater', + })->get_source(), + ), + undef, + undef, + undef + ) +} 'signing with wrong key using an exception'; + +my $action2 = Youri::Submit::Action::Sign->new( + name => 'Youri', + path => dirname($0) . '/gpghome', + passphrase => 'Youri rulez', +); + +lives_ok { + $action2->run( + Youri::Package::RPM::URPM->new( + file => Youri::Package::RPM::Generator->new()->get_source(), + ), + undef, + undef, + undef + ) +} 'signing with correct key'; diff --git a/t/tags.t b/t/tags.t new file mode 100755 index 0000000..4946799 --- /dev/null +++ b/t/tags.t @@ -0,0 +1,55 @@ +#!/usr/bin/perl +# $Id: tags.t 1687 2007-06-28 22:44:07Z guillomovitch $ + +use Test::More tests => 3; +use Test::Exception; +use Youri::Package::RPM::Test; +use Youri::Submit::Test::Tag; + +my $test = Youri::Submit::Test::Tag->new( + tags => { release => 'plf$' }, + skip => [ 'bar' ] +); + +lives_ok { + $test->run( + undef, + undef, + undef, + [ + Youri::Package::RPM::Test->new(tags => { + name => 'foo', + release => '1plf' + }) + ] + ) +} 'compliant package succeed'; + +throws_ok { + $test->run( + undef, + undef, + undef, + [ + Youri::Package::RPM::Test->new(tags => { + name => 'foo', + release => '1mdk' + }) + ] + ) +} qr/invalid value 1mdk for tag release/, +'non-compliant package fails'; + +lives_ok { + $test->run( + undef, + undef, + undef, + [ + Youri::Package::RPM::Test->new(tags => { + name => 'bar', + release => '1mdk' + }) + ], + ) +} 'non-compliant package with exception succeed'; -- cgit v1.2.1