CAPE-Utils
view release on metacpan or search on metacpan
lib/CAPE/Utils.pm view on Meta::CPAN
if ( $column eq 'ET' ) {
$row->{ET} = $row->{enforce_timeout};
}
if (
(
$column eq 'clock'
|| $column eq 'added_on'
|| $column eq 'started_on'
|| $column eq 'completed_on'
|| $column eq 'analysis_started_on'
|| $column eq 'analysis_finished_on'
|| $column eq 'processing_started_on'
|| $column eq 'processing_finished_on'
|| $column eq 'signatures_started_on'
|| $column eq 'signatures_finished_on'
|| $column eq 'reporting_started_on'
|| $column eq 'reporting_finished_on'
|| $column eq 'latest'
)
&& $opts{task_time_clip}
)
{
$row->{$column} =~ s/\.[0-9]+$//;
} elsif ( $column eq 'target' && $opts{task_target_clip} ) {
$row->{target} =~ s/^.*\///;
}
push( @new_line, $row->{$column} );
} else {
push( @new_line, '' );
}
} ## end foreach my $column (@columns)
push( @td, \@new_line );
} ## end foreach my $row ( @{$rows} )
$tb->add_rows( \@td );
return $tb->draw;
} ## end sub get_tasks_table
=head2 munge
Munges the specified report file.
$cape_utils->munge(file=>$report_file);
=cut
sub munge {
my ( $self, %opts ) = @_;
if ( !defined( $opts{file} ) ) {
die('No file specified via $opts{file}');
}
if ( !-f $opts{file} ) {
die( '"' . $opts{file} . '" is not a file' );
}
# create a backup copy prior to munging
# also only create it if it does not exist
my $pre_munge_file = $opts{file} . '.pre-cape_utils_munge';
if ( !-f $pre_munge_file ) {
copy( $opts{file}, $pre_munge_file )
|| die( 'Creating pre-munge file for "' . $opts{file} . '" failed... ' . $! );
} else {
warn( 'Pre-munge file, "' . $pre_munge_file . '", already exists, skippying coppying' );
}
# read the file on in
my $report;
eval { $report = decode_json( read_file( $opts{file} ) ); };
if ($@) {
die( 'Failed to parse "' . $opts{file} . '"... ' . $@ );
}
# find the munge keys
my @sections = sort( keys( %{ $self->{config} } ) );
my @munges;
foreach my $item (@sections) {
if ( $item =~ /^munge\_/ ) {
push( @munges, $item );
}
}
# should be set by a munge if it made a change
my $changed = 0;
# scratch space for between all munges
my %all_scratch;
foreach my $item (@munges) {
# scratch space for the munges to use
my %scratch;
# only process the specified munge if we have both keys
if ( defined( $self->{config}{$item}{check} ) && defined( $self->{config}{$item}{munge} ) ) {
# now that we know we have the keys, get the full file path if needed
my $check_file = $self->{config}{$item}{check};
my $munge_file = $self->{config}{$item}{munge};
if ( $check_file !~ /^\// && $check_file !~ /^.\// && $check_file !~ /^..\// ) {
$check_file = '/usr/local/etc/cape_utils_munge/' . $check_file;
}
if ( $munge_file !~ /^\// && $munge_file !~ /^.\// && $munge_file !~ /^..\// ) {
$munge_file = '/usr/local/etc/cape_utils_munge/' . $munge_file;
}
# figure out if we need to munge it or not
my $munge_it = 0;
eval {
my $check_code = read_file($check_file);
eval($check_code);
if ($@) {
die($@);
}
};
if ($@) {
warn( 'Munge "' . $item . '" errored during the check... ' . $@ );
# override this even if set before dying
$munge_it = 0;
}
( run in 1.466 second using v1.01-cache-2.11-cpan-4ef0a570458 )