use FindBin;
my $gallery_root = $FindBin::Bin;
+my $all;
+my $threads = 4;
+
sub show_help() {
print <<AMEN ;
Usage: gal <general-options> <command> <command-options> <args>
General options:
-(none yet)
+--all Run on all galleries in subdirectories
+--threads=<n> Run in <n> threads (default=4)
Common commands:
scan Scan directory and obtain originals
"version" => sub {
print "UCW Gallery 2.0 (c) 2004-2012 Martin Mares <mj\@ucw.cz>\n";
},
+ "all!" => \$all,
+ "threads=i" => \$threads,
) or die "Try `gal help' for more information.\n";
Getopt::Long::Configure('default');
$ENV{"GALLERY_ROOT"} = $gallery_root;
$ENV{"PERL5LIB"} = join(":", $gallery_root, $ENV{"PERL5LIB"} // ());
-exec $sub_path, @ARGV;
-die "Cannot execute $sub_path: $!\n";
+
+if (!$all) {
+ exec $sub_path, @ARGV;
+ die "Cannot execute $sub_path: $!\n";
+}
+
+### Parallel execution ###
+
+my @dirs = sort map { chomp; s{^\./}{}; s{\/gallery.cf}{}; $_; } `find . -mindepth 2 -name gallery.cf`;
+my $done = 0;
+my $need = @dirs;
+
+my $running = 0;
+my $errors = 0;
+my %pid_to_dir = ();
+
+while ($running || @dirs) {
+ if ($running == $threads || !@dirs) {
+ # Wait for children
+ my $pid = wait; die if $pid < 0;
+ if ($?) {
+ print "!! ", $pid_to_dir{$pid}, " FAILED";
+ $errors++;
+ } else {
+ print "++ ", $pid_to_dir{$pid};
+ }
+ delete $pid_to_dir{$pid};
+ $running--;
+ $done++;
+ print " (done $done/$need)\n";
+ } else {
+ my $dir = shift @dirs;
+ print "<< $dir\n";
+ my $pid = fork;
+ if (!$pid) {
+ close STDOUT;
+ open STDOUT, '>', "$dir/gallery.log" or die;
+ chdir $dir or die "Cannot chdir to $dir: $!\n";
+ exec $sub_path, @ARGV;
+ die "Cannot execute $sub_path: $!\n";
+ }
+ $pid_to_dir{$pid} = $dir;
+ $running++;
+ }
+}
+
+print "$done jobs, $errors errors. See gallery.log in subdirectories.\n";
+exit ($errors > 0);