lib/Rex/Pkg/Gentoo.pm

filter: Statementstmt 18.9% 22 / 116 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 53.8% 7 / 13 Podpod 0.0% 0 / 6 totaltotal 14.2% 29 / 204 CC 35 SCAR 59.8
CC
35
Cov
12%
is_installed
702.0
add_repository
42.0
get_installed
12.0
CRAP 395.2
« lib/Rex/User/OpenBSD.pm ↑ Summary lib/Rex/User/NetBSD.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Pkg::Gentoo;
6  
7 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.16.1'; # VERSION
11  
12 1 ▶use Rex::Commands::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Rex::Commands::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Rex::Pkg::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use base qw(Rex::Pkg::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
19 0 my $that = shift;
20 0 ▶ my $proto = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
21 0 my $self = $proto->SUPER::new(@_);
22  
23 0 bless( $self, $proto );
24  
25 $self->{commands} = {
26 0 install => 'emerge --update --changed-use %s',
27 install_version => 'emerge --update --changed-use =%s-%s',
28 reinstall_check =>
29 'emerge --pretend --update --changed-use --nodeps --quiet --verbose =%s',
30 update_system => 'emerge --update --deep --with-bdeps=y --newuse world',
31 dist_update_system =>
32 'emerge --update --deep --with-bdeps=y --newuse world',
33 remove => 'emerge -C %s',
34 update_package_db => 'emerge --sync',
35 };
36  
37 0 return $self;
38 }
39  
40 0 ▶sub bulk_install {
Subroutine bulk_install: not called CC=1 SCAR=6.9
Pod undocumented
41 0 my ( $self, $packages_aref, $option ) = @_;
42  
43 0 delete $option->{version}; # makes no sense to specify the same version for several packages
44  
45 0 $self->update( "@{$packages_aref}", $option );
46  
47 0 return 1;
48 }
49  
50 0 ▶sub is_installed {
Subroutine is_installed: not called CC=26 SCAR=65.5
Pod undocumented
51  
52 0 my ( $self, $pkg, $option ) = @_;
53 0 my $slot;
54 0 my $version = $option->{version};
55  
56 # Determine slot.
57 0 my $slot_idx = index( $pkg, ':' );
58 0 ▶ if ( $slot_idx != -1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($slot_idx != -1) { } 0 0 0
elsif ($version) { } 0 0 0
59 0 ▶ die
Branch: 1 branch
BranchTrueFalseTotal
if $version and index($version, ":") != -1 0 0 0
Condition0%0/3
$version and index($version, ":") != -1
!ll&&!rl&&r
000
MC/DC0%0/2
$version and index($version, ":") != -1
$version index($version, ":") != -1
Truth table0%0/3
A and B
A= $versionB= index($version, ":") != -1
ABresult
0X0
100
111
60 "Illegal package spec. `$pkg-$version': Both package and version has SLOT"
61 if $version && index( $version, ':' ) != -1;
62 0 $slot = substr( $pkg, $slot_idx + 1 );
63 0 substr( $pkg, $slot_idx ) = '';
64 }
65 elsif ($version) {
66 0 $slot_idx = index( $version, ':' );
67 0 ▶ if ( $slot_idx != -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slot_idx != -1) 0 0 0
68 0 $slot = substr( $version, $slot_idx + 1 );
69 0 substr( $version, $slot_idx ) = '';
70 }
71 }
72  
73 0 $self->{short} = 0;
74 0 ▶ Rex::Logger::debug( "Checking if $pkg"
Branch: 2 branches
BranchTrueFalseTotal
$version ? : 0 0 0
$slot ? : 0 0 0
75 . ( $version ? "-$version" : "" )
76 . ( $slot ? ":$slot" : '' )
77 . " is installed" );
78  
79 0 my @pkg_info = grep { $_->{name} eq $pkg } $self->get_installed();
80 0 ▶ @pkg_info = grep { $_->{version} eq $version } @pkg_info if defined $version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $version 0 0 0
81  
82 0 ▶ unless (@pkg_info) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@pkg_info) 0 0 0
83 0 Rex::Logger::debug(
84 "Couldn't find package by category/packagename, trying with packagename only"
85 );
86 0 $self->{short} = 1;
87 0 @pkg_info = grep { $_->{name} eq $pkg } $self->get_installed();
88 0 ▶ @pkg_info = grep { $_->{version} eq $version } @pkg_info
Branch: 1 branch
BranchTrueFalseTotal
if defined $version 0 0 0
89 if defined $version;
90 }
91  
92 0 ▶ unless (@pkg_info) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@pkg_info) 0 0 0
93 0 ▶ Rex::Logger::debug( "$pkg"
Branch: 2 branches
BranchTrueFalseTotal
$version ? : 0 0 0
$slot ? : 0 0 0
94 . ( $version ? "-$version" : "" )
95 . ( $slot ? ":$slot" : '' )
96 . " is NOT installed." );
97 0 return 0;
98 }
99  
100 # Check for requested SLOT.
101 0 my $pkg_atom;
102  
103 0 ▶ if ( defined $slot ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $slot) { } 0 0 0
104 0 my $slot_ok;
105  
106 0 for my $info (@pkg_info) {
107 0 $pkg_atom =
108 "$info->{name}-$info->{version}$info->{suffix}$info->{release}";
109  
110 0 my $fh = file_read("/var/db/pkg/$pkg_atom/SLOT");
111 0 chomp( my $slot_installed = $fh->read_all );
112 0 $fh->close;
113  
114 0 ▶ if ( $slot eq $slot_installed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slot eq $slot_installed) 0 0 0
115 0 $pkg_atom .= ":$slot";
116 0 $slot_ok = 1;
117 0 last;
118 }
119 }
120  
121 0 ▶ unless ($slot_ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($slot_ok) 0 0 0
122 0 ▶ Rex::Logger::debug( "$pkg"
Branch: 2 branches
BranchTrueFalseTotal
$version ? : 0 0 0
$slot ? : 0 0 0
123 . ( $version ? "-$version" : "" )
124 . ( $slot ? ":$slot" : '' )
125 . " is NOT installed." );
126 0 return 0;
127 }
128 }
129 else {
130 0 $pkg_atom =
131 "$pkg_info[0]->{name}-$pkg_info[0]->{version}$pkg_info[0]->{suffix}$pkg_info[0]->{release}";
132 }
133  
134 # Check for any USE flag changes.
135 0 my $rchk_cmd = sprintf( $self->{commands}->{reinstall_check}, $pkg_atom );
136 0 my @rchk_out = i_run $rchk_cmd;
137  
138 0 for my $line (@rchk_out) {
139 0 ▶ next unless $line =~ /\s*\[ebuild[^]]+\]\s+$pkg_info[0]->{name}/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\s*\[ebuild[^]]+\]\s+$pkg_info[0]{"name"}/u 0 0 0
140  
141 0 ▶ Rex::Logger::debug( "$pkg"
Branch: 2 branches
BranchTrueFalseTotal
$version ? : 0 0 0
$slot ? : 0 0 0
142 . ( $version ? "-$version" : "" )
143 . ( $slot ? ":$slot" : '' )
144 . " is installed but USE flags have changed." );
145 0 return 0;
146 }
147  
148 0 ▶ Rex::Logger::debug( "$pkg"
Branch: 2 branches
BranchTrueFalseTotal
$version ? : 0 0 0
$slot ? : 0 0 0
149 . ( $version ? "-$version" : "" )
150 . ( $slot ? ":$slot" : '' )
151 . " is installed." );
152 0 return 1;
153  
154 }
155  
156 0 ▶sub get_installed {
Subroutine get_installed: not called CC=3 SCAR=24.8
Pod undocumented
157 0 my ($self) = @_;
158 0 my $cut_cmd;
159 0 ▶ if ( $self->{short} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'short'}) { } 0 0 0
160 0 $cut_cmd = "cut -d '/' -f6-";
161 }
162 else {
163 0 $cut_cmd = "cut -d '/' -f5-";
164 }
165  
166 # ,,stolen'' from epm
167 0 my $pkgregex = '(.+?)' . # name
168 '-(\d+(?:\.\d+)*\w*)' . # version, eg 1.23.4a
169 '((?:(?:_alpha|_beta|_pre|_rc)\d*)?)' . # special suffix
170 '((?:-r\d+)?)$'; # revision, eg r12
171  
172 0 my @ret;
173  
174 0 for my $line ( i_run("ls -d /var/db/pkg/*/* | $cut_cmd") ) {
175 0 my $r = qr{$pkgregex};
176 0 my ( $name, $version, $suffix, $revision ) = ( $line =~ $r );
177 0 push(
178 @ret,
179 {
180 name => $name,
181 version => $version,
182 suffix => $suffix,
183 release => $revision,
184 }
185 );
186 }
187  
188 0 return @ret;
189 }
190  
191 0 ▶sub add_repository {
Subroutine add_repository: not called CC=6 SCAR=37.4
Pod undocumented
192 0 my ( $self, %data ) = @_;
193  
194 0 my $name = $data{"name"};
195 0 ▶ my $readd = $data{"readd"} // 0;
Condition0%0/2
$data{"readd"} // 0
l!l
00
MC/DC0%0/1
$data{"readd"} // 0
$data{"readd"}
Truth table0%0/2
A
A= $data{"readd"}
Aresult
11
00
196  
197 0 ▶ if ( can_run("layman") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (can_run('layman')) { } 0 0 0
198 0 my $op;
199  
200 0 i_run "layman -lqnN | grep -q '$name'", fail_ok => 1;
201 0 ▶ if ( $? == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? == 0) { } 0 0 0
202 0 ▶ if ($readd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($readd) { } 0 0 0
203 0 $op = 'r'; # --readd
204 }
205 else {
206 0 Rex::Logger::info(
207 "Repository $name is present, use `readd' option to re-add from scratch."
208 );
209 }
210 }
211 else {
212 0 $op = 'a'; # --add
213 }
214 0 ▶ i_run "layman -$op $name" if defined $op;
Branch: 1 branch
BranchTrueFalseTotal
if defined $op 0 0 0
215 }
216 else {
217 0 Rex::Logger::debug("You have to install layman, git and subversion.");
218 0 die("Please install layman, git and subversion");
219 }
220 }
221  
222 0 ▶sub rm_repository {
Subroutine rm_repository: not called CC=2 SCAR=17.9
Pod undocumented
223 0 my ( $self, $name ) = @_;
224  
225 0 ▶ if ( can_run("layman") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (can_run('layman')) { } 0 0 0
226 0 i_run "layman -d $name";
227 }
228 else {
229 0 Rex::Logger::debug("You have to install layman, git and subversion.");
230 0 die("Please install layman, git and subversion");
231 }
232 }
233  
234 1 1;
« lib/Rex/User/OpenBSD.pm ↑ Summary lib/Rex/User/NetBSD.pm »