From e697b78e94d85c99ecbd4d99dd4cfeff66059c86 Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Wed, 10 Apr 2013 14:02:30 +0300 Subject: [PATCH] Faster implementation --- image_list.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/image_list.py b/image_list.py index d6ae840..101b2c5 100755 --- a/image_list.py +++ b/image_list.py @@ -93,10 +93,12 @@ def add_recurse(options): if not options.symlinks: files=clean_syms(files) files.sort() + db_files=get_folder_contents(db,os.path.abspath(path)+'/') for file in files: if IMGMATCH.match(file): filename=os.path.abspath(os.path.join(path,file)) - if not is_listed(db,filename): + #if not is_listed(db,filename): + if file not in db_files: if options.add: add_single(conn,filename,change=False,minsize=options.minsize) else: @@ -108,7 +110,7 @@ def add_recurse(options): #file content changed add_single(conn,filename,change=True,minsize=options.minsize) # if file mentioned, and hash same, no need to change entry - + conn.commit() return def add_single(conn,filename,change=False,hash=None,minsize=0): @@ -132,7 +134,6 @@ def add_single(conn,filename,change=False,hash=None,minsize=0): db.execute("INSERT INTO list(file,date,portrait,hash,width,height)\ VALUES(?,?,?,?,?,?)",(filename,ftime,portrait,hash,dims[0],dims[1])) print "adding: %(f)s (%(x)sx%(y)s)" % {'f':filename, 'x':dims[0], 'y':dims[1]} - conn.commit() return def random_lists(sqlfile): @@ -162,6 +163,16 @@ def is_listed(db,filename): count=db.fetchall() return count[0][0]>0 +def get_folder_contents(db,path): + ''' return the contents of the folder ''' + files=[] + db.execute("SELECT file FROM list where file LIKE ?",(path+'%',)) + for row in db: + base=row[0].replace(path,'',1) + if base.find('/')==-1: + files.append(base) + return files + def ftime_match(db,filename,ftime): db.execute("SELECT date FROM list where file == ?",(filename,)) count=db.fetchall()