diff options
author | Jeffrey C. Ollie <jeff@ocjtech.us> | 2008-08-19 22:46:54 -0500 |
---|---|---|
committer | Jeffrey C. Ollie <jeff@ocjtech.us> | 2008-08-19 22:46:54 -0500 |
commit | 397a78b63a6a6a39feb80507fdac00508e83db15 (patch) | |
tree | 2e3923c8cc17f19e8c5a1d6298a424b79f492f33 | |
parent | 288a20d39dba44f995c8167c48b7b8160621af70 (diff) | |
download | nohgooee-397a78b63a6a6a39feb80507fdac00508e83db15.tar.gz nohgooee-397a78b63a6a6a39feb80507fdac00508e83db15.tar.xz nohgooee-397a78b63a6a6a39feb80507fdac00508e83db15.zip |
Use twisted functions for logging.
-rw-r--r-- | NohGooee/parsedir.py | 35 | ||||
-rw-r--r-- | NohGooee/track.py | 6 |
2 files changed, 16 insertions, 25 deletions
diff --git a/NohGooee/parsedir.py b/NohGooee/parsedir.py index 2ffe1c2..1a5054b 100644 --- a/NohGooee/parsedir.py +++ b/NohGooee/parsedir.py @@ -13,25 +13,25 @@ import os from sha import sha +from twisted.python import log + from NohGooee.bencode import bencode, bdecode from NohGooee.btformats import check_message -NOISY = False - -def parsedir(directory, parsed, files, blocked, errfunc, +def parsedir(directory, parsed, files, blocked, include_metainfo=True): - if NOISY: - errfunc('checking dir') + log.msg('scanning directories for torrents') dirs_to_check = [directory] new_files = {} new_blocked = {} while dirs_to_check: # first, recurse directories and gather torrents directory = dirs_to_check.pop() + log.msg('checking directory %s' % directory) newtorrents = False try: dir_contents = os.listdir(directory) except (IOError, OSError), e: - errfunc(_("Could not read directory ") + directory) + log.err(_("Could not read directory ") + directory) continue for f in dir_contents: if f.endswith('.torrent'): @@ -40,7 +40,7 @@ def parsedir(directory, parsed, files, blocked, errfunc, try: new_files[p] = [(os.path.getmtime(p),os.path.getsize(p)),0] except (IOError, OSError), e: - errfunc(_("Could not stat ") + p + " : " + str(e)) + log.err(_("Could not stat ") + p + " : " + str(e)) if not newtorrents: for f in dir_contents: p = os.path.join(directory, f) @@ -70,8 +70,7 @@ def parsedir(directory, parsed, files, blocked, errfunc, new_blocked[p] = None # same broken unparseable file continue if p not in blocked and h in parsed: # modified; remove+add - if NOISY: - errfunc(_("removing %s (will re-add)") % p) + log.err(_("removing %s (will re-add)") % p) removed[h] = parsed[h] to_add.append(p) @@ -81,13 +80,12 @@ def parsedir(directory, parsed, files, blocked, errfunc, v = new_file[0] if new_file[1] in new_parsed: # duplicate if p not in blocked or files[p][0] != v: - errfunc(_("**warning** %s is a duplicate torrent for %s") % + log.msg(_("**warning** %s is a duplicate torrent for %s") % (p, new_parsed[new_file[1]]['path'])) new_blocked[p] = None continue - if NOISY: - errfunc('adding '+p) + log.msg('adding '+p) try: ff = open(p, 'rb') d = bdecode(ff.read()) @@ -95,7 +93,7 @@ def parsedir(directory, parsed, files, blocked, errfunc, h = sha(bencode(d['info'])).digest() new_file[1] = h if new_parsed.has_key(h): - errfunc(_("**warning** %s is a duplicate torrent for %s") % + log.msg(_("**warning** %s is a duplicate torrent for %s") % (p, new_parsed[h]['path'])) new_blocked[p] = None continue @@ -127,24 +125,21 @@ def parsedir(directory, parsed, files, blocked, errfunc, if include_metainfo: a['metainfo'] = d except: - errfunc(_("**warning** %s has errors") % p) + log.msg(_("**warning** %s has errors") % p) new_blocked[p] = None continue try: ff.close() except: pass - if NOISY: - errfunc(_("... successful")) + log.msg(_("... successful")) new_parsed[h] = a added[h] = a for p,v in files.iteritems(): # and finally, mark removed torrents if p not in new_files and p not in blocked: - if NOISY: - errfunc(_("removing %s") % p) + log.msg(_("removing %s") % p) removed[v[1]] = parsed[v[1]] - if NOISY: - errfunc(_("done checking")) + log.msg(_("done checking")) return (new_parsed, new_files, new_blocked, added, removed) diff --git a/NohGooee/track.py b/NohGooee/track.py index ee1fe5e..a8c1fa7 100644 --- a/NohGooee/track.py +++ b/NohGooee/track.py @@ -555,12 +555,8 @@ class Tracker(object): log.msg('parse_allowed') reactor.callLater(self.parse_dir_interval, self.parse_allowed) - # logging broken .torrent files would be useful but could confuse - # programs parsing log files, so errors are just ignored for now - def ignore(message): - pass r = parsedir(self.allowed_dir, self.allowed, self.allowed_dir_files, - self.allowed_dir_blocked, ignore,include_metainfo = False) + self.allowed_dir_blocked, include_metainfo = False) ( self.allowed, self.allowed_dir_files, self.allowed_dir_blocked, added, garbage2 ) = r |