diff options
| author | toshio | 2012-03-13 05:50:53 +0000 |
|---|---|---|
| committer | toshio | 2012-03-13 05:50:53 +0000 |
| commit | f4f5226e97e53826ebbe8794e2e7b770e53db5f2 (patch) | |
| tree | 8149d8e5498872597489c946f2142fe3b0a19f55 | |
| parent | cd158259c6cb95abce61341ff41fdb2767328bcd (diff) | |
| download | mailman-f4f5226e97e53826ebbe8794e2e7b770e53db5f2.tar.gz mailman-f4f5226e97e53826ebbe8794e2e7b770e53db5f2.tar.zst mailman-f4f5226e97e53826ebbe8794e2e7b770e53db5f2.zip | |
Style cleanups for the prototype patch
| -rw-r--r-- | src/mailman/archiving/prototype.py | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/mailman/archiving/prototype.py b/src/mailman/archiving/prototype.py index b26dc9768..b3490009a 100644 --- a/src/mailman/archiving/prototype.py +++ b/src/mailman/archiving/prototype.py @@ -25,18 +25,18 @@ __all__ = [ ] +import os +import errno import hashlib +import logging from base64 import b32encode from datetime import timedelta -import errno -import logging from mailbox import Maildir -import os from urlparse import urljoin -from zope.interface import implements from flufl.lock import Lock, TimeOutError +from zope.interface import implements from mailman.config import config from mailman.interfaces.archiver import IArchiver @@ -100,17 +100,19 @@ class Prototype: mail_box = Maildir(list_dir, create=True, factory=None) # Lock the maildir as Maildir.add() is not threadsafe - lock = Lock(os.path.join(config.LOCK_DIR, '%s-maildir.lock' % mlist.fqdn_listname)) - try: - lock.lock(timeout=timedelta(seconds=1)) - # Add the message to the Maildir - # Message_key could be used to construct the file path if - # necessary: - # os.path.join(archive_dir,mlist.fqdn_listname,'new',message_key) - message_key = mail_box.add(message) - except TimeOutError: - # log the error and go on - elog.error('Unable to lock archive for %s, discarded message: %s' % (mlist.fqdn_listname, message.get('message-id', '<unknown>'))) - finally: - # unlock the maildir - lock.unlock(unconditionally=1) + lock = Lock(os.path.join(config.LOCK_DIR, '%s-maildir.lock' + % mlist.fqdn_listname)) + with lock: + try: + lock.lock(timeout=timedelta(seconds=1)) + # Add the message to the Maildir + # Message_key could be used to construct the file path if + # necessary:: + # os.path.join(archive_dir, mlist.fqdn_listname, 'new', + # message_key) + message_key = mail_box.add(message) + except TimeOutError: + # log the error and go on + elog.error('Unable to lock archive for %s, discarded' + ' message: %s' % (mlist.fqdn_listname, + message.get('message-id', '<unknown>'))) |
