2008-11-25 11:01:42 +00:00
|
|
|
package Hydra::View::TT;
|
2008-10-28 10:19:31 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use base 'Catalyst::View::TT';
|
2013-01-22 22:48:02 +01:00
|
|
|
use Hydra::Helper::Nix;
|
2021-03-09 18:27:34 +01:00
|
|
|
use Time::Seconds;
|
2008-10-28 10:19:31 +00:00
|
|
|
|
2013-01-22 22:48:02 +01:00
|
|
|
__PACKAGE__->config(
|
|
|
|
TEMPLATE_EXTENSION => '.tt',
|
2014-05-01 16:33:25 +02:00
|
|
|
ENCODING => 'utf-8',
|
2013-02-05 14:00:09 +01:00
|
|
|
PRE_CHOMP => 1,
|
|
|
|
POST_CHOMP => 1,
|
2021-03-09 18:27:34 +01:00
|
|
|
expose_methods => [qw/buildLogExists buildStepLogExists jobExists relativeDuration stripSSHUser/]);
|
2008-10-28 10:19:31 +00:00
|
|
|
|
2013-08-30 13:53:25 +00:00
|
|
|
sub buildLogExists {
|
|
|
|
my ($self, $c, $build) = @_;
|
2017-04-05 17:55:56 +02:00
|
|
|
return 1 if defined $c->config->{log_prefix};
|
2013-08-30 13:53:25 +00:00
|
|
|
my @outPaths = map { $_->path } $build->buildoutputs->all;
|
|
|
|
return defined findLog($c, $build->drvpath, @outPaths);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub buildStepLogExists {
|
|
|
|
my ($self, $c, $step) = @_;
|
2017-04-05 17:55:56 +02:00
|
|
|
return 1 if defined $c->config->{log_prefix};
|
2013-08-30 13:53:25 +00:00
|
|
|
my @outPaths = map { $_->path } $step->buildstepoutputs->all;
|
|
|
|
return defined findLog($c, $step->drvpath, @outPaths);
|
2013-04-26 13:23:34 +02:00
|
|
|
}
|
|
|
|
|
2021-03-09 18:27:34 +01:00
|
|
|
=head2 relativeDuration
|
|
|
|
|
|
|
|
Given an integer of seconds, return an English representation of the
|
|
|
|
duration as a string.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
|
|
|
=over 1
|
|
|
|
|
|
|
|
=item C<$seconds>
|
|
|
|
|
|
|
|
An integer number of seconds
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
=cut
|
|
|
|
sub relativeDuration {
|
|
|
|
my ($self, $c, $seconds) = @_;
|
|
|
|
return Time::Seconds->new($seconds)->pretty();
|
|
|
|
}
|
|
|
|
|
2015-06-17 13:49:18 +02:00
|
|
|
sub stripSSHUser {
|
|
|
|
my ($self, $c, $name) = @_;
|
|
|
|
if ($name =~ /^.*@(.*)$/) {
|
|
|
|
return $1;
|
|
|
|
} else {
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-08 18:49:10 +02:00
|
|
|
# Check whether the given job is a member of the most recent jobset
|
|
|
|
# evaluation.
|
|
|
|
sub jobExists {
|
2020-05-27 20:09:36 +02:00
|
|
|
my ($self, $c, $jobset, $jobName) = @_;
|
|
|
|
return defined $jobset->builds->search({ job => $jobName, iscurrent => 1 })->single;
|
2014-04-08 18:49:10 +02:00
|
|
|
}
|
|
|
|
|
2008-10-28 10:19:31 +00:00
|
|
|
1;
|