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 --threads=<n> Run in <n> threads (default=4)
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');
38 "help" => \&show_help,
40 print "UCW Gallery 2.0 (c) 2004-2012 Martin Mares <mj\@ucw.cz>\n";
43 "threads=i" => \$threads,
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, $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`;
74 while ($running || @dirs) {
75 if ($running == $threads || !@dirs) {
77 my $pid = wait; die if $pid < 0;
78 my $dir = $pid_to_dir{$pid} or die;
80 print "!! $dir FAILED [see $dir/gallery.log]";
84 unlink "$dir/gallery.log";
86 delete $pid_to_dir{$pid};
89 print " (done $done/$need)\n";
91 my $dir = shift @dirs;
96 open STDOUT, '>', "$dir/gallery.log" or die;
97 chdir $dir or die "Cannot chdir to $dir: $!\n";
98 exec $sub_path, @ARGV;
99 die "Cannot execute $sub_path: $!\n";
101 $pid_to_dir{$pid} = $dir;
106 print "$done jobs, $errors errors.\n";