This commit is contained in:
ville rantanen
2015-02-11 10:32:33 +02:00
parent bad98cb13a
commit f5c6d59bd4

View File

@@ -55,8 +55,8 @@ def setup_options():
"Append with ',value' to limit similarity. "+ "Append with ',value' to limit similarity. "+
"The output columns: SD SimilarityDiff., CD ColorDiff., "+ "The output columns: SD SimilarityDiff., CD ColorDiff., "+
"RD AspectRatioDiff.,Shp SharpnessIndex. This function does not return exact duplicates.") "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, parser.add_argument("--viewer",type=str,dest="viewer",default=None,
help="Program to view images, %%f refers to filename(s)."+ help="Program to view images, %%f refers to filename(s)."+
"If '1', defaults to: 'geeqie -l %%f'") "If '1', defaults to: 'geeqie -l %%f'")
@@ -66,8 +66,16 @@ def setup_options():
options=parser.parse_args() options=parser.parse_args()
BADDIRS.extend(options.exclude) 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 options.add=not options.add
if options.tag:
options.add=False
return options return options
def createdb(sqlfile): def createdb(sqlfile):
@@ -107,6 +115,10 @@ def delete_data(sqlfile):
for row in db: for row in db:
dbdel.execute("DELETE FROM data where hash == ?",(row[0],)) dbdel.execute("DELETE FROM data where hash == ?",(row[0],))
conn.commit() 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 return
def delete_files(files): def delete_files(files):
@@ -197,6 +209,30 @@ def add_single(conn,filename,change=False,hash=None,minsize=0):
return 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): def random_lists(sqlfile):
conn=sqlite3.connect(sqlfile) conn=sqlite3.connect(sqlfile)
conn.text_factory=str conn.text_factory=str
@@ -855,7 +891,11 @@ def main():
if options.diskused: if options.diskused:
disk_used(options) disk_used(options)
#print(files) #print(files)
if options.tag:
if options.startpath==".":
print_tag(options)
else:
add_tag(options)
sys.exit(0) sys.exit(0)
if __name__ == "__main__": if __name__ == "__main__":