summaryrefslogtreecommitdiff
path: root/Mailman/bin
diff options
context:
space:
mode:
Diffstat (limited to 'Mailman/bin')
-rw-r--r--Mailman/bin/arch.py106
-rw-r--r--Mailman/bin/gate_news.py12
-rw-r--r--Mailman/bin/mailmanctl.py5
-rw-r--r--Mailman/bin/testall.py5
-rw-r--r--Mailman/bin/update.py3
5 files changed, 62 insertions, 69 deletions
diff --git a/Mailman/bin/arch.py b/Mailman/bin/arch.py
index 09ca4d914..6227482ad 100644
--- a/Mailman/bin/arch.py
+++ b/Mailman/bin/arch.py
@@ -23,14 +23,15 @@ import errno
import shutil
import optparse
+from locknix.lockfile import Lock
+
from Mailman import Errors
from Mailman import Version
from Mailman import i18n
from Mailman.Archiver.HyperArch import HyperArchive
from Mailman.Defaults import hours
-from Mailman.MailList import MailList
from Mailman.configuration import config
-from Mailman.lockfile import LockFile
+from Mailman.initialize import initialize
_ = i18n._
__i18n_templates__ = True
@@ -103,62 +104,51 @@ def main():
mbox = args[1]
# Open the mailing list object
- mlist = None
- lock = None
- try:
+ mlist = config.list_manager.get(listname)
+ if mlist is None:
+ parser.error(_('No such list: $listname'))
+ if mbox is None:
+ mbox = mlist.ArchiveFileName()
+
+ i18n.set_language(mlist.preferred_language)
+ # Lay claim to the archive's lock file. This is so no other post can
+ # mess up the archive while we're processing it. Try to pick a
+ # suitably long period of time for the lock lifetime even though we
+ # really don't know how long it will take.
+ #
+ # XXX processUnixMailbox() should refresh the lock.
+ lock_path = os.path.join(mlist.full_path, '.archiver.lck')
+ with Lock(lock_path, lifetime=int(hours(3))):
+ # Maybe wipe the old archives
+ if opts.wipe:
+ if mlist.scrub_nondigest:
+ # TK: save the attachments dir because they are not in mbox
+ saved = False
+ atchdir = os.path.join(mlist.archive_dir(), 'attachments')
+ savedir = os.path.join(mlist.archive_dir() + '.mbox',
+ 'attachments')
+ try:
+ os.rename(atchdir, savedir)
+ saved = True
+ except OSError, e:
+ if e.errno <> errno.ENOENT:
+ raise
+ shutil.rmtree(mlist.archive_dir())
+ if mlist.scrub_nondigest and saved:
+ os.renames(savedir, atchdir)
try:
- mlist = MailList(listname)
- except Errors.MMListError, e:
- parser.print_help()
- print >> sys.stderr, _('No such list: $listname\n$e')
+ fp = open(mbox)
+ except IOError, e:
+ if e.errno == errno.ENOENT:
+ print >> sys.stderr, _('Cannot open mbox file: $mbox')
+ else:
+ print >> sys.stderr, e
sys.exit(1)
- if mbox is None:
- mbox = mlist.ArchiveFileName()
-
- i18n.set_language(mlist.preferred_language)
- # Lay claim to the archive's lock file. This is so no other post can
- # mess up the archive while we're processing it. Try to pick a
- # suitably long period of time for the lock lifetime even though we
- # really don't know how long it will take.
- #
- # XXX processUnixMailbox() should refresh the lock.
- with LockFile(os.path.join(mlist.full_path, '.archiver.lck'),
- lifetime=int(hours(3))):
- # Maybe wipe the old archives
- if opts.wipe:
- if mlist.scrub_nondigest:
- # TK: save the attachments dir because they are not in mbox
- saved = False
- atchdir = os.path.join(mlist.archive_dir(), 'attachments')
- savedir = os.path.join(mlist.archive_dir() + '.mbox',
- 'attachments')
- try:
- os.rename(atchdir, savedir)
- saved = True
- except OSError, e:
- if e.errno <> errno.ENOENT:
- raise
- shutil.rmtree(mlist.archive_dir())
- if mlist.scrub_nondigest and saved:
- os.renames(savedir, atchdir)
- try:
- fp = open(mbox)
- except IOError, e:
- if e.errno == errno.ENOENT:
- print >> sys.stderr, _('Cannot open mbox file: $mbox')
- else:
- print >> sys.stderr, e
- sys.exit(1)
-
- archiver = HyperArchive(mlist)
- archiver.VERBOSE = opts.verbose
- try:
- archiver.processUnixMailbox(fp, opts.start, opts.end)
- finally:
- archiver.close()
- fp.close()
-
-
-if __name__ == '__main__':
- main()
+ archiver = HyperArchive(mlist)
+ archiver.VERBOSE = opts.verbose
+ try:
+ archiver.processUnixMailbox(fp, opts.start, opts.end)
+ finally:
+ archiver.close()
+ fp.close()
diff --git a/Mailman/bin/gate_news.py b/Mailman/bin/gate_news.py
index 6fc8139c6..9402504dc 100644
--- a/Mailman/bin/gate_news.py
+++ b/Mailman/bin/gate_news.py
@@ -24,15 +24,15 @@ import socket
import logging
import nntplib
import optparse
-
import email.Errors
+
from email.Parser import Parser
+from locknix import lockfile
from Mailman import MailList
from Mailman import Message
from Mailman import Utils
from Mailman import Version
-from Mailman import lockfile
from Mailman import loginit
from Mailman.configuration import config
from Mailman.i18n import _
@@ -233,12 +233,12 @@ def main():
log = logging.getLogger('mailman.fromusenet')
try:
- with lockfile.LockFile(GATENEWS_LOCK_FILE,
- # It's okay to hijack this
- lifetime=LOCK_LIFETIME):
+ with lockfile.Lock(GATENEWS_LOCK_FILE,
+ # It's okay to hijack this
+ lifetime=LOCK_LIFETIME):
process_lists(lock)
clearcache()
- except LockFile.TimeOutError:
+ except lockfile.TimeOutError:
log.error('Could not acquire gate_news lock')
diff --git a/Mailman/bin/mailmanctl.py b/Mailman/bin/mailmanctl.py
index 07716029b..8b7eeb5d2 100644
--- a/Mailman/bin/mailmanctl.py
+++ b/Mailman/bin/mailmanctl.py
@@ -25,11 +25,12 @@ import socket
import logging
import optparse
+from locknix import lockfile
+
from Mailman import Defaults
from Mailman import Errors
from Mailman import Utils
from Mailman import Version
-from Mailman import lockfile
from Mailman import loginit
from Mailman.configuration import config
from Mailman.i18n import _
@@ -197,7 +198,7 @@ def qrunner_state():
def acquire_lock_1(force):
# Be sure we can acquire the master qrunner lock. If not, it means some
# other master qrunner daemon is already going.
- lock = lockfile.LockFile(config.LOCK_FILE, LOCK_LIFETIME)
+ lock = lockfile.Lock(config.LOCK_FILE, LOCK_LIFETIME)
try:
lock.lock(0.1)
return lock
diff --git a/Mailman/bin/testall.py b/Mailman/bin/testall.py
index f6f263a31..9be591253 100644
--- a/Mailman/bin/testall.py
+++ b/Mailman/bin/testall.py
@@ -47,7 +47,7 @@ def v_callback(option, opt, value, parser):
elif opt in ('-v', '--verbose'):
delta = 1
else:
- delta = 0
+ raise AssertionError('Unexpected option: %s' % opt)
dest = getattr(parser.values, option.dest)
setattr(parser.values, option.dest, max(0, dest + delta))
@@ -217,7 +217,8 @@ def main():
with open(cfg_out, 'a') as fp:
print >> fp, 'SQLALCHEMY_ENGINE_URL = "%s"' % test_engine_url
- initialize_2()
+ # With -vvv, turn on engine debugging.
+ initialize_2(opts.verbosity > 3)
# Run the tests
basedir = os.path.dirname(Mailman.__file__)
diff --git a/Mailman/bin/update.py b/Mailman/bin/update.py
index 93bb0021b..379a5a1b5 100644
--- a/Mailman/bin/update.py
+++ b/Mailman/bin/update.py
@@ -26,12 +26,13 @@ import cPickle
import marshal
import optparse
+from locknix.lockfile import TimeOutError
+
from Mailman import MailList
from Mailman import Message
from Mailman import Pending
from Mailman import Utils
from Mailman import Version
-from Mailman.LockFile import TimeOutError
from Mailman.MemberAdaptor import BYBOUNCE, ENABLED
from Mailman.OldStyleMemberships import OldStyleMemberships
from Mailman.Queue.Switchboard import Switchboard