Slackget/PkgTools.pm

filter: Statementstmt 14.7% 15 / 102 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 36.3% 4 / 11 Podpod 100% 4 / 4 totaltotal 14.5% 23 / 158 CC 23 SCAR 31.6
CC
23
Cov
11%
install
42.0
upgrade
42.0
new
20.0
CRAP 23.5
« Slackget/SpecialFiles/FILELIST.pm ↑ Summary Slackget/GPG/Signature.pm »
1 package Slackware::Slackget::PkgTools;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 require Slackware::Slackget::Status ;
7 2 ▶use File::Copy ;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 PKG_INSTALL_OK => 0x43001,
11 PKG_UPGRADE_OK => 0x43003,
12 PKG_REMOVE_OK => 0x43005,
13 PKG_INSTALL_FAIL => 0x43002,
14 PKG_UPGRADE_FAIL => 0x43004,
15 PKG_REMOVE_FAIL => 0x43006,
16 PKG_NOT_FOUND_INSTALL_FAIL => 0x43007,
17 PKG_NOT_FOUND_UPGRADE_FAIL => 0x43008,
18 PKG_NOT_FOUND_REMOVE_FAIL => 0x43009,
19 PKG_UNKNOWN_FAIL => 0x43010,
20 2 };
21  
22 =head1 NAME
23  
24 Slackware::Slackget::PkgTools - A wrapper for the pkgtools action(installpkg, upgradepkg and removepkg)
25  
26 =head1 VERSION
27  
28 Version 1.0.21
29  
30 =cut
31  
32 2 our $VERSION = '1.0.21';
33  
34 =head1 SYNOPSIS
35  
36 This class is anoter wrapper for slack-get. It encapsulates the pkgtools system call.
37  
38 use Slackware::Slackget::PkgTools;
39  
40 my $pkgtool = Slackware::Slackget::PkgTools->new($config);
41 $pkgtool->install($package1);
42 $pkgtool->remove($package_list);
43 foreach (@{$packagelist->get_all})
44 {
45 print "Status for ",$_->name," : ",$_->status()->to_string,"\n";
46 }
47 $pkgtool->upgrade($package_list);
48  
49 =cut
50  
51 sub new
52 0 ▶{
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
53 0 my ($class,$config,%args) = @_ ;
54 0 ▶ return undef if(!defined($config) && ref($config) ne 'Slackware::Slackget::Config') ;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $config and ref $config ne "Slackware::Slackget::Config" 0 0 0
Condition0%0/3
not defined $config and ref $config ne "Slackware::Slackget::Config"
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $config and ref $config ne "Slackware::Slackget::Config"
not defined $config ref $config ne "Slackware::Slackget::Config"
Truth table0%0/3
not(A) and B
A= not defined $configB= ref $config ne "Slackware::Slackget::Config"
ABresult
0X0
100
111
55 0 my $self={};
56 0 $self->{CONF} = $config ;
57 $self->{SUCCESS_STATUS} = {
58 0 Slackware::Slackget::PkgTools::PKG_INSTALL_OK => "Package have been installed successfully.",
59 Slackware::Slackget::PkgTools::PKG_UPGRADE_OK => "Package have been upgraded successfully.",
60 Slackware::Slackget::PkgTools::PKG_REMOVE_OK => "Package have been removed successfully.",
61 };
62 $self->{ERROR_STATUS}={
63 0 Slackware::Slackget::PkgTools::PKG_NOT_FOUND_INSTALL_FAIL => "Can't install package : new package not found in the cache.",
64 Slackware::Slackget::PkgTools::PKG_NOT_FOUND_REMOVE_FAIL => "Can't remove package : no such package installed.",
65 Slackware::Slackget::PkgTools::PKG_NOT_FOUND_UPGRADE_FAIL => "Can't upgrade package : new package not found in the cache.",
66 Slackware::Slackget::PkgTools::PKG_INSTALL_FAIL => "Can't install package : an error occured during $self->{CONF}->{common}->{pkgtools}->{'installpkg-binary'} system call",
67 Slackware::Slackget::PkgTools::PKG_REMOVE_FAIL => "Can't remove package : an error occured during $self->{CONF}->{common}->{pkgtools}->{'removepkg-binary'} system call",
68 Slackware::Slackget::PkgTools::PKG_UPGRADE_FAIL => "Can't upgrade package : an error occured during $self->{CONF}->{common}->{pkgtools}->{'upgradepkg-binary'} system call",
69 Slackware::Slackget::PkgTools::PKG_UNKNOWN_FAIL => "An error occured in the Slackware::Slackget::PkgTool class (during installpkg, upgradepkg or removepkg) but the class is unable to understand the error.",
70 };
71 $self->{DATA} = {
72 0 'info-output' => undef,
73 'connection-id' => 0,
74 'fake_mode' => 0,
75 };
76 0 ▶ $self->{DATA}->{'fake_mode'} = $args{'fake_mode'} if(defined($args{'fake_mode'}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"fake_mode"} 0 0 0
77 0 bless($self,$class);
78 #
79 # use Data::Dumper;
80 # print Dumper($self);
81
82 0 return $self;
83 }
84  
85 =head1 CONSTRUCTOR
86  
87 =head2 new
88  
89 Take a Slackware::Slackget::Config object as argument :
90  
91 my $pkgtool = new Slackware::Slackget::PkgTool ($config);
92  
93 ** IMPORTANT NOTE ** : in the old time, when this module was poorly coded (by me) it was taking care of sending network messages.
94 This is obviously not its role, so it do not do that anymore.
95  
96 =cut
97  
98 =head1 FUNCTIONS
99  
100 Slackware::Slackget::PkgTools methods used the followings status :
101  
102 0 : Package have been installed successfully.
103 1 : Package have been upgraded successfully.
104 2 : Package have been removed successfully.
105 3 : Can't install package : new package not found in the cache.
106 4 : Can't remove package : no such package installed.
107 5 : Can't upgrade package : new package not found in the cache.
108 6 : Can't install package : an error occured during <installpkg-binary /> system call
109 7 : Can't remove package : an error occured during <removepkg-binary /> system call
110 8 : Can't upgrade package : an error occured during <upgradepkg-binary /> system call
111 9 : Package scheduled for install on next reboot.
112 10 : An error occured in the Slackware::Slackget::PkgTool class (during installpkg, upgradepkg or removepkg) but the class is unable to understand the error.
113  
114 =head2 install
115  
116 Take a single Slackware::Slackget::Package object or a single Slackware::Slackget::PackageList as argument and call installpkg on all this packages.
117 Return 1 or undef if an error occured. But methods from the Slackware::Slackget::PkgTools class don't return on the first error, it will try to install all packages. Additionnally, for each package, set a status.
118  
119 $pkgtool->install($package_list);
120  
121 =cut
122  
123 0 ▶sub install {
Subroutine install: not called CC=6 SCAR=37.4
Pod documented
124
125 sub _install_package
126 0 ▶ {
Subroutine _install_package: not called CC=3 SCAR=24.8
127 0 my ($self,$pkg) = @_;
128 0 my $status = new Slackware::Slackget::Status (success_codes => $self->{SUCCESS_STATUS}, error_codes => $self->{ERROR_STATUS});
129 0 ▶ if( -e "$self->{CONF}->{common}->{'update-directory'}/package-cache/lock/".$pkg->get_id.".tgz")
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$self->{'CONF'}{'common'}{'update-directory'}/package-cache/lock/" . $pkg->get_id . '.tgz') { } 0 0 0
130 {
131 0 print "\tTrying to install package: $self->{CONF}->{common}->{'update-directory'}/package-cache/lock/".$pkg->get_id.".tgz\n";
132 0 ▶ if(system("$self->{CONF}->{common}->{pkgtools}->{'installpkg-binary'} $self->{CONF}->{common}->{'update-directory'}/package-cache/lock/".$pkg->get_id.".tgz")==0)
Branch: 1 branch
BranchTrueFalseTotal
if (system("$self->{'CONF'}{'common'}{'pkgtools'}{'installpkg-binary'} $self->{'CONF'}{'common'}{'update-directory'}/package-cache/lock/" . $pkg->get_id . '.tgz') == 0) { } 0 0 0
133 {
134 0 print "Slackware::Slackget::install: package successfully installed.\n";
135 0 $status->current(PKG_INSTALL_OK);
136 0 return $status ;
137 }
138 else
139 {
140 0 print "Slackware::Slackget::install: an error occured while installing package.\n";
141 0 $status->current(PKG_INSTALL_FAIL);
142 0 return $status ;
143 }
144 }
145 else
146 {
147 0 $status->current(PKG_NOT_FOUND_INSTALL_FAIL);
148 0 print "\tUnable to install package: $self->{CONF}->{common}->{'update-directory'}/package-cache/lock/".$pkg->get_id.".tgz\n";
149 0 return $status ;
150 }
151 }
152 0 my ($self,$object) = @_;
153 0 ▶ if( -e $object ){
Branch: 3 branches
BranchTrueFalseTotal
if (-e $object) { } 0 0 0
elsif (ref $object eq 'Slackware::Slackget::PackageList') { } 0 0 0
elsif (ref $object eq 'Slackware::Slackget::Package') { } 0 0 0
154 0 print "Slackware::Slackget::install: installing package from a file name (not a Slackware::Slackget::Package)\n";
155 0 my $status = new Slackware::Slackget::Status (success_codes => $self->{SUCCESS_STATUS}, error_codes => $self->{ERROR_STATUS});
156 0 ▶ if(system("$self->{CONF}->{common}->{pkgtools}->{'installpkg-binary'} $object")==0)
Branch: 1 branch
BranchTrueFalseTotal
if (system("$self->{'CONF'}{'common'}{'pkgtools'}{'installpkg-binary'} $object") == 0) { } 0 0 0
157 {
158 0 $status->current(PKG_INSTALL_OK);
159 0 return $status ;
160 }
161 else
162 {
163 0 $status->current(PKG_INSTALL_FAIL);
164 0 return $status ;
165 }
166 0 return $status ;
167 }
168 elsif(ref($object) eq 'Slackware::Slackget::PackageList')
169 {
170 # print "[install] Do the job for a Slackware::Slackget::PackageList\n";
171 0 foreach my $pack ( @{ $object->get_all() })
172 {
173 # print "[install] sending ",$pack->get_id," to _install_package.\n";
174 0 $pack->status($self->_install_package($pack));
175 }
176 # print "[install] end of the install loop.\n";
177 }
178 elsif(ref($object) eq 'Slackware::Slackget::Package')
179 {
180 # print "[install] Do the job for a Slackware::Slackget::Package '$object'\n";
181 0 $object->status($self->_install_package($object));
182 }
183 else
184 {
185 0 return undef;
186 }
187 # print "[Slackware::Slackget::PkgTools DEBUG] all job processed.\n";
188 }
189  
190 =head2 upgrade
191  
192 Take a single Slackware::Slackget::Package object or a single Slackware::Slackget::PackageList as argument and call upgradepkg on all this packages.
193 Return 1 or undef if an error occured. But methods from the Slackware::Slackget::PkgTools class don't return on the first error, it will try to install all packages. Additionnally, for each package, set a status.
194  
195 $pkgtool->install($package_list) ;
196  
197 =cut
198  
199 0 ▶sub upgrade {
Subroutine upgrade: not called CC=6 SCAR=37.4
Pod documented
200
201 sub _upgrade_package
202 0 ▶ {
Subroutine _upgrade_package: not called CC=3 SCAR=24.8
203 0 my ($self,$pkg) = @_;
204 0 my $status = new Slackware::Slackget::Status (success_codes => $self->{SUCCESS_STATUS}, error_codes => $self->{ERROR_STATUS});
205 #$self->{CONF}->{common}->{'update-directory'}/".$server->shortname."/cache/
206 0 ▶ if( -e "$self->{CONF}->{common}->{'update-directory'}/package-cache/lock/".$pkg->get_id.".tgz")
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$self->{'CONF'}{'common'}{'update-directory'}/package-cache/lock/" . $pkg->get_id . '.tgz') { } 0 0 0
207 {
208 0 print "\tTrying to upgrade package: $self->{CONF}->{common}->{'update-directory'}/package-cache/lock/".$pkg->get_id.".tgz\n";
209 0 ▶ if(system("$self->{CONF}->{common}->{pkgtools}->{'upgradepkg-binary'} $self->{CONF}->{common}->{'update-directory'}/package-cache/lock/".$pkg->get_id.".tgz")==0)
Branch: 1 branch
BranchTrueFalseTotal
if (system("$self->{'CONF'}{'common'}{'pkgtools'}{'upgradepkg-binary'} $self->{'CONF'}{'common'}{'update-directory'}/package-cache/lock/" . $pkg->get_id . '.tgz') == 0) { } 0 0 0
210 {
211 0 $status->current(PKG_UPGRADE_OK);
212 0 return $status ;
213 }
214 else
215 {
216 0 $status->current(PKG_UPGRADE_FAIL);
217 0 return $status ;
218 }
219 }
220 else
221 {
222 0 $status->current(PKG_NOT_FOUND_UPGRADE_FAIL);
223 0 print "\tUnable to upgrade package: $self->{CONF}->{common}->{'update-directory'}/package-cache/lock/".$pkg->get_id.".tgz\n";
224 0 return $status ;
225 }
226 }
227 0 my ($self,$object) = @_;
228 0 ▶ if( -e $object ){
Branch: 3 branches
BranchTrueFalseTotal
if (-e $object) { } 0 0 0
elsif (ref $object eq 'Slackware::Slackget::PackageList') { } 0 0 0
elsif (ref $object eq 'Slackware::Slackget::Package') { } 0 0 0
229 0 my $status = new Slackware::Slackget::Status (success_codes => $self->{SUCCESS_STATUS}, error_codes => $self->{ERROR_STATUS});
230 0 ▶ if(system("$self->{CONF}->{common}->{pkgtools}->{'upgradepkg-binary'} $object")==0)
Branch: 1 branch
BranchTrueFalseTotal
if (system("$self->{'CONF'}{'common'}{'pkgtools'}{'upgradepkg-binary'} $object") == 0) { } 0 0 0
231 {
232 0 $status->current(PKG_UPGRADE_OK);
233 0 return $status ;
234 }
235 else
236 {
237 0 $status->current(PKG_UPGRADE_FAIL);
238 0 return $status ;
239 }
240 0 return $status ;
241 }
242 elsif(ref($object) eq 'Slackware::Slackget::PackageList')
243 {
244 # print "Do the job for a Slackware::Slackget::PackageList\n";
245 0 foreach my $pack ( @{ $object->get_all() })
246 {
247 0 $pack->status($self->_upgrade_package($pack));
248 }
249 }
250 elsif(ref($object) eq 'Slackware::Slackget::Package')
251 {
252 0 print "Slackware::Slackget::upgrade: Do the job for a Slackware::Slackget::Package\n";
253 0 $object->status($self->_upgrade_package($object));
254 }
255 else
256 {
257 0 print "Slackware::Slackget::upgrade: returning an undefined value for because \$object do not match required types.\n";
258 0 return undef;
259 }
260 }
261  
262 =head2 remove
263  
264 Take a single Slackware::Slackget::Package object or a single Slackware::Slackget::PackageList as argument and call installpkg on all this packages.
265 Return 1 or undef if an error occured. But methods from the Slackware::Slackget::PkgTools class don't return on the first error, it will try to install all packages. Additionnally, for each package, set a status.
266  
267 $pkgtool->remove($package_list);
268  
269 =cut
270  
271 0 ▶sub remove {
Subroutine remove: not called CC=4 SCAR=30.0
Pod documented
272
273 sub _remove_package
274 0 ▶ {
Subroutine _remove_package: not called CC=3 SCAR=24.8
275 0 my ($self,$pkg) = @_;
276 0 my $status = new Slackware::Slackget::Status (success_codes => $self->{SUCCESS_STATUS}, error_codes => $self->{ERROR_STATUS});
277 #$self->{CONF}->{common}->{'update-directory'}/".$server->shortname."/cache/
278 0 ▶ if( -e "$self->{CONF}->{common}->{'packages-history-dir'}/".$pkg->get_id)
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$self->{'CONF'}{'common'}{'packages-history-dir'}/" . $pkg->get_id) { } 0 0 0
279 {
280 # print "\tTrying to remove package: ".$pkg->get_id."\n";
281 # TODO: the error output is not logged anymore in the PkgTools calls. It must be fixed.
282 0 ▶ if(system("$self->{CONF}->{common}->{pkgtools}->{'removepkg-binary'} ".$pkg->get_id)==0)
Branch: 1 branch
BranchTrueFalseTotal
if (system("$self->{'CONF'}{'common'}{'pkgtools'}{'removepkg-binary'} " . $pkg->get_id) == 0) { } 0 0 0
283 {
284 0 print "[Slackware::Slackget::PkgTools] (removepkg) setting (success) status ",PKG_REMOVE_OK,"\n";
285 0 $status->current(PKG_REMOVE_OK);
286 0 return $status ;
287 }
288 else
289 {
290 0 print "[Slackware::Slackget::PkgTools] (removepkg) setting (failed) status ",PKG_REMOVE_FAIL,"\n";
291 0 $status->current(PKG_REMOVE_FAIL);
292 0 return $status ;
293 }
294 }
295 else
296 {
297 0 print "[Slackware::Slackget::PkgTools] (removepkg) setting (fail) status ",PKG_NOT_FOUND_REMOVE_FAIL,"\n";
298 0 $status->current(PKG_NOT_FOUND_REMOVE_FAIL);
299 0 return $status ;
300 }
301 }
302 0 my ($self,$object) = @_;
303 0 ▶ if(ref($object) eq 'Slackware::Slackget::PackageList')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $object eq 'Slackware::Slackget::PackageList') { } 0 0 0
elsif (ref $object eq 'Slackware::Slackget::Package') { } 0 0 0
304 {
305 # print "Do the job for a Slackware::Slackget::PackageList\n";
306 0 foreach my $pack ( @{ $object->get_all() })
307 {
308 0 $pack->status($self->_remove_package($pack));
309 }
310 }
311 elsif(ref($object) eq 'Slackware::Slackget::Package')
312 {
313 # print "Do the job for a Slackware::Slackget::Package\n";
314 0 $object->status($self->_remove_package($object));
315 }
316 else
317 {
318 0 return undef;
319 }
320 }
321  
322 =head1 AUTHOR
323  
324 DUPUIS Arnaud, C<< <a.dupuis@infinityperl.org> >>
325  
326 =head1 BUGS
327  
328 Please report any bugs or feature requests to
329 C<bug-Slackware-Slackget@rt.cpan.org>, or through the web interface at
330 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Slackware-Slackget>.
331 I will be notified, and then you'll automatically be notified of progress on
332 your bug as I make changes.
333  
334 =head1 SUPPORT
335  
336 You can find documentation for this module with the perldoc command.
337  
338 perldoc Slackware::Slackget
339  
340  
341 You can also look for information at:
342  
343 =over 4
344  
345 =item * Infinity Perl website
346  
347 L<http://www.infinityperl.org/category/slack-get>
348  
349 =item * slack-get specific website
350  
351 L<http://slackget.infinityperl.org>
352  
353 =item * RT: CPAN's request tracker
354  
355 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Slackware-Slackget>
356  
357 =item * AnnoCPAN: Annotated CPAN documentation
358  
359 L<http://annocpan.org/dist/Slackware-Slackget>
360  
361 =item * CPAN Ratings
362  
363 L<http://cpanratings.perl.org/d/Slackware-Slackget>
364  
365 =item * Search CPAN
366  
367 L<http://search.cpan.org/dist/Slackware-Slackget>
368  
369 =back
370  
371 =head1 ACKNOWLEDGEMENTS
372  
373 Thanks to Bertrand Dupuis (yes my brother) for his contribution to the documentation.
374  
375 =head1 SEE ALSO
376  
377 =head1 COPYRIGHT & LICENSE
378  
379 Copyright 2005 DUPUIS Arnaud, All Rights Reserved.
380  
381 This program is free software; you can redistribute it and/or modify it
382 under the same terms as Perl itself.
383  
384 =cut
385  
386 2 1; # End of Slackware::Slackget::PkgTools
« Slackget/SpecialFiles/FILELIST.pm ↑ Summary Slackget/GPG/Signature.pm »