]> mj.ucw.cz Git - gallery.git/commitdiff
Gallery2: The driver script supports sequential mode, which shows full output
authorMartin Mares <mj@ucw.cz>
Mon, 31 Dec 2012 20:19:23 +0000 (21:19 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 8 Feb 2015 20:14:17 +0000 (21:14 +0100)
gal/gal

diff --git a/gal/gal b/gal/gal
index f66c682ee8722dc654474d6be3044b195e425f08..f16a5f746fb7c5bfe2a24468740c4383f57f4b49 100755 (executable)
--- 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 <<AMEN ;
 Usage: gal <general-options> <command> <command-options> <args>
 
 General options:
---all          Run on all galleries in subdirectories
---threads=<n>  Run in <n> threads (default=4)
+    --all              Run on all galleries in subdirectories
+-p, --parallel=<n>     Run in parallel and use <n> 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 <mj\@ucw.cz>\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";