summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-02-28 18:47:35 +0100
committerDaniel Friesel <derf@finalrewind.org>2011-02-28 18:47:35 +0100
commit37a7b741692997d8cf7ecc371dc5c829a388067d (patch)
tree0a1ec749d6f8e53fba40c56a4304c8a8974ea2a1
parent46cd0526adfe160984e36dcfc7af208b7ba6cd38 (diff)
Move CLI code from App::Dthumb to bin/dthumb
-rwxr-xr-xbin/dthumb30
-rwxr-xr-xlib/App/Dthumb.pm65
2 files changed, 33 insertions, 62 deletions
diff --git a/bin/dthumb b/bin/dthumb
index 64c527a..ced3a78 100755
--- a/bin/dthumb
+++ b/bin/dthumb
@@ -8,8 +8,13 @@ use autodie;
use App::Dthumb;
use Getopt::Long qw(:config no_ignore_case);
+use IO::Handle;
+use Time::Progress;
+
+STDERR->autoflush(1);
my $opt = {};
+my $id = 1;
GetOptions(
$opt,
@@ -25,8 +30,31 @@ GetOptions(
) or die("Please see perldoc -F $0\n");
my $dthumb = App::Dthumb->new($opt);
+my $timer = Time::Progress->new();
+
+
+$dthumb->check_cmd_flags();
+$dthumb->read_directories();
+$dthumb->create_files();
+$dthumb->delete_old_thumbnails();
+
+$timer->attr(
+ min => 1,
+ max => scalar $dthumb->get_files(),
+);
+
+for my $file ($dthumb->get_files()) {
+ print STDERR $timer->report(
+ "\r\e[KCreating Thumbnails: %p done, %L elapsed, %E remaining",
+ $id++,
+ );
+
+ $dthumb->create_thumbnail_html($file);
+ $dthumb->create_thumbnail_image($file);
+}
+print "\n";
-$dthumb->run();
+$dthumb->write_out_html();
__END__
diff --git a/lib/App/Dthumb.pm b/lib/App/Dthumb.pm
index f2cf875..bb5a4ce 100755
--- a/lib/App/Dthumb.pm
+++ b/lib/App/Dthumb.pm
@@ -45,14 +45,10 @@ use base 'Exporter';
use App::Dthumb::Data;
use Cwd;
use Image::Imlib2;
-use IO::Handle;
-use Time::Progress;
our @EXPORT_OK = ();
our $VERSION = '0.1';
-STDERR->autoflush(1);
-
=head1 METHODS
@@ -127,7 +123,6 @@ sub new {
$ref->{config} = $conf;
$ref->{data} = App::Dthumb::Data->new();
- $ref->{timer} = Time::Progress->new();
$ref->{html} = $ref->{data}->get('html_start');
@@ -140,26 +135,6 @@ sub new {
return bless($ref, $obj);
}
-
-=head2 run
-
-Run dthumb. Read all files, create thumbnails, write index.xhtml, and so on.
-
-=cut
-
-
-sub run {
- my ($self) = @_;
-
- $self->check_cmd_flags();
- $self->read_directories();
- $self->create_files();
- $self->delete_old_thumbnails();
- $self->create_thumbnails();
- $self->write_out_html();
-}
-
-
=head1 INTERNALS
The following methods are internal only and do not need to be called by
@@ -226,11 +201,6 @@ sub read_directories {
@{$self->{files}} = sort { lc($a) cmp lc($b) } @files;
@{$self->{old_thumbnails}} = @old_thumbs;
-
- $self->{timer}->attr(
- min => 1,
- max => scalar @files,
- );
}
@@ -288,28 +258,17 @@ sub delete_old_thumbnails {
}
-=head2 create_thumbnails
+=head2 get_files
-Iterate over all files in $self->{files}, print a progress bar to STDERR and
-call B<create_thumbnail_html> and B<create_thumbnail_image> for each.
+Returns an array of all image files found by B<read_directories>.
=cut
-sub create_thumbnails {
+sub get_files {
my ($self) = @_;
- for my $file (@{$self->{files}}) {
-
- print STDERR $self->{timer}->report(
- "\r\e[KCreating Thumbnails: %p done, %L elapsed, %E remaining",
- ++$self->{current_file_id},
- );
-
- $self->create_thumbnail_html($file);
- $self->create_thumbnail_image($file);
- }
- print "\n";
+ return @{$self->{files}};
}
@@ -404,22 +363,6 @@ sub write_out_html {
close($fh);
}
-#sub print_progress {
-# my ($self) = @_;
-# my $num = $self->{current_file_id};
-# my $name = $self->{current_file_name};
-#
-# if (($num % 60) == 0) {
-# if ($number) {
-# printf(" %4d/%d\n", $number, scalar(@files));
-# }
-# printf('[%3d%%] ', $number * 100 / @files);
-# } elsif (($number % 10) == 0) {
-# print ' ';
-# }
-# return;
-#}
-
1;
__END__