1package Magus::Run;
2#
3# Copyright (c) 2008 Chris Reinhardt. All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9# 1. Redistributions of source code must retain the above copyright notice
10#    this list of conditions and the following disclaimer.
11#
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
17# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27
28#
29# MAINTAINER=   ctriv@MidnightBSD.org
30#
31
32use strict;
33use warnings;
34use base qw(Magus::DBI);
35
36
37__PACKAGE__->table('runs');
38__PACKAGE__->columns(Essential => qw/id osversion arch status created blessed/);
39
40__PACKAGE__->has_many(ports => 'Magus::Port');
41
42=head2 Magus::Run->latest($machine)
43
44Takes a machine, and returns the latest active run for that machine's osversion and arch.
45
46=cut
47
48sub latest {
49  my ($class, $machine) = @_;
50
51  return $class->search(
52    osversion => $machine->osversion,
53    arch      => $machine->arch,
54    status    => 'active',
55    { order_by => 'id DESC' }
56  )->next;
57}
58
59
60=head2 $run->is_empty();
61
62Returns true if the run has no ports left to be tested
63
64=cut
65
66sub is_empty {
67  my ($self) = @_;
68
69  # if there is a locked port, then there may be new ports once this one is done.
70  return 0 if Magus::Lock->search_by_run($self)->count;
71
72  return Magus::Port->get_ready_port($self) ? 0 : 1;
73}
74
75
76=head2 $run->tarball
77
78Returns the run's tarball filename (no path)
79
80=cut
81
82sub tarball {
83  my ($self) = @_;
84  my $id = $self->id;
85
86  return "mports-tree-$id.tar.bz2"
87}
88
89=head2 $run->tarballpath
90
91Returns the absolute path to the tarball (including scp information if you're
92on a node).  This is implemented as:
93
94 "$Magus::Config{MasterDataDir}/$Magus::Conig{MportsSnapDir}/" . $run->tarball
95
96=cut
97
98sub tarballpath {
99  return "$Magus::Config{MasterDataDir}/$Magus::Config{MportsSnapDir}/" . shift->tarball;
100}
101
102
1031;
104__END__
105
106