2 # UCW Gallery -- Master Program
3 # (c) 2012 Martin Mares <mj@ucw.cz>
10 my $gallery_root = $FindBin::Bin;
17 Usage: gal <general-options> <command> <command-options> <args>
20 --all Run on all galleries in subdirectories
21 -p, --parallel=<n> Run in parallel and use <n> processes
24 scan Scan directory and obtain originals
25 gen Generate web photos from originals
26 cache Rebuild thumbnails and other cached info
29 dump-config Show configuration settings
30 dump-meta Show contents of metadata files
31 from-gqview Parse gqview/geeqie collections
36 Getopt::Long::Configure('require_order', 'bundling');
38 "help" => \&show_help,
40 print "UCW Gallery 2.0 (c) 2004-2012 Martin Mares <mj\@ucw.cz>\n";
43 "p|parallel=i" => \$parallel,
44 ) or die "Try `gal help' for more information.\n";
45 Getopt::Long::Configure('default');
47 @ARGV or die "Missing subcommand.\n";
48 my $sub = shift @ARGV;
49 $sub =~ /^[0-9a-zA-Z-]+$/ or die "Invalid subcommand $sub\n";
51 if ($sub eq 'help') { show_help(); }
53 my $sub_path = "$gallery_root/bin/gal-$sub";
54 -x $sub_path or die "Unknown subcommand $sub\n";
56 $ENV{"GALLERY_ROOT"} = $gallery_root;
57 $ENV{"PERL5LIB"} = join(":", $gallery_root . "/lib", $ENV{"PERL5LIB"} // ());
60 exec $sub_path, @ARGV;
61 die "Cannot execute $sub_path: $!\n";
64 ### Parallel execution ###
66 my @dirs = sort map { chomp; s{^\./}{}; s{\/gallery.cf}{}; $_; } `find . -mindepth 2 -name gallery.cf`;
69 my $logging = $parallel ? 1 : 0;
70 my $threads = $parallel // 1;
76 while ($running || @dirs) {
77 if ($running == $threads || !@dirs) {
79 my $pid = wait; die if $pid < 0;
80 my $dir = $pid_to_dir{$pid} or die;
82 print "!! $dir FAILED";
83 print " [see $dir/gallery.log]" if $logging;
87 unlink "$dir/gallery.log" if $logging;
89 delete $pid_to_dir{$pid};
92 print " (done $done/$need)\n";
94 my $dir = shift @dirs;
100 open STDOUT, '>', "$dir/gallery.log" or die;
102 open STDERR, '>&STDOUT';
104 chdir $dir or die "Cannot chdir to $dir: $!\n";
105 exec $sub_path, @ARGV;
106 die "Cannot execute $sub_path: $!\n";
108 $pid_to_dir{$pid} = $dir;
113 print "$done jobs, $errors errors.\n";