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');
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;
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--;
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";