www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit b87c081c6025a142a5c41660b81563300967ae87
parent e973dc4adb81a800e70d8c69171c673dbef2bbad
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Sun,  4 Sep 2011 11:19:36 +0200

updatehash.py now takes command-line arguments.

Diffstat:
Mupdatehash.py | 22+++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/updatehash.py b/updatehash.py @@ -4,6 +4,7 @@ import hashlib import os import sqlite3 import time +import sys def checksumFile(path): md5 = hashlib.md5() @@ -21,7 +22,7 @@ def fileInfo(path): return {'mtime':stat.st_mtime, 'size':stat.st_size} def initdb(cursor): - cursor.execute("create table if not exists files(tag,path primary key,md5,sha1,mtime,size)") + cursor.execute("create table if not exists files(tag,timestamp,path primary key,md5,sha1,mtime,size)") cursor.execute("create index if not exists i_files_tag on files(tag)") cursor.execute("create index if not exists i_files_path_md5_sha1 on files(path,md5,sha1)") @@ -31,7 +32,8 @@ def cacheFileInfo(cursor, path): return data and {'mtime':data[0], 'size':data[1]} def update(connection,cursor,path): - currentTime = time.clock() + timestamp = time.clock() + currentTime = timestamp lastTime = currentTime for d in os.walk(path): dirpath=d[0] @@ -43,8 +45,8 @@ def update(connection,cursor,path): if fi != cfi: print " updating", fpath md5,sha1 = checksumFile(fpath) - values = ('no tag',fpath,md5,sha1,fi['mtime'],fi['size']) - cursor.execute("insert or replace into files(tag,path,md5,sha1,mtime,size) values(?,?,?,?,?,?)", values) + values = ('no tag',timestamp,fpath,md5,sha1,fi['mtime'],fi['size']) + cursor.execute("insert or replace into files(tag,timestamp,path,md5,sha1,mtime,size) values(?,?,?,?,?,?,?)", values) currentTime = time.clock() if abs(lastTime-currentTime) >= 0.1: @@ -61,4 +63,14 @@ def walk(db,path): connection.commit() cursor.close() -walk('/tmp/files','/home/js') +def help(): + print 'Usage : %s database-file directory' % sys.argv[0] + sys.exit(1) + +if len(sys.argv) < 3: + help() +for arg in sys.argv[1:]: + if arg == '-h' or arg == '--help': + help() + +walk(sys.argv[1], sys.argv[2])