| 1 | package PkgForge::BuildTopic; # -*-perl-*- | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | # $Id: BuildTopic.pm.in 16580 2011-04-05 10:03:29Z squinney@INF.ED.AC.UK $ | ||
| 6 | # $Source:$ | ||
| 7 | # $Revision: 16580 $ | ||
| 8 | # $HeadURL: https://svn.lcfg.org/svn/source/tags/PkgForge-Server/PkgForge_Server_1_1_10/lib/PkgForge/BuildTopic.pm.in $ | ||
| 9 | # $Date: 2011-04-05 11:03:29 +0100 (Tue, 05 Apr 2011) $ | ||
| 10 | |||
| 11 | our $VERSION = '1.1.10'; | ||
| 12 | |||
| 13 | use English qw(-no_match_vars); | ||
| 14 | use File::Copy (); | ||
| 15 | use File::Spec (); | ||
| 16 | |||
| 17 | use Moose; | ||
| 18 | use MooseX::Types::Moose qw(Bool Str); | ||
| 19 | use PkgForge::Types qw(SourcePackageList); | ||
| 20 | |||
| 21 | with 'MooseX::LogDispatch'; | ||
| 22 | |||
| 23 | has 'debug' => ( | ||
| 24 | is => 'rw', | ||
| 25 | isa => Bool, | ||
| 26 | default => 0, | ||
| 27 | documentation => 'Turn on the printing of debug statements', | ||
| 28 | ); | ||
| 29 | |||
| 30 | has 'job' => ( | ||
| 31 | is => 'ro', | ||
| 32 | isa => 'PkgForge::Job', | ||
| 33 | required => 1, | ||
| 34 | handles => [qw/bucket/], | ||
| 35 | documentation => 'The job to be built', | ||
| 36 | ); | ||
| 37 | |||
| 38 | has 'resultsdir' => ( | ||
| 39 | is => 'ro', | ||
| 40 | isa => Str, | ||
| 41 | required => 1, | ||
| 42 | documentation => 'Where the results and log files for a build job should be stored' | ||
| 43 | ); | ||
| 44 | |||
| 45 | has 'logfile' => ( | ||
| 46 | is => 'ro', | ||
| 47 | isa => Str, | ||
| 48 | required => 1, | ||
| 49 | lazy => 1, | ||
| 50 | default => sub { | ||
| 51 | my $self = shift @_; | ||
| 52 | my $logfile = File::Spec->catfile( $self->logdir, | ||
| 53 | 'pkgforge-build.log' ); | ||
| 54 | }, | ||
| 55 | documentation => 'The PkgForge build log file', | ||
| 56 | ); | ||
| 57 | |||
| 58 | has 'logdir' => ( | ||
| 59 | is => 'ro', | ||
| 60 | isa => Str, | ||
| 61 | required => 1, | ||
| 62 | documentation => 'Where the pkgforge build log will be stored' | ||
| 63 | ); | ||
| 64 | |||
| 65 | has 'sources' => ( | ||
| 66 | traits => ['Array'], | ||
| 67 | is => 'rw', | ||
| 68 | isa => SourcePackageList, | ||
| 69 | default => sub { [] }, | ||
| 70 | handles => { | ||
| 71 | 'sources_list' => 'elements', | ||
| 72 | }, | ||
| 73 | documentation => 'The set of source packages to be built', | ||
| 74 | ); | ||
| 75 | |||
| 76 | has 'log_dispatch_conf' => ( | ||
| 77 | is => 'ro', | ||
| 78 | isa => 'HashRef', | ||
| 79 | lazy => 1, | ||
| 80 | required => 1, | ||
| 81 | default => sub { | ||
| 82 | my $self = shift; | ||
| 83 | |||
| 84 | return { | ||
| 85 | class => 'Log::Dispatch::File', | ||
| 86 | min_level => 'debug', | ||
| 87 | filename => $self->logfile, | ||
| 88 | mode => 'append', | ||
| 89 | format => '[%d] [%p] %m%n', | ||
| 90 | close_on_write => 1, | ||
| 91 | }; | ||
| 92 | }, | ||
| 93 | documentation => 'The configuration for Log::Dispatch', | ||
| 94 | ); | ||
| 95 | |||
| 96 | no Moose; | ||
| 97 | __PACKAGE__->meta->make_immutable; | ||
| 98 | |||
| 99 | sub store_logs { | ||
| 100 | my ( $self, @files ) = @_; | ||
| 101 | |||
| 102 | my $logger = $self->logger; | ||
| 103 | |||
| 104 | my $resultsdir = $self->resultsdir; | ||
| 105 | |||
| 106 | for my $file (@files) { | ||
| 107 | if ($self->debug) { | ||
| 108 | $logger->debug("Storing $file in $resultsdir"); | ||
| 109 | } | ||
| 110 | File::Copy::copy( $file, $resultsdir ) | ||
| 111 | or $logger->log_and_die( | ||
| 112 | level => 'critical', | ||
| 113 | message => "Could not copy $file to $resultsdir: $OS_ERROR" | ||
| 114 | ); | ||
| 115 | } | ||
| 116 | |||
| 117 | return 1; | ||
| 118 | } | ||
| 119 | |||
| 120 | sub store_results { | ||
| 121 | my ( $self, @files ) = @_; | ||
| 122 | |||
| 123 | my $logger = $self->logger; | ||
| 124 | |||
| 125 | my $resultsdir = $self->resultsdir; | ||
| 126 | |||
| 127 | for my $file (@files) { | ||
| 128 | if ($self->debug) { | ||
| 129 | $logger->debug("Storing $file in $resultsdir"); | ||
| 130 | } | ||
| 131 | File::Copy::copy( $file, $resultsdir ) | ||
| 132 | or $logger->log_and_die( | ||
| 133 | level => 'critical', | ||
| 134 | message => "Could not copy $file to $resultsdir: $OS_ERROR" | ||
| 135 | ); | ||
| 136 | } | ||
| 137 | |||
| 138 | return 1; | ||
| 139 | } | ||
| 140 | |||
| 141 | sub finish { | ||
| 142 | my ($self) = @_; | ||
| 143 | |||
| 144 | my $logfile = $self->logfile; | ||
| 145 | my $resultsdir = $self->resultsdir; | ||
| 146 | |||
| 147 | if ( -f $logfile ) { | ||
| 148 | File::Copy::copy( $logfile, $resultsdir ) | ||
| 149 | or die "Could not copy $logfile to $resultsdir: $OS_ERROR\n"; | ||
| 150 | } | ||
| 151 | |||
| 152 | return 1; | ||
| 153 | } | ||
| 154 | |||
| 155 | |||
| 156 | |||
| 157 | 1; | ||
| 158 | __END__ |