diff options
author | zyp <zyp@localhost> | 2006-10-25 18:14:43 +0200 |
---|---|---|
committer | zyp <zyp@localhost> | 2006-10-25 18:14:43 +0200 |
commit | 802668818e930d91c37f8107e4c8822bd3ebdfac (patch) | |
tree | 0806c5e4aff2f69e442b687785ab059fc4130069 /anidb.py | |
parent | 077ce424d11c8344dc4d95bc5b5fa88d67adf643 (diff) |
[project @ zyp-20061025161443-953b0f9ed85da86e]
[project @ 64]
Implemented caching.
Diffstat (limited to 'anidb.py')
-rw-r--r-- | anidb.py | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -1,7 +1,7 @@ #!/usr/bin/env python import pyanidb, pyanidb.hash -import ConfigParser, optparse, os, sys, getpass, multihash +import ConfigParser, optparse, os, sys, getpass # Colors. @@ -34,6 +34,8 @@ op.add_option('-r', '--recursive', help = 'Recurse into directories.', action = 'store_true', dest = 'recursive', default = False) op.add_option('-s', '--suffix', help = 'File suffix for recursive matching.', action = 'append', dest = 'suffix', default = config.get('suffix', '').split()) +op.add_option('-c', '--no-cache', help = 'Do not use cached values.', + action = 'store_false', dest = 'cache', default = int(config.get('cache', '1'))) op.add_option('-i', '--identify', help = 'Identify files.', action = 'store_true', dest = 'identify', default = False) @@ -48,6 +50,12 @@ options, args = op.parse_args(sys.argv[1:]) # Defaults. +if options.cache: + try: + import xattr + except ImportError: + print red('No xattr, caching disabled.') + options.cache = False options.identify = options.identify or options.rename options.login = options.add or options.identify if not options.suffix: @@ -103,10 +111,9 @@ if options.login: hashed = unknown = 0 -for filename, hash in pyanidb.hash.hash_files(files): - size = os.path.getsize(filename) - print blue('Hashed:'), 'ed2k://|file|%s|%d|%s|' % (filename, size, hash.ed2k()) - fid = (size, hash.ed2k()) +for file in pyanidb.hash.hash_files(files, options.cache): + print blue('Hashed:'), 'ed2k://|file|%s|%d|%s|%s' % (file.name, file.size, file.ed2k, ' (cached)' if file.cached else '') + fid = (file.size, file.ed2k) hashed += 1 try: @@ -137,7 +144,7 @@ for filename, hash in pyanidb.hash.hash_files(files): s = s.replace('/', '_') print yellow('Renaming to:'), s - os.rename(filename, os.path.join(os.path.split(filename)[0], s)) + os.rename(file.name, os.path.join(os.path.split(file.name)[0], s)) # Adding. |