#!/bin/bash
-# parse ini file
+# copyright 2012,2013 Arun Persaud <arun@nubati.net>
+#
+# This file is part of photo-tags.
+#
+# Photo-tags is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Photo-tags is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Photo-tags. If not, see <http://www.gnu.org/licenses/>.
+
+# parse ini file
CONFIG_FILE="config.ini"
# copied and modified from http://mark.aufflick.com/blog/2007/11/08/parsing-ini-files-with-sed
function usage () {
- echo "TODO: use comma seperate tags for --include=... and/or --exclude=..."
+ echo <<EOF
+f-spot-db-reduce.sh <options>
+
+The script uses config.ini for most of it's input data.
+
+Options:
+ --include=<comma separated taglist> include pictures with these tags
+ --exclude=<comma separated taglist> remove pictures with these tags
+ --hide=<comma separated taglist> remove these tags, but leave pictures
+EOF
+
}
# parse command line
CL_INCLUDE=""
CL_EXCLUDE=""
+CL_HIDE=""
for i in "$@"; do
- case $i in
+ case $i in
--include=*)
- CL_INCLUDE=${i#*=}
+ CL_INCLUDE=${i#*=}
;;
--exclude=*)
- CL_EXCLUDE=${i#*=}
+ CL_EXCLUDE=${i#*=}
+ ;;
+ --hide=*)
+ CL_HIDE=${i#*=}
;;
-h|--help)
usage
# join tags together in a list of comma seperated quoted strings, so that they can be used in DB queries
INCLUDE="'${CL_INCLUDE/,/','}'"
EXCLUDE="'${CL_EXCLUDE/,/','}'"
+HIDE="'${CL_HIDE/,/','}'"
if [ "x$INCLUDE" != "x" ] ; then
echo "only including pictures with tags: $INCLUDE"
echo "excluding all pictures with tags: $EXCLUDE"
fi
+if [ "x$HIDE" != "x" ] ; then
+ echo "removing tags: $HIDE"
+fi
+
if [ "x$EXCLUDE" == "x" -a "x$INCLUDE" == "x" ] ; then
echo "using all pictures from the database"
fi
# test if localdb already exist:
# yes:
# see if photo-db is newer? yes: merge them; no: do nothing
-# no:
+# no:
# create it
cp $REMOTEDB $LOCALDB
ExcludeTags="insert into rmphotoids select photo_id from photo_tags where tag_id in (select id from tags where name in ($EXCLUDE));"
fi
+HideTags=""
+if [ "x$HIDE" != "x" ] ; then
+ HideTags="delete from photo_tags where tag_id in (select id from tags where name in ($HIDE));
+ delete from tags where name in ($HIDE);"
+fi
+
# delete all photo related information that we don't want to keep in case INCLUDE tags were given
sqlite3 $LOCALDB <<EOF
create temp table rmphotoids as select id from photos where id not in (select photo_id from photo_tags where tag_id in (select id from tags where name in ($INCLUDE)));
$ExcludeTags
+$HideTags
delete from photos where id in (select * from rmphotoids);
delete from photo_tags where photo_id in (select * from rmphotoids);
delete from rolls where id not in (select distinct roll_id from photos asc);
drop table rmphotoids;
-drop table jobs;
+drop table jobs;
drop table exports;
vacuum;