| 1 | package Test::Smoke::Archiver; | ||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 3 | our $VERSION = '0.001'; | |||||||||
| 6 | |||||||||||
| 7 | 3 | ▶ | use base 'Test::Smoke::ObjectBase'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use Test::Smoke::LogMixin; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 3 | ▶ | use File::Copy; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 3 | ▶ | use File::Path; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 3 | ▶ | use File::Spec::Functions; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 3 | ▶ | use Test::Smoke::Util qw/get_patch/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | =head1 NAME | ||||||||||
| 16 | |||||||||||
| 17 | Test::Smoke::Archiver - Archive the smoke files. | ||||||||||
| 18 | |||||||||||
| 19 | =head1 DESCRIPTION | ||||||||||
| 20 | |||||||||||
| 21 | =head2 Test::Smoke::Archiver->new(%arguments) | ||||||||||
| 22 | |||||||||||
| 23 | =head3 Arguments | ||||||||||
| 24 | |||||||||||
| 25 | =over | ||||||||||
| 26 | |||||||||||
| 27 | =item archive => [0|1] | ||||||||||
| 28 | |||||||||||
| 29 | =item ddir => $smoke_destination_directory | ||||||||||
| 30 | |||||||||||
| 31 | =item adir => $archive_destination_directory | ||||||||||
| 32 | |||||||||||
| 33 | =item outfile => 'mktest.out' | ||||||||||
| 34 | |||||||||||
| 35 | =item rptfile => 'mktest.rpt' | ||||||||||
| 36 | |||||||||||
| 37 | =item jsnfile => 'mktest.jsn' | ||||||||||
| 38 | |||||||||||
| 39 | =item lfile => $logfile_name | ||||||||||
| 40 | |||||||||||
| 41 | =item v => [0|1|2] | ||||||||||
| 42 | |||||||||||
| 43 | =back | ||||||||||
| 44 | |||||||||||
| 45 | =head3 Returns | ||||||||||
| 46 | |||||||||||
| 47 | The instance... | ||||||||||
| 48 | |||||||||||
| 49 | =cut | ||||||||||
| 50 | |||||||||||
| 51 | 3 | my %CONFIG = ( | |||||||||
| 52 | df_archive => 1, | ||||||||||
| 53 | df_ddir => '.', | ||||||||||
| 54 | df_adir => undef, | ||||||||||
| 55 | |||||||||||
| 56 | df_outfile => 'mktest.out', | ||||||||||
| 57 | df_rptfile => 'mktest.rpt', | ||||||||||
| 58 | df_jsnfile => 'mktest.jsn', | ||||||||||
| 59 | df_lfile => undef, | ||||||||||
| 60 | |||||||||||
| 61 | df_v => 0, | ||||||||||
| 62 | ); | ||||||||||
| 63 | |||||||||||
| 64 | 3 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 65 | 3 | my $class = shift; | |||||||||
| 66 | 3 | my %args = @_; | |||||||||
| 67 | |||||||||||
| 68 | 3 | my %struct; | |||||||||
| 69 | 3 | for my $dfkey (keys %CONFIG) { | |||||||||
| 70 | 24 | (my $key = $dfkey) =~ s/^df_//; | |||||||||
| 71 | 24 | ▶ | $struct{"_$key"} = exists $args{$key} ? $args{$key} : $CONFIG{$dfkey}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 3 | my $self = bless \%struct, $class; | |||||||||
| 75 | |||||||||||
| 76 | 3 | return $self; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | =head2 $archiver->archive_files() | ||||||||||
| 80 | |||||||||||
| 81 | Copy files. | ||||||||||
| 82 | |||||||||||
| 83 | =cut | ||||||||||
| 84 | |||||||||||
| 85 | 1 | ▶ | sub archive_files { | ||||||||
|
Subroutine
archive_files: called CC=8 SCAR=22.2
| |||||||||||
| 86 | 1 | my $self = shift; | |||||||||
| 87 | 1 | ▶ | if (!$self->archive) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | 0 | return $self->log_info("Skipping archive: --noarchive."); | |||||||||
| 89 | } | ||||||||||
| 90 | 1 | ▶ | if (!$self->adir) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 0 | return $self->log_info("Skipping archive: No archive directory set."); | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 1 | ▶ | if (!-d $self->adir) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | 1 | open my $ch, '>', \my $output; | |||||||||
| 96 | 1 | my $stdout = select $ch; | |||||||||
| 97 | 1 | ▶ | mkpath($self->adir, 1, 0775) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 0 | or die "Cannot mkpath(@{[$self->adir]}): $!"; | |||||||||
| 99 | 1 | select $stdout; | |||||||||
| 100 | 1 | $self->log_debug($_) for split /\n/, $output; | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | 1 | (my $patch_level = get_patch($self->ddir)->[0]) =~ tr/ //sd; | |||||||||
| 104 | 1 | $self->{_patchlevel} = $patch_level; | |||||||||
| 105 | |||||||||||
| 106 | 1 | my @archived; | |||||||||
| 107 | 1 | for my $filetype (qw/rpt out jsn/) { | |||||||||
| 108 | 3 | my $to_archive = "archive_$filetype"; | |||||||||
| 109 | 3 | my $filename = "${filetype}file"; | |||||||||
| 110 | 3 | ▶ | push @archived, $self->$filename if $self->$to_archive; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | } | ||||||||||
| 112 | 1 | return \@archived; | |||||||||
| 113 | } | ||||||||||
| 114 | |||||||||||
| 115 | =head2 $archiver->archive_rpt | ||||||||||
| 116 | |||||||||||
| 117 | =cut | ||||||||||
| 118 | |||||||||||
| 119 | 1 | ▶ | sub archive_rpt { | ||||||||
|
Subroutine
archive_rpt: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||
| 120 | 1 | my $self = shift; | |||||||||
| 121 | 1 | my $src = catfile($self->ddir, $self->rptfile); | |||||||||
| 122 | 1 | ▶ | if (! -f $src) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 0 | return $self->log_info("%s not found: skip archive rpt", $src); | |||||||||
| 124 | } | ||||||||||
| 125 | 1 | my $dst = catfile($self->adir, sprintf("rpt%s.rpt", $self->patchlevel)); | |||||||||
| 126 | 1 | ▶ | if (-f $dst) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 127 | 0 | return $self->log_info("%s exists, skip archive rpt", $dst); | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | 1 | my $success = copy($src, $dst); | |||||||||
| 131 | 1 | ▶ | if (!$success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 132 | 0 | $self->log_warn("Failed to cp(%s,%s): %s", $src, $dst, $!); | |||||||||
| 133 | } | ||||||||||
| 134 | else { | ||||||||||
| 135 | 1 | $self->log_info("Copy(%s, %s): ok", $src, $dst); | |||||||||
| 136 | } | ||||||||||
| 137 | 1 | return $success; | |||||||||
| 138 | } | ||||||||||
| 139 | |||||||||||
| 140 | =head2 $archiver->archive_out | ||||||||||
| 141 | |||||||||||
| 142 | =cut | ||||||||||
| 143 | |||||||||||
| 144 | 1 | ▶ | sub archive_out { | ||||||||
|
Subroutine
archive_out: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||
| 145 | 1 | my $self = shift; | |||||||||
| 146 | 1 | my $src = catfile($self->ddir, $self->outfile); | |||||||||
| 147 | 1 | ▶ | if (! -f $src) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 148 | 0 | return $self->log_info("%s not found: skip archive out", $src); | |||||||||
| 149 | } | ||||||||||
| 150 | 1 | my $dst = catfile($self->adir, sprintf("out%s.out", $self->patchlevel)); | |||||||||
| 151 | 1 | ▶ | if (-f $dst) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 152 | 0 | return $self->log_info("%s exists, skip archive out", $dst); | |||||||||
| 153 | } | ||||||||||
| 154 | |||||||||||
| 155 | 1 | my $success = copy($src, $dst); | |||||||||
| 156 | 1 | ▶ | if (!$success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 157 | 0 | $self->log_warn("Failed to cp(%s,%s): %s", $src, $dst, $!); | |||||||||
| 158 | } | ||||||||||
| 159 | else { | ||||||||||
| 160 | 1 | $self->log_info("Copy(%s, %s): ok", $src, $dst); | |||||||||
| 161 | } | ||||||||||
| 162 | 1 | return $success; | |||||||||
| 163 | } | ||||||||||
| 164 | |||||||||||
| 165 | =head2 $archiver->archive_jsn | ||||||||||
| 166 | |||||||||||
| 167 | =cut | ||||||||||
| 168 | |||||||||||
| 169 | 1 | ▶ | sub archive_jsn { | ||||||||
|
Subroutine
archive_jsn: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||
| 170 | 1 | my $self = shift; | |||||||||
| 171 | 1 | my $src = catfile($self->ddir, $self->jsnfile); | |||||||||
| 172 | 1 | ▶ | if (! -f $src) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 173 | 0 | return $self->log_info("%s not found: skip archive jsn", $src); | |||||||||
| 174 | } | ||||||||||
| 175 | 1 | my $dst = catfile($self->adir, sprintf("jsn%s.jsn", $self->patchlevel)); | |||||||||
| 176 | 1 | ▶ | if (-f $dst) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 177 | 0 | return $self->log_info("%s exists, skip archive jsn", $dst); | |||||||||
| 178 | } | ||||||||||
| 179 | |||||||||||
| 180 | 1 | my $success = copy($src, $dst); | |||||||||
| 181 | 1 | ▶ | if (!$success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 182 | 0 | $self->log_warn("Failed to cp(%s,%s): %s", $src, $dst, $!); | |||||||||
| 183 | } | ||||||||||
| 184 | else { | ||||||||||
| 185 | 1 | $self->log_info("Copy(%s, %s): ok", $src, $dst); | |||||||||
| 186 | } | ||||||||||
| 187 | 1 | return $success; | |||||||||
| 188 | } | ||||||||||
| 189 | |||||||||||
| 190 | =head2 $archiver->archive_log | ||||||||||
| 191 | |||||||||||
| 192 | =cut | ||||||||||
| 193 | |||||||||||
| 194 | 0 | ▶ | sub archive_log { | ||||||||
|
Subroutine
archive_log: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 195 | 0 | my $self = shift; | |||||||||
| 196 | 0 | my $src = $self->lfile; | |||||||||
| 197 | 0 | ▶ | if (! -f $src) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 198 | 0 | return $self->log_info("%s not found: skip archive log", $src); | |||||||||
| 199 | } | ||||||||||
| 200 | 0 | my $dst = catfile($self->adir, sprintf("log%s.log", $self->patchlevel)); | |||||||||
| 201 | 0 | ▶ | if (-f $dst) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 202 | 0 | return $self->log_info("%s exists, skip archive log", $dst); | |||||||||
| 203 | } | ||||||||||
| 204 | |||||||||||
| 205 | 0 | my $success = copy($src, $dst); | |||||||||
| 206 | 0 | ▶ | if (!$success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 207 | 0 | $self->log_warn("Failed to cp(%s,%s): %s", $src, $dst, $!); | |||||||||
| 208 | } | ||||||||||
| 209 | else { | ||||||||||
| 210 | 0 | $self->log_info("Copy(%s, %s): ok", $src, $dst); | |||||||||
| 211 | } | ||||||||||
| 212 | 0 | return $success; | |||||||||
| 213 | } | ||||||||||
| 214 | |||||||||||
| 215 | 3 | 1; | |||||||||
| 216 | |||||||||||
| 217 | =head1 COPYRIGHT | ||||||||||
| 218 | |||||||||||
| 219 | (c) 2002-2013, Abe Timmerman <abeltje@cpan.org> All rights reserved. | ||||||||||
| 220 | |||||||||||
| 221 | With contributions from Jarkko Hietaniemi, Merijn Brand, Campo | ||||||||||
| 222 | Weijerman, Alan Burlison, Allen Smith, Alain Barbet, Dominic Dunlop, | ||||||||||
| 223 | Rich Rauenzahn, David Cantrell. | ||||||||||
| 224 | |||||||||||
| 225 | This library is free software; you can redistribute it and/or modify | ||||||||||
| 226 | it under the same terms as Perl itself. | ||||||||||
| 227 | |||||||||||
| 228 | See: | ||||||||||
| 229 | |||||||||||
| 230 | =over 4 | ||||||||||
| 231 | |||||||||||
| 232 | =item * L<http://www.perl.com/perl/misc/Artistic.html> | ||||||||||
| 233 | |||||||||||
| 234 | =item * L<http://www.gnu.org/copyleft/gpl.html> | ||||||||||
| 235 | |||||||||||
| 236 | =back | ||||||||||
| 237 | |||||||||||
| 238 | This program is distributed in the hope that it will be useful, | ||||||||||
| 239 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||
| 240 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||
| 241 | |||||||||||
| 242 | =cut | ||||||||||