From 2a26a73a91a5debcd879f59ae578d3a637bb82ed Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 26 Dec 2012 21:20:43 +0100 Subject: [PATCH] Gallery2: Subcommands --- gal2/{ => bin}/gal-cache | 3 -- gal2/{ => bin}/gal-dump-config | 2 -- gal2/{ => bin}/gal-dump-meta | 2 -- gal2/{ => bin}/gal-from-gqview | 0 gal2/{ => bin}/gal-gen | 3 -- gal2/bin/gal-mj-digikam | 44 ++++++++++++++++++++++++++++ gal2/bin/gal-mj-init | 20 +++++++++++++ gal2/{ => bin}/gal-scan | 7 ++--- gal2/gal | 53 ++++++++++++++++++++++++++++++++++ 9 files changed, 119 insertions(+), 15 deletions(-) rename gal2/{ => bin}/gal-cache (98%) rename gal2/{ => bin}/gal-dump-config (90%) rename gal2/{ => bin}/gal-dump-meta (89%) rename gal2/{ => bin}/gal-from-gqview (100%) rename gal2/{ => bin}/gal-gen (98%) create mode 100755 gal2/bin/gal-mj-digikam create mode 100755 gal2/bin/gal-mj-init rename gal2/{ => bin}/gal-scan (96%) create mode 100755 gal2/gal diff --git a/gal2/gal-cache b/gal2/bin/gal-cache similarity index 98% rename from gal2/gal-cache rename to gal2/bin/gal-cache index 7d581a6..2039d1b 100755 --- a/gal2/gal-cache +++ b/gal2/bin/gal-cache @@ -5,10 +5,7 @@ use strict; use warnings; -use FindBin; -use lib $FindBin::Bin; use UCW::Gallery; - use Image::Magick; use IO::Handle; use File::Spec; diff --git a/gal2/gal-dump-config b/gal2/bin/gal-dump-config similarity index 90% rename from gal2/gal-dump-config rename to gal2/bin/gal-dump-config index 1432c2e..600a9d5 100755 --- a/gal2/gal-dump-config +++ b/gal2/bin/gal-dump-config @@ -5,8 +5,6 @@ use strict; use warnings; -use FindBin; -use lib $FindBin::Bin; use UCW::Gallery; use Data::Dumper; diff --git a/gal2/gal-dump-meta b/gal2/bin/gal-dump-meta similarity index 89% rename from gal2/gal-dump-meta rename to gal2/bin/gal-dump-meta index 28dbd93..1734183 100755 --- a/gal2/gal-dump-meta +++ b/gal2/bin/gal-dump-meta @@ -5,8 +5,6 @@ use strict; use warnings; -use FindBin; -use lib $FindBin::Bin; use UCW::Gallery; use Data::Dumper; diff --git a/gal2/gal-from-gqview b/gal2/bin/gal-from-gqview similarity index 100% rename from gal2/gal-from-gqview rename to gal2/bin/gal-from-gqview diff --git a/gal2/gal-gen b/gal2/bin/gal-gen similarity index 98% rename from gal2/gal-gen rename to gal2/bin/gal-gen index bc9c8b6..6c767d8 100755 --- a/gal2/gal-gen +++ b/gal2/bin/gal-gen @@ -5,10 +5,7 @@ use strict; use warnings; -use FindBin; -use lib $FindBin::Bin; use UCW::Gallery; - use Image::Magick; use IO::Handle; use File::Spec; diff --git a/gal2/bin/gal-mj-digikam b/gal2/bin/gal-mj-digikam new file mode 100755 index 0000000..134bfc0 --- /dev/null +++ b/gal2/bin/gal-mj-digikam @@ -0,0 +1,44 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Cwd; +use DBI; + +my $photos_root = $ENV{HOME} . '/photos'; + +my $album = $ARGV[0]; +if (!defined $album) { + my $cwd = getcwd; + $cwd =~ m{/photos/(.*)} or die "Cannot identify album from current directory, need to specify maunally.\n"; + $album = $1; +} + +my $dbfile = "$photos_root/digikam4.db"; +my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "") or die "Cannot access $dbfile\n"; + +my %alba = (); +for my $r (@{$dbh->selectall_arrayref( + 'SELECT a.id AS id, r.label AS label, a.relativePath AS rpath FROM Albums a JOIN AlbumRoots r ON (r.id = a.albumRoot)', + { Slice => {} })}) { + my $name = $r->{label} . $r->{rpath}; + # print "$name\n"; + $alba{$name} = $r->{id}; +} + +my $album_id = $alba{$album} // die "Unknown album $album\n"; +print "## Album $album: id=$album_id\n"; + +my ($tag_id) = $dbh->selectrow_array('SELECT id FROM Tags WHERE pid=0 AND name="web"'); +$tag_id // die "Cannot find web tag\n"; +print "## Tag ID: $tag_id\n"; + +open OUT, '|-', $ENV{GALLERY_ROOT} . '/bin/gal-scan' or die "Cannot feed gal scan\n"; +for my $r (@{$dbh->selectall_arrayref( + 'SELECT i.name AS name FROM Images i JOIN ImageTags t ON (i.id = t.imageid) WHERE i.album=? AND t.tagid=? ORDER BY i.name', + { Slice => {} }, + $album_id, $tag_id)}) { + print OUT "$photos_root/$album/" . $r->{name}, "\n"; +} +close OUT; diff --git a/gal2/bin/gal-mj-init b/gal2/bin/gal-mj-init new file mode 100755 index 0000000..1105254 --- /dev/null +++ b/gal2/bin/gal-mj-init @@ -0,0 +1,20 @@ +#!/bin/sh +set -e + +if [ -f gallery.cf ] ; then + echo >&2 'gallery.cf already present, giving up!' + exit 1 +fi + +cat >gallery.cf <<'AMEN' +use strict; +use warnings; +use utf8; + +my $gal = require '../../default.cf'; +$gal->set( + Title => 'Unnamed', +); + +return $gal; +AMEN diff --git a/gal2/gal-scan b/gal2/bin/gal-scan similarity index 96% rename from gal2/gal-scan rename to gal2/bin/gal-scan index 02eb33d..4610980 100755 --- a/gal2/gal-scan +++ b/gal2/bin/gal-scan @@ -5,18 +5,15 @@ use strict; use warnings; -use FindBin; -use lib $FindBin::Bin; use UCW::Gallery; - use File::Spec; use Image::EXIF; use Digest::SHA; if (@ARGV && $ARGV[0] eq '--help') { die < +Usage: cat list | gal scan + or: gal scan AMEN } diff --git a/gal2/gal b/gal2/gal new file mode 100755 index 0000000..d8dd694 --- /dev/null +++ b/gal2/gal @@ -0,0 +1,53 @@ +#!/usr/bin/perl +# UCW Gallery -- Master Program +# (c) 2012 Martin Mares + +use strict; +use warnings; +use Getopt::Long; + +use FindBin; +my $gallery_root = $FindBin::Bin; + +sub show_help() { + print < + +General options: +(none yet) + +Common commands: +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 +AMEN + exit 0; +} + +Getopt::Long::Configure('require_order'); +GetOptions( + "help" => \&show_help, + "version" => sub { + print "UCW Gallery 2.0 (c) 2004-2012 Martin Mares \n"; + }, +) or die "Try `gal help' for more information.\n"; +Getopt::Long::Configure('default'); + +@ARGV or die "Missing subcommand.\n"; +my $sub = shift @ARGV; +$sub =~ /^[0-9a-zA-Z-]+$/ or die "Invalid subcommand $sub\n"; + +if ($sub eq 'help') { show_help(); } + +my $sub_path = "$gallery_root/bin/gal-$sub"; +-x $sub_path or die "Unknown subcommand $sub\n"; + +$ENV{"GALLERY_ROOT"} = $gallery_root; +$ENV{"PERL5LIB"} = join(":", $gallery_root, $ENV{"PERL5LIB"} // ()); +exec $sub_path, @ARGV; +die "Cannot execute $sub_path: $!\n"; -- 2.39.2