2 # UCW Gallery -- Master Program
3 # (c) 2012 Martin Mares <mj@ucw.cz>
9 my $gallery_root = $FindBin::Bin;
16 Usage: gal <general-options> <command> <command-options> <args>
19 --all Run on all galleries in subdirectories
20 -p, --parallel=<n> Run in parallel and use <n> processes
23 scan Scan directory and obtain originals
24 gen Generate web photos from originals
25 cache Rebuild thumbnails and other cached info
28 dump-config Show configuration settings
29 dump-meta Show contents of metadata files
30 from-gqview Parse gqview/geeqie collections
35 Getopt::Long::Configure('require_order', 'bundling');
37 "help" => \&show_help,
39 print "UCW Gallery 2.0 (c) 2004-2012 Martin Mares <mj\@ucw.cz>\n";
42 "p|parallel=i" => \$parallel,
43 ) or die "Try `gal help' for more information.\n";
44 Getopt::Long::Configure('default');
46 @ARGV or die "Missing subcommand.\n";
47 my $sub = shift @ARGV;
48 $sub =~ /^[0-9a-zA-Z-]+$/ or die "Invalid subcommand $sub\n";
50 if ($sub eq 'help') { show_help(); }
52 my $sub_path = "$gallery_root/bin/gal-$sub";
53 -x $sub_path or die "Unknown subcommand $sub\n";
55 $ENV{"GALLERY_ROOT"} = $gallery_root;
56 $ENV{"PERL5LIB"} = join(":", $gallery_root . "/lib", $ENV{"PERL5LIB"} // ());
59 exec $sub_path, @ARGV;
60 die "Cannot execute $sub_path: $!\n";
63 ### Parallel execution ###
65 my @dirs = sort map { chomp; s{^\./}{}; s{\/gallery.cf}{}; $_; } `find . -mindepth 2 -name gallery.cf`;
68 my $logging = $parallel ? 1 : 0;
69 my $threads = $parallel // 1;
75 while ($running || @dirs) {
76 if ($running == $threads || !@dirs) {
78 my $pid = wait; die if $pid < 0;
79 my $dir = $pid_to_dir{$pid} or die;
81 print "!! $dir FAILED";
82 print " [see $dir/gallery.log]" if $logging;
86 unlink "$dir/gallery.log" if $logging;
88 delete $pid_to_dir{$pid};
91 print " (done $done/$need)\n";
93 my $dir = shift @dirs;
99 open STDOUT, '>', "$dir/gallery.log" or die;
101 open STDERR, '>&STDOUT';
103 chdir $dir or die "Cannot chdir to $dir: $!\n";
104 exec $sub_path, @ARGV;
105 die "Cannot execute $sub_path: $!\n";
107 $pid_to_dir{$pid} = $dir;
112 print "$done jobs, $errors errors.\n";