Test::AutoBuild::Stage::CreateRepo - Create an package repository index for package management tools


Test-AutoBuild documentation Contained in the Test-AutoBuild distribution.

Index


Code Index:

NAME

Top

Test::AutoBuild::Stage::CreateRepo - Create an package repository index for package management tools

SYNOPSIS

Top

  use Test::AutoBuild::Stage::CreateRepo

  my $stage = Test::AutoBuild::Stage::CreateRepo->new(name => "crearerepo",
					       label => "Create package repository index",
					       options => {
						 directory => "/var/lib/builder/public_html/dist",
						 parameters => "-d -s -n",
					       });

  $stage->run($runtime);

DESCRIPTION

Top

This module invokes the createrepo(8) command to generate an index of RPM packages generated during the build. The index enables use of the yum(8) command to install packages generated by the builder. The crearerepo(8) command is expected to be found in the $PATH.

CONFIGURATION

Top

In addition to the standard parameters defined by the Test::AutoBuild::Stage module, this module accepts two entries in the options parameter:

directory

The full path to the directory containing RPMs to be indexed. If this option is not specified, then the directories option must be set.

directories

An array of paths to directories containing RPMs to be indexed. If this option is not specified, then the directory option must be set.

parameters

A string of command line arguments to be passed to the createrepo command, see the createrepo(8) manual page for details of possible values.

EXAMPLE

  {
    name = createrepo
    label = Update Pacakge Repository
    module = Test::AutoBuild::Stage::CreateRepo
    critical = 0
    options = {
      directory = /var/lib/builder/public_html/dist
      parameters = -d
    }
  }




METHODS

Top

$stage->process($runtime);

For each directory defined in the options parameter, this method will run the createrepo command to generate the index.

AUTHORS

Top

Daniel Berrange <dan@berrange.com> Dennis Gregorovic <dgregorovic@alum.mit.edu>

COPYRIGHT

Top

SEE ALSO

Top

perl(1), Test::AutoBuild::Stage, yum(8), createrepo(8)


Test-AutoBuild documentation Contained in the Test-AutoBuild distribution.
# -*- perl -*-
#
# Test::AutoBuild::Stage::CreateRepo
#
# Daniel Berrange <dan@berrange.com>
# Dennis Gregorovic <dgregorovic@alum.mit.edu>
#
# Copyright (C) 2004 Red Hat, Inc.
#
# 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 of the License, 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
#
# $Id: CreateRepo.pm,v 1.5 2007/12/08 17:35:16 danpb Exp $

package Test::AutoBuild::Stage::CreateRepo;

use base qw(Test::AutoBuild::Stage);
use warnings;
use strict;
use Log::Log4perl;

sub process {
    my $self = shift;
    my $runtime = shift;

    my $log = Log::Log4perl->get_logger();
    my $directories = $self->option('directories');
    if (!defined $directories) {
	my $dir = $self->option("directory");
	$directories = [$dir];
    }
    if (defined $directories) {
	foreach my $directory (@{$directories}) {
	    my $dirs = Test::AutoBuild::Lib::_expand_standard_macros([[ "", $directory, {} ]], $runtime);
	    foreach my $expanded_dir (@{$dirs}) {
		if (-d $expanded_dir->[1]) {
		    my $parameters = $self->option('parameters') ||  "";
		    my $cmdopt = $self->option("command") || {};
		    my $mod = $cmdopt->{module} || "Test::AutoBuild::Command::Local";
		    my $opts = $cmdopt->{options} || {};
		    eval "use $mod;";
		    die "cannot load $mod: $!" if $@;

		    my @cmd = ("createrepo",
			       ref($parameters)? @{$parameters} : ($parameters),
			       $expanded_dir->[1]);
		    my $c = $mod->new(cmd => \@cmd,
				      dir => $expanded_dir->[1],
				      options => $opts);

		    my ($output, $errors);
		    my $status = $c->run(\$output, \$errors);

		    $output = "" unless defined $output;
		    $errors = "" unless defined $errors;
		    my $log = Log::Log4perl->get_logger();
		    $log->debug("Output: [$output]") if $output;
		    $log->debug("Errors: [$errors]") if $errors;

		    die "command '" . join("' '", @cmd) . "' exited with status $status\n$errors" if $status;
		} else {
		    $log->warn("directory does not exists: " . $expanded_dir->[1]);
		}
	    }
	}
    }
}

1 # So that the require or use succeeds.

__END__