3 # copyright 2012,2013 Arun Persaud <arun@nubati.net>
5 # This file is part of photo-tags.
7 # Photo-tags is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # Photo-tags is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Photo-tags. If not, see <http://www.gnu.org/licenses/>.
21 CONFIG_FILE="config.ini"
23 # copied and modified from http://mark.aufflick.com/blog/2007/11/08/parsing-ini-files-with-sed
24 eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
27 -e 's/[[:space:]]*$//' \
28 -e 's/^[[:space:]]*//' \
29 -e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \
34 dbprefix=${dbprefix//\//\\\/}
40 f-spot-db-reduce.sh <options>
42 The script uses config.ini for most of it's input data.
45 --include=<comma separated taglist> include pictures with these tags
46 --exclude=<comma separated taglist> remove pictures with these tags
47 --hide=<comma separated taglist> remove these tags, but leave pictures
74 # check database version, exit if different from what we expect
75 DBVERSION=`sqlite3 $REMOTEDB 'select data from meta where name="F-Spot Database Version"'`
77 if [ x"$DBVERSION" != "x18" ] ; then
78 echo "The database is from a different F-spot version (database version $DBVERSION) that is not implemented."
79 echo "Check TODO for a newer version or file a bug-report at: TODO"
84 # join tags together in a list of comma seperated quoted strings, so that they can be used in DB queries
85 INCLUDE="'${CL_INCLUDE/,/','}'"
86 EXCLUDE="'${CL_EXCLUDE/,/','}'"
87 HIDE="'${CL_HIDE/,/','}'"
89 if [ "x$INCLUDE" != "x" ] ; then
90 echo "only including pictures with tags: $INCLUDE"
93 if [ "x$EXCLUDE" != "x" ] ; then
94 echo "excluding all pictures with tags: $EXCLUDE"
97 if [ "x$HIDE" != "x" ] ; then
98 echo "removing tags: $HIDE"
101 if [ "x$EXCLUDE" == "x" -a "x$INCLUDE" == "x" ] ; then
102 echo "using all pictures from the database"
105 # test if localdb already exist:
107 # see if photo-db is newer? yes: merge them; no: do nothing
111 cp $REMOTEDB $LOCALDB
114 if [ "x$EXCLUDE" != "x" ] ; then
115 ExcludeTags="insert into rmphotoids select photo_id from photo_tags where tag_id in (select id from tags where name in ($EXCLUDE));"
119 if [ "x$HIDE" != "x" ] ; then
120 HideTags="delete from photo_tags where tag_id in (select id from tags where name in ($HIDE));
121 delete from tags where name in ($HIDE);"
124 # delete all photo related information that we don't want to keep in case INCLUDE tags were given
125 sqlite3 $LOCALDB <<EOF
126 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)));
131 delete from photos where id in (select * from rmphotoids);
132 delete from photo_tags where photo_id in (select * from rmphotoids);
133 delete from photo_versions where photo_id in (select * from rmphotoids);
135 delete from tags where id not in (select distinct tag_id from photo_tags asc);
136 delete from rolls where id not in (select distinct roll_id from photos asc);
138 drop table rmphotoids;