diff -r 8d28864d1ba1 -r 8397c7a3e5b1 bin/imager.list --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/imager.list Wed Sep 07 19:38:02 2011 +0200 @@ -0,0 +1,94 @@ +#! /usr/bin/perl + +use 5.010; +use strict; +use warnings; +use Pod::Usage; +use Hash::Util qw(lock_keys); +use File::Find; +use Digest::MD5 qw(md5_hex); +use File::Basename; +use autodie qw(:all); +use Imager; + +use Getopt::Long; + +our %o = ( + latest => undef, +); +lock_keys(%o); + +MAIN: { + my $dir; + + Getopt::Long::Configure qw(Bundling); + GetOptions( + "latest" => \$o{latest}, + "h|help" => sub { pod2usage(-verbose => 1, -exit => 0) }, + "m|man" => sub { + pod2usage( + -verbose => 2, + -exit => 0, + -noperldoc => system( + "perldoc -V 1>/dev/null + 2>&1" + ) + ); + }, + ) + and defined ($dir = shift) + or pod2usage; + + my (%by_day, %by_dev); + find(sub{ + return if not (-f and /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ$/); + my ($host, $dev) = dirname($File::Find::name) =~ /^\Q$dir\/idx\E\/(.+?)(\/.*)/; + push @{$by_day{$_}}, "$host\::$dev"; + push @{$by_dev{"$host\::$dev"}}, $_; + }, "$dir/idx"); + + # by dev + my $l = (sort { $b <=> $a } map { length } keys %by_dev)[0]; + foreach (sort keys %by_dev) { + my $prefix = $_; + foreach ((reverse sort @{$by_dev{$_}})) { + printf "%-*s: %s\n", $l => $prefix, $_; + last if $o{latest}; + $prefix = " "; + } + } + +} + +__END__ + +=head1 NAME + + imager.list - list the images created by imager + +=head1 SYNOPSIS + + imager.list [options] {directory} + +=head1 DESCRIPTION + +B lists the index files (images) the imager created. + + +=head1 OPTIONS + +=over + +=item B<--latest> + +List only the latest backups. (default: list all) + +=item B<-h>|B<--help> + +=item B<-m>|B<--man> + +The short and longer help. + +=back + +=cut