Arepa/CommandManager.pm

filter: Statementstmt 30.8% 29 / 94 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 9 / 18 Podpod 0.0% 0 / 7 totaltotal 26.0% 38 / 146 CC 15 SCAR 29.8
CC
15
Cov
25%
request_source_pkg_compilation
56.0
recompile_request
30.0
ui_module
12.0
CRAP 19.8
« Arepa/Web/Public.pm ↑ Summary Arepa/Job/CompilePackage.pm »
1 package Arepa::CommandManager;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use TheSchwartz;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Arepa::BuilderFarm;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Arepa::Repository;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Arepa::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Arepa::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Arepa::Job::CompilePackage;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 my $ui_module = 'Arepa::UI::Text';
16  
17 0 ▶sub ui_module {
Subroutine ui_module: not called CC=3 SCAR=24.8
Pod undocumented
18 0 my ($self, $module) = @_;
19  
20 0 Arepa::Builder->ui_module($module);
21 0 ▶ if (defined $module) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $module) 0 0 0
22 0 $ui_module = $module;
23 }
24 0 eval qq(use $ui_module;);
25 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
26 0 return $ui_module;
27 }
28  
29 0 ▶sub print {
Subroutine print: not called CC=1 SCAR=6.9
Pod undocumented
30 0 my ($self, @args) = @_;
31 0 $self->ui_module->print(@args);
32 }
33  
34 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
35 0 my ($class, $config_file) = @_;
36  
37 0 return bless {
38 config_file => $config_file,
39 farm => Arepa::BuilderFarm->new($config_file),
40 repository => Arepa::Repository->new($config_file),
41 },
42 $class;
43 }
44  
45 0 ▶sub _farm { $_[0]->{farm} }
Subroutine _farm: not called CC=1 SCAR=6.9
46 0 ▶sub _repository { $_[0]->{repository} }
Subroutine _repository: not called CC=1 SCAR=6.9
47  
48 0 ▶sub build_pending {
Subroutine build_pending: not called CC=1 SCAR=6.9
Pod undocumented
49 0 my ($self) = @_;
50  
51 0 my $conf = Arepa::Config->new($self->{config_file});
52 0 my $client = TheSchwartz->new(databases => [
53 { dsn => "dbi:SQLite:dbname=" . $conf->get_key('package_db') }
54 ]);
55 0 $client->can_do('Arepa::Job::CompilePackage');
56 0 $Arepa::Job::CompilePackage::PrintMessages = 1;
57 0 $client->work_until_done();
58 }
59  
60 0 ▶sub recompile_request {
Subroutine recompile_request: not called CC=5 SCAR=34.0
Pod undocumented
61 0 my ($self, $request_id) = @_;
62  
63 0 my %req = $self->_farm->package_db->
64 get_compilation_request_by_id($request_id);
65  
66 # Find out the builder for this compilation. If it's not claimed by any
67 # builder, get the first matching (there should be only one, really)
68 0 my $builder = $req{builder};
69 0 ▶ if (!$builder) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($builder) 0 0 0
70 ($builder) = $self->_farm->get_matching_builders($req{architecture},
71 0 $req{distribution});
72 }
73  
74 my %source_attrs = $self->_farm->package_db->
75 0 get_source_package_by_id($req{source_package_id});
76 0 $self->print("Compiling request id $req{id}\n");
77 0 $self->print("$source_attrs{name} ");
78 0 $self->print("$source_attrs{full_version} ");
79 0 $self->print("(arch: $req{architecture}, ");
80 0 $self->print("distro: $req{distribution}) ");
81 0 $self->print("with builder $builder...\n");
82 0 my $temp_dir = File::Temp::tempdir();
83 0 ▶ if ($self->_farm->compile_package_from_queue($builder,
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_farm->compile_package_from_queue($builder, $req{'id'}, 'output_dir', $temp_dir)) { } 0 0 0
84 $req{id},
85 output_dir => $temp_dir)) {
86 0 $self->print(" done.\n");
87 0 foreach my $deb_package (glob('*.deb')) {
88 0 $self->print("Adding $deb_package to the repository\n");
89 0 ▶ if ($self->_repository->
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_repository->insert_binary_package($deb_package, $req{"distribution"})) 0 0 0
90 insert_binary_package($deb_package,
91 $req{distribution})) {
92 0 unlink $deb_package;
93 }
94 }
95 0 $self->_repository->sign_distribution($req{distribution});
96 }
97 else {
98 0 $self->print(" failed.\n");
99 0 $self->print("Log:\n".$self->_farm->last_build_log."\n");
100 }
101 0 rmtree($temp_dir);
102 }
103  
104 0 ▶sub build_dsc {
Subroutine build_dsc: not called CC=3 SCAR=24.8
Pod undocumented
105 0 my ($self, $builder, $dsc_file) = @_;
106  
107 0 my $temp_dir = File::Temp::tempdir();
108 0 $self->_farm->compile_package_from_dsc($builder, $dsc_file,
109 output_dir => $temp_dir);
110 0 foreach my $deb_package (glob('*.deb')) {
111 0 $self->print("Adding $deb_package to the repository\n");
112 0 ▶ if ($self->_repository->insert_binary_package($deb_package)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_repository->insert_binary_package($deb_package)) 0 0 0
113 0 unlink $deb_package;
114 }
115 }
116 0 rmtree($temp_dir);
117 }
118  
119 0 ▶sub request_source_pkg_compilation {
Subroutine request_source_pkg_compilation: not called CC=7 SCAR=40.3
Pod undocumented
120 0 my ($self, $source_pkg, $distro, $arch) = @_;
121  
122 0 my $pkg_db = $self->_farm->package_db;
123 0 my $source_id = $pkg_db->get_source_package_id($source_pkg, '*latest*');
124 0 ▶ if ($source_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source_id) { } 0 0 0
125 0 my @targets = $self->_farm->get_compilation_targets($source_id);
126 0 my $target_found = 0;
127 0 foreach my $target (@targets) {
128 0 my ($target_arch, $target_distro) = @$target;
129  
130 0 ▶ if ((!defined($arch) || $target_arch eq $arch) &&
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($arch) || $target_arch eq $arch and $target_distro eq $distro) 0 0 0
Condition0%0/6
!defined($arch) || $target_arch eq $arch and $target_distro eq $distro
!ll&&!rl&&r
000
not defined $arch or $target_arch eq $arch
l!l&&r!l&&!r
000
MC/DC0%0/3
!defined($arch) || $target_arch eq $arch and $target_distro eq $distro
not defined $arch $target_arch eq $arch $target_distro eq $distro
Truth table0%0/5
not(A) or B and C
A= not defined $archB= $target_arch eq $archC= $target_distro eq $distro
ABCresult
00X0
1X00
0100
1X11
0111
131 $target_distro eq $distro) {
132 0 $target_found = 1;
133 0 $pkg_db->request_compilation($source_id,
134 $target_arch,
135 $target_distro);
136 }
137 }
138 0 ▶ if (! $target_found) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $target_found) 0 0 0
139 die "Distribution $distro (arch $arch) is not a valid target " .
140 "for $source_pkg.\nValid targets are: " .
141 0 join(", ", map { "$_->[0]/$_->[1]" } @targets) . "\n";
142 }
143 }
144 else {
145 0 die "Couldn't find source package $source_pkg\n";
146 }
147 }
148  
149 1 1;
« Arepa/Web/Public.pm ↑ Summary Arepa/Job/CompilePackage.pm »