aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ Pipkin <j@dawnrazor.net>2013-01-03 02:36:27 -0600
committerJ Pipkin <j@dawnrazor.net>2013-01-03 02:36:27 -0600
commitfa2ffaf281e5b8212a4b0dd96519c0dd35166fc1 (patch)
tree5156b906c567159d3e879d71ab24c7b5a27f93b1
parenta6f6c1525b6f8e564456b9eb6961bf69eebd735e (diff)
downloadsbotools2-fa2ffaf281e5b8212a4b0dd96519c0dd35166fc1.tar.xz
use sprintf for formatting sbocheck output instead of Text::Tabulate
-rwxr-xr-xsbocheck26
-rwxr-xr-xt/test.t3
2 files changed, 18 insertions, 11 deletions
diff --git a/sbocheck b/sbocheck
index 73bf7c1..da3a3b8 100755
--- a/sbocheck
+++ b/sbocheck
@@ -14,7 +14,6 @@ use strict;
use warnings FATAL => 'all';
use SBO::Lib;
use Getopt::Long;
-use Text::Tabulate;
use File::Basename;
my $self = basename($0);
@@ -45,30 +44,35 @@ update_tree;
sub get_update_list() {
print "Checking for updated SlackBuilds...\n";
my $updates = get_available_updates;
- # pretty formatting.
+ # consistent formatting - first we need the minimum length for name-version
+ my @lengths;
+ push @lengths, length "$$updates[$_]{name}-$$updates[$_]{installed}"
+ for keys @$updates;
+ my @s_lengths = sort {$b <=> $a} @lengths;
+ my $min = $s_lengths[0];
+ $min = 37 if $min > 37;
+
my @listing;
for my $update (@$updates) {
- my $string = "$$update{name}-$$update{installed}";
- $string .= " < needs updating (SBo has $$update{update})\n";
- push @listing, $string;
+ push(@listing, sprintf "%-${min}s < needs updating (SBo has %s)",
+ "$$update{name}-$$update{installed}", "$$update{update}");
}
return \@listing;
}
-# Text::Tabulate and print list of updates
+# print list of updates
sub print_output($) {
exists $_[0] or script_error 'print_output requires an argument';
my $listing = shift;
if (exists $$listing[0]) {
- my $tab = new Text::Tabulate();
- $tab->configure(tab => '\s');
- my $output = $tab->format(@$listing);
- say "\n". $output;
+ print "\n";
+ say $_ for @$listing;
+ print "\n";
# save a log of available updates
my $logfile = '/var/log/sbocheck.log';
unlink $logfile if -f $logfile;
my $log_fh = open_fh($logfile, '>');
- print {$log_fh} $output;
+ say {$log_fh} $_ for @$listing;
close $log_fh;
say "A copy of the above result is kept in $logfile\n";
} else {
diff --git a/t/test.t b/t/test.t
index d69ef34..8c2979a 100755
--- a/t/test.t
+++ b/t/test.t
@@ -247,10 +247,13 @@ is($$info[0], "", 'get_from_info GET => DOWNLOAD_x86_64 is good');
# get_update_list tests
my $listing = get_update_list;
+say $_ for @$listing;
s/\s//g for @$listing;
for my $item (@$listing) {
is($item, 'ffmpeg-0.8.7<needsupdating(SBohas0.11.1)',
'get_update_list output good for ffmpeg') if $item =~ /^ffmpeg/;
+ is($item, 'libdvdnav-4.1.3<needsupdating(SBohas4.2.0)',
+ 'get_update_list output test, libdvdnav') if $item =~ /^libdvdnav/;
is($item, 'mutagen-1.15<needsupdating(SBohas1.20)',
'get_update_list output good for mutagen') if $item =~ /^atkmm/;
}