tagging
This commit is contained in:
@@ -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):
|
||||
@@ -107,6 +115,10 @@ def delete_data(sqlfile):
|
||||
for row in db:
|
||||
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
|
||||
|
||||
def delete_files(files):
|
||||
@@ -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__":
|
||||
|
||||
Reference in New Issue
Block a user