From f5c6d59bd422beeef3a40a7accc4d7fb4ac112f5 Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Wed, 11 Feb 2015 10:32:33 +0200 Subject: [PATCH] tagging --- image_list_beta.py | 50 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/image_list_beta.py b/image_list_beta.py index bd63fc2..80f47c8 100755 --- a/image_list_beta.py +++ b/image_list_beta.py @@ -55,8 +55,8 @@ def setup_options(): "Append with ',value' to limit similarity. "+ "The output columns: SD SimilarityDiff., CD ColorDiff., "+ "RD AspectRatioDiff.,Shp SharpnessIndex. This function does not return exact duplicates.") -## -t string add tag to [file] - + parser.add_argument("-t",type=str,dest="tag",default=None, + help="Give file a tag. If argument is a file name, print the tags of the file.") parser.add_argument("--viewer",type=str,dest="viewer",default=None, help="Program to view images, %%f refers to filename(s)."+ "If '1', defaults to: 'geeqie -l %%f'") @@ -66,8 +66,16 @@ def setup_options(): options=parser.parse_args() BADDIRS.extend(options.exclude) - if options.duplicate or options.searchsmall or options.measure or options.nearestcolor or options.similarity!=None or options.search or options.diskused: + if options.duplicate or \ + options.searchsmall or \ + options.measure or \ + options.nearestcolor or \ + options.similarity!=None or \ + options.search or \ + options.diskused: options.add=not options.add + if options.tag: + options.add=False return options def createdb(sqlfile): @@ -105,7 +113,11 @@ def delete_data(sqlfile): dbdel=conn.cursor() db.execute('''SELECT hash FROM data EXCEPT SELECT hash FROM list''') for row in db: - dbdel.execute("DELETE FROM data where hash == ?",(row[0],)) + dbdel.execute("DELETE FROM data where hash == ?",(row[0],)) + conn.commit() + db.execute('''SELECT hash FROM tags EXCEPT SELECT hash FROM list''') + for row in db: + dbdel.execute("DELETE FROM tags where hash == ?",(row[0],)) conn.commit() return @@ -197,6 +209,30 @@ def add_single(conn,filename,change=False,hash=None,minsize=0): return +def add_tag(options): + conn=sqlite3.connect(options.sqlfile) + conn.text_factory=str + hash=file2hash(conn.cursor(), os.path.realpath(options.startpath)) + if hash==None: + print("Image not found "+os.path.realpath(options.startpath)) + return + db=conn.cursor() + db.execute("INSERT INTO tags(hash,tag) \ + VALUES(?,?)",(hash,options.tag)) + conn.commit() + print(options.startpath+":\""+options.tag+"\"") + +def print_tag(options): + conn=sqlite3.connect(options.sqlfile) + conn.text_factory=str + hash=file2hash(conn.cursor(), os.path.realpath(options.tag)) + if hash==None: + print("Image not found "+os.path.realpath(options.tag)) + return + db=conn.cursor() + db.execute("SELECT DISTINCT tag FROM tags WHERE hash = ?",(hash,)) + print( ",".join( row[0] for row in db )) + def random_lists(sqlfile): conn=sqlite3.connect(sqlfile) conn.text_factory=str @@ -855,7 +891,11 @@ def main(): if options.diskused: disk_used(options) #print(files) - + if options.tag: + if options.startpath==".": + print_tag(options) + else: + add_tag(options) sys.exit(0) if __name__ == "__main__":