Small adjustments in scripts, updatehash.py can now update a subdirectory.

This commit is contained in:
Georges Dupéron 2012-05-11 12:34:00 +02:00
parent 56c735c248
commit 127d32936f
2 changed files with 11 additions and 5 deletions

View File

@ -7,16 +7,17 @@ def walk(path):
#print >> sys.stderr, path #print >> sys.stderr, path
for f in os.listdir(path): for f in os.listdir(path):
fpath = os.path.join(path, f) fpath = os.path.join(path, f)
if os.path.isdir(fpath) and not os.path.islink(fpath):
walk(fpath)
if f[0:2] == ".%": if f[0:2] == ".%":
ff = f ff = f
while ff[0:2] == ".%": while ff[0:2] == ".%":
ff = ff[2:] ff = ff[2:]
dest = os.path.join(path, ff) dest = os.path.join(path, ff)
if not os.path.exists(dest): if not os.path.exists(dest):
print "i-have-moved -i '%s' '%s'" % (fpath.replace("'", "'\\''"), dest.replace("'", "'\\''")) print "i-have-moved -i -- '%s' '%s'" % (fpath.replace("'", "'\\''"), dest.replace("'", "'\\''"))
os.rename(fpath, dest) os.rename(fpath, dest)
if os.path.isdir(fpath) and not os.path.islink(fpath):
walk(fpath)
def help(): def help():
print 'Usage : %s directory' % sys.argv[0] print 'Usage : %s directory' % sys.argv[0]
sys.exit(1) sys.exit(1)

View File

@ -66,8 +66,13 @@ def update(connection,cursor,path):
connection.commit() connection.commit()
print "commit!" print "commit!"
print "cleaning up..." print "cleaning up..."
cursor.execute("insert into removedfiles(rmtimestamp,tag,timestamp,path,md5,sha1,mtime,size) select ?,tag,timestamp,path,md5,sha1,mtime,size from files where path not in newfiles", (timestamp,)) cursor.execute("create temp table deletedfiles(path)")
cursor.execute("delete from files where path not in (select path from newfiles)") cursor.execute("create index i_deletedfiles_path on deletedfiles(path)")
likepath=('' + path).replace('%', '%%') + '%';
cursor.execute("insert into deletedfiles(path) select path from files where path like ?", (likepath,));
cursor.execute("delete from deletedfiles where path in newfiles");
cursor.execute("insert into removedfiles(rmtimestamp,tag,timestamp,path,md5,sha1,mtime,size) select ?,tag,timestamp,path,md5,sha1,mtime,size from files where path in deletedfiles", (timestamp,))
cursor.execute("delete from files where path in deletedfiles")
connection.commit() connection.commit()
def walk(db,path): def walk(db,path):