From cf40dbdb820d1248c0e11c67a15b3cb88851becf Mon Sep 17 00:00:00 2001 From: zyp Date: Tue, 16 May 2006 23:29:44 +0000 Subject: [project @ zyp-20060516232944-3de034366a874a83] [project @ 35] Renamed pyanidb.py to anidb.py to resolve name-conflict. --- anidb.py | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pyanidb.py | 103 ------------------------------------------------------------- setup.py | 2 +- 3 files changed, 104 insertions(+), 104 deletions(-) create mode 100644 anidb.py delete mode 100644 pyanidb.py diff --git a/anidb.py b/anidb.py new file mode 100644 index 0000000..62258c9 --- /dev/null +++ b/anidb.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python + +import pyanidb, pyanidb.hash +import ConfigParser, optparse, os, sys, getpass, multihash + +# Config. + +config = {} +try: + cp = ConfigParser.ConfigParser() + cp.read(os.path.expanduser('~/.pyanidb.conf')) + for option in cp.options('pyanidb'): + config[option] = cp.get('pyanidb', option) +except: + pass + +# Options. + +op = optparse.OptionParser() + +op.add_option('-u', '--username', help = 'AniDB username.', + action = 'store', dest = 'username', default = config.get('username')) +op.add_option('-p', '--password', help = 'AniDB password.', + action = 'store', dest = 'password', default = config.get('password')) + +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['suffix'].split()) + +op.add_option('-a', '--add', help = 'Add files to mylist.', + action = 'store_true', dest = 'add', default = False) + +options, args = op.parse_args(sys.argv[1:]) + +# Defaults. + +options.login = options.add + +# Authorization. + +if options.login: + if not options.username: + options.username = raw_input('Username: ') + if not options.password: + options.passord = getpass.getpass() + a = pyanidb.AniDB(options.username, options.password) + try: + a.auth() + print 'Logged in as user %s.' % (options.username) + if a.new_version: + print 'New version available.' + except pyanidb.AniDBUserError: + print 'Invalid username/password.' + sys.exit(1) + except pyanidb.AniDBTimeout: + print 'Connection timed out.' + sys.exit(1) + except pyanidb.AniDBError, e: + print 'Fatal error:', e + sys.exit(1) + +# Input files. + +files = [] +for name in args: + if not os.access(name, os.R_OK): + print 'Invalid file: %s' % (name) + elif os.path.isfile(name): + files.append(name) + elif os.path.isdir(name): + if not options.recursive: + print 'Is a directory: %s' % (name) + else: + for root, subdirs, subfiles in os.walk(name): + subdirs.sort() + subfiles.sort() + files += [os.path.join(root, file) for file in subfiles if sum([file.endswith('.' + suffix) for suffix in options.suffix])] + +# Hashing. + +for filename, hash in pyanidb.hash.hash_files(files): + size = os.path.getsize(filename) + print 'Hashed: ed2k://|file|%s|%d|%s|' % (filename, size, hash.ed2k()) + + # Adding + + if options.add: + try: + while 1: + try: + a.add_hash(size, hash.ed2k()) + except pyanidb.AniDBTimeout: + print 'Connection timed out, retrying.' + continue + break + print 'Added file: %s' % (filename) + except pyanidb.AniDBUnknownFile: + print 'Unknown file: %s' % (filename) + +# Finished. + +print 'All operations finished.' diff --git a/pyanidb.py b/pyanidb.py deleted file mode 100644 index 62258c9..0000000 --- a/pyanidb.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env python - -import pyanidb, pyanidb.hash -import ConfigParser, optparse, os, sys, getpass, multihash - -# Config. - -config = {} -try: - cp = ConfigParser.ConfigParser() - cp.read(os.path.expanduser('~/.pyanidb.conf')) - for option in cp.options('pyanidb'): - config[option] = cp.get('pyanidb', option) -except: - pass - -# Options. - -op = optparse.OptionParser() - -op.add_option('-u', '--username', help = 'AniDB username.', - action = 'store', dest = 'username', default = config.get('username')) -op.add_option('-p', '--password', help = 'AniDB password.', - action = 'store', dest = 'password', default = config.get('password')) - -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['suffix'].split()) - -op.add_option('-a', '--add', help = 'Add files to mylist.', - action = 'store_true', dest = 'add', default = False) - -options, args = op.parse_args(sys.argv[1:]) - -# Defaults. - -options.login = options.add - -# Authorization. - -if options.login: - if not options.username: - options.username = raw_input('Username: ') - if not options.password: - options.passord = getpass.getpass() - a = pyanidb.AniDB(options.username, options.password) - try: - a.auth() - print 'Logged in as user %s.' % (options.username) - if a.new_version: - print 'New version available.' - except pyanidb.AniDBUserError: - print 'Invalid username/password.' - sys.exit(1) - except pyanidb.AniDBTimeout: - print 'Connection timed out.' - sys.exit(1) - except pyanidb.AniDBError, e: - print 'Fatal error:', e - sys.exit(1) - -# Input files. - -files = [] -for name in args: - if not os.access(name, os.R_OK): - print 'Invalid file: %s' % (name) - elif os.path.isfile(name): - files.append(name) - elif os.path.isdir(name): - if not options.recursive: - print 'Is a directory: %s' % (name) - else: - for root, subdirs, subfiles in os.walk(name): - subdirs.sort() - subfiles.sort() - files += [os.path.join(root, file) for file in subfiles if sum([file.endswith('.' + suffix) for suffix in options.suffix])] - -# Hashing. - -for filename, hash in pyanidb.hash.hash_files(files): - size = os.path.getsize(filename) - print 'Hashed: ed2k://|file|%s|%d|%s|' % (filename, size, hash.ed2k()) - - # Adding - - if options.add: - try: - while 1: - try: - a.add_hash(size, hash.ed2k()) - except pyanidb.AniDBTimeout: - print 'Connection timed out, retrying.' - continue - break - print 'Added file: %s' % (filename) - except pyanidb.AniDBUnknownFile: - print 'Unknown file: %s' % (filename) - -# Finished. - -print 'All operations finished.' diff --git a/setup.py b/setup.py index 0ead3b1..52a4259 100755 --- a/setup.py +++ b/setup.py @@ -6,4 +6,4 @@ from distutils.core import setup, Extension setup( name='pyanidb', packages = ['pyanidb'], - scripts = ['pyanidb.py']) + scripts = ['anidb.py']) -- cgit v1.2.3