add data after filenames

This commit is contained in:
q
2015-02-18 20:19:58 +02:00
parent fd74c93a71
commit 895bb17b12

View File

@@ -42,7 +42,7 @@ def setup_options():
parser.add_argument("-l",action="store_true",dest="symlinks",default=False,
help="Follow symbolic links [%(default)s]")
parser.add_argument("-m",type=int,dest="minsize",default=MINSIZE,
help="Minimum pixel width/height of stored image [%(default)s]")
help="Minimum pixel width/height of stored image for --small search [%(default)s]")
parser.add_argument("-r",action="store_true",dest="random",default=False,
help="Create randomized files for landscape and portrait images [%(default)s]")
parser.add_argument("-s",type=str,dest="search",default=False,
@@ -174,7 +174,7 @@ def add_recurse(options):
if file not in db_files:
if options.add:
try:
add_single(conn,filename,change=False,minsize=options.minsize)
add_single(conn,filename,change=False)
except:
print('error adding file: '+filename)
traceback.print_exc(file=sys.stdout)
@@ -187,24 +187,17 @@ def add_recurse(options):
if not ftime_match(db,filename,ftime):
#file content changed
try:
add_single(conn,filename,change=True,minsize=options.minsize)
add_single(conn,filename,change=True)
except:
print('error changing file: '+filename)
traceback.print_exc(file=sys.stdout)
sys.exit(1)
# if file mentioned, and hash same, no need to change entry
conn.commit()
append_data(conn)
return
def add_single(conn,filename,change=False,hash=None,minsize=0):
dims=get_dims(filename)
if int(dims[0])<int(dims[1]):
portrait=1
else:
portrait=0
if (int(dims[0])<minsize) & (int(dims[1])<minsize):
print(filename+" too small (%s)" % dims)
return
db=conn.cursor()
if hash==None:
hash=get_md5(filename)
@@ -213,20 +206,34 @@ def add_single(conn,filename,change=False,hash=None,minsize=0):
if change:
db.execute("UPDATE list SET hash=?, date=? ,size=? \
WHERE file=?",(hash,ftime,fsize,filename))
print("changing: %(f)s (%(x)sx%(y)s)" % {'f':filename, 'x':dims[0], 'y':dims[1]})
print("changing: %(f)s (%(x)s)" % {'f':filename, 'x':humanize_size(fsize)})
else:
db.execute("INSERT INTO list(file,hash,size,date)\
VALUES(?,?,?,?)",(filename,hash,fsize,ftime))
print("adding: %(f)s (%(x)sx%(y)s)" % {'f':filename, 'x':dims[0], 'y':dims[1]})
print("adding: %(f)s (%(x)s)" % {'f':filename, 'x':humanize_size(fsize)})
return
if hash_in_data(conn.cursor(),hash):
if change:
db.execute("UPDATE data SET portrait=?, width=? ,height=?, \
fingerprint=NULL, sharpness=NULL, R=NULL, G=NULL, B=NULL, BR=NULL, BG=NULL, BB=NULL \
WHERE hash = ?",(portrait,dims[0],dims[1],hash))
def append_data(conn):
db=conn.cursor()
dbh=conn.cursor()
count=db.execute('''SELECT count(hash) FROM list EXCEPT SELECT hash FROM data''').fetchall()[0][0]
db.execute('''SELECT hash FROM list EXCEPT SELECT hash FROM data''')
dirname_old=""
for i,row in enumerate(db):
filename=hash2file(conn.cursor(),row[0])
if filename==None:
continue
dims=get_dims(filename)
if int(dims[0])<int(dims[1]):
portrait=1
else:
db.execute("INSERT INTO data(hash,portrait,width,height) \
VALUES(?,?,?,?)",(hash,portrait,dims[0],dims[1]))
portrait=0
dbh.execute("INSERT OR REPLACE INTO data(hash,portrait,width,height) \
VALUES(?,?,?,?)",(row[0],portrait,dims[0],dims[1]))
print("%(nr)i %(f)s" % {'f':filename, 'nr':count-i})
if (i%50==0):
conn.commit()
conn.commit()
return
def add_tag(options):