From: Martin Mares Date: Mon, 31 Dec 2012 20:19:23 +0000 (+0100) Subject: Gallery2: The driver script supports sequential mode, which shows full output X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=b5e3875897d7a7a18fb09e863794ef151a758c97;p=gallery.git Gallery2: The driver script supports sequential mode, which shows full output --- diff --git a/gal/gal b/gal/gal index f66c682..f16a5f7 100755 --- a/gal/gal +++ b/gal/gal @@ -10,37 +10,37 @@ use FindBin; my $gallery_root = $FindBin::Bin; my $all; -my $threads = 4; +my $parallel; sub show_help() { print < General options: ---all Run on all galleries in subdirectories ---threads= Run in threads (default=4) + --all Run on all galleries in subdirectories +-p, --parallel= Run in parallel and use processes Common commands: -scan Scan directory and obtain originals -gen Generate web photos from originals -cache Rebuild thumbnails and other cached info +scan Scan directory and obtain originals +gen Generate web photos from originals +cache Rebuild thumbnails and other cached info Other commands: -dump-config Show configuration settings -dump-meta Show contents of metadata files -from-gqview Parse gqview/geeqie collections +dump-config Show configuration settings +dump-meta Show contents of metadata files +from-gqview Parse gqview/geeqie collections AMEN exit 0; } -Getopt::Long::Configure('require_order'); +Getopt::Long::Configure('require_order', 'bundling'); GetOptions( "help" => \&show_help, "version" => sub { print "UCW Gallery 2.0 (c) 2004-2012 Martin Mares \n"; }, "all!" => \$all, - "threads=i" => \$threads, + "p|parallel=i" => \$parallel, ) or die "Try `gal help' for more information.\n"; Getopt::Long::Configure('default'); @@ -66,6 +66,8 @@ if (!$all) { my @dirs = sort map { chomp; s{^\./}{}; s{\/gallery.cf}{}; $_; } `find . -mindepth 2 -name gallery.cf`; my $done = 0; my $need = @dirs; +my $logging = $parallel ? 1 : 0; +my $threads = $parallel // 1; my $running = 0; my $errors = 0; @@ -77,11 +79,12 @@ while ($running || @dirs) { my $pid = wait; die if $pid < 0; my $dir = $pid_to_dir{$pid} or die; if ($?) { - print "!! $dir FAILED [see $dir/gallery.log]"; + print "!! $dir FAILED"; + print " [see $dir/gallery.log]" if $logging; $errors++; } else { print "++ $dir"; - unlink "$dir/gallery.log"; + unlink "$dir/gallery.log" if $logging; } delete $pid_to_dir{$pid}; $running--; @@ -92,8 +95,12 @@ while ($running || @dirs) { print "<< $dir\n"; my $pid = fork; if (!$pid) { - close STDOUT; - open STDOUT, '>', "$dir/gallery.log" or die; + if ($logging) { + close STDOUT; + open STDOUT, '>', "$dir/gallery.log" or die; + close STDERR; + open STDERR, '>&STDOUT'; + } chdir $dir or die "Cannot chdir to $dir: $!\n"; exec $sub_path, @ARGV; die "Cannot execute $sub_path: $!\n";