diff options
Diffstat (limited to 'Mailman/bin')
| -rw-r--r-- | Mailman/bin/arch.py | 85 | ||||
| -rw-r--r-- | Mailman/bin/gate_news.py | 21 | ||||
| -rw-r--r-- | Mailman/bin/mailmanctl.py | 8 | ||||
| -rw-r--r-- | Mailman/bin/withlist.py | 44 |
4 files changed, 57 insertions, 101 deletions
diff --git a/Mailman/bin/arch.py b/Mailman/bin/arch.py index a7929e407..09ca4d914 100644 --- a/Mailman/bin/arch.py +++ b/Mailman/bin/arch.py @@ -15,6 +15,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. +from __future__ import with_statement + import os import sys import errno @@ -25,9 +27,10 @@ from Mailman import Errors from Mailman import Version from Mailman import i18n from Mailman.Archiver.HyperArch import HyperArchive -from Mailman.LockFile import LockFile +from Mailman.Defaults import hours from Mailman.MailList import MailList from Mailman.configuration import config +from Mailman.lockfile import LockFile _ = i18n._ __i18n_templates__ = True @@ -119,53 +122,41 @@ def main(): # really don't know how long it will take. # # XXX processUnixMailbox() should refresh the lock. - # - # XXX This may not be necessary because I think we lay claim to the - # list lock up above, although that may be too short to be of use (and - # maybe we don't really want to lock the list anyway). - lockfile = os.path.join(config.LOCK_DIR, mlist._internal_name) + \ - '.archiver.lock' - # set the lock lifetime to 3 hours. XXX is this reasonable??? - lock = LockFile(lockfile, lifetime=3*60*60) - lock.lock() - # 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) + 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() - finally: - if lock: - lock.unlock() - if mlist: - mlist.Unlock() + 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 da78b6068..6fc8139c6 100644 --- a/Mailman/bin/gate_news.py +++ b/Mailman/bin/gate_news.py @@ -15,6 +15,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. +from __future__ import with_statement + import os import sys import time @@ -26,11 +28,11 @@ import optparse import email.Errors from email.Parser import Parser -from Mailman 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 _ @@ -210,7 +212,7 @@ def process_lists(glock): # loop over range, and this will not include the last # element in the list. poll_newsgroup(mlist, conn, start, last + 1, glock) - except LockFile.TimeOutError: + except lockfile.TimeOutError: log.error('Could not acquire list lock: %s', listname) finally: if mlist.Locked(): @@ -230,19 +232,14 @@ def main(): loginit.initialize(propagate=True) log = logging.getLogger('mailman.fromusenet') - lock = LockFile.LockFile(GATENEWS_LOCK_FILE, - # It's okay to hijack this - lifetime=LOCK_LIFETIME) try: - lock.lock(timeout=0.5) + with lockfile.LockFile(GATENEWS_LOCK_FILE, + # It's okay to hijack this + lifetime=LOCK_LIFETIME): + process_lists(lock) + clearcache() except LockFile.TimeOutError: log.error('Could not acquire gate_news lock') - return - try: - process_lists(lock) - finally: - clearcache() - lock.unlock(unconditionally=True) diff --git a/Mailman/bin/mailmanctl.py b/Mailman/bin/mailmanctl.py index f6190f685..07716029b 100644 --- a/Mailman/bin/mailmanctl.py +++ b/Mailman/bin/mailmanctl.py @@ -27,9 +27,9 @@ import optparse from Mailman import Defaults from Mailman import Errors -from Mailman import LockFile 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,11 +197,11 @@ 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.LockFile(config.LOCK_FILE, LOCK_LIFETIME) try: lock.lock(0.1) return lock - except LockFile.TimeOutError: + except lockfile.TimeOutError: if not force: raise # Force removal of lock first @@ -216,7 +216,7 @@ def acquire_lock(force): try: lock = acquire_lock_1(force) return lock - except LockFile.TimeOutError: + except lockfile.TimeOutError: status = qrunner_state() if status == 1: # host matches and proc exists diff --git a/Mailman/bin/withlist.py b/Mailman/bin/withlist.py index cf40ddabd..dc820eb90 100644 --- a/Mailman/bin/withlist.py +++ b/Mailman/bin/withlist.py @@ -17,7 +17,6 @@ import os import sys -import atexit import optparse from Mailman import Errors @@ -31,20 +30,6 @@ __i18n_templates__ = True LAST_MLIST = None VERBOSE = True -LOCK = False - - - -def exitfunc(mlist): - """Unlock a locked list, but do not implicitly Save() it.""" - if mlist.Locked(): - if VERBOSE: - listname = mlist.fqdn_listname - print >> sys.stderr, _( - 'Unlocking (but not saving) list: $listname') - mlist.Unlock() - if VERBOSE: - print >> sys.stderr, _('Finalizing') @@ -54,18 +39,12 @@ def do_list(listname, args, func): if '@' not in listname: listname += '@' + config.DEFAULT_EMAIL_HOST - if VERBOSE: - print >> sys.stderr, _('Loading list $listname'), - if LOCK: - print >> sys.stderr, _('(locked)') - else: - print >> sys.stderr, _('(unlocked)') - mlist = config.db.list_manager.get(listname) if mlist is None: print >> sys.stderr, _('Unknown list: $listname') else: - atexit.register(exitfunc, mlist) + if VERBOSE: + print >> sys.stderr, _('Loaded list: $listname') LAST_MLIST = mlist # Try to import the module and run the callable. if func: @@ -107,7 +86,7 @@ Now, from the command line you can print the list's posting address by running the following from the command line: % bin/withlist -r listaddr mylist - Loading list: mylist (unlocked) + Loading list: mylist Importing listaddr ... Running listaddr.listaddr() ... mylist@myhost.com @@ -115,7 +94,7 @@ the following from the command line: And you can print the list's request address by running: % bin/withlist -r listaddr.requestaddr mylist - Loading list: mylist (unlocked) + Loading list: mylist Importing listaddr ... Running listaddr.requestaddr() ... mylist-request@myhost.com @@ -136,15 +115,6 @@ called 'changepw.py': and run this from the command line: % bin/withlist -l -r changepw mylist somebody@somewhere.org foobar""")) - parser.add_option('-l', '--lock', - default=False, action='store_true', help=_("""\ -Lock the list when opening. Normally the list is opened unlocked (e.g. for -read-only operations). You can always lock the file after the fact by typing -'m.Lock()' - -Note that if you use this option, you should explicitly call m.Save() before -exiting, since the interpreter's clean up procedure will not automatically -save changes to the IMailingList object (but it will unlock the list).""")) parser.add_option('-i', '--interactive', default=None, action='store_true', help=_("""\ Leaves you at an interactive prompt after all other processing is complete. @@ -180,14 +150,12 @@ the results.""")) def main(): - global LAST_MLIST, LOCK, VERBOSE + global LAST_MLIST, VERBOSE parser, opts, args = parseargs() initialize(opts.config, not opts.quiet) VERBOSE = not opts.quiet - LOCK = opts.lock - # The default for interact is true unless -r was given if opts.interactive is None: if not opts.run: @@ -241,5 +209,5 @@ def main(): "The variable 'm' is the $listname mailing list") else: banner = interact.DEFAULT_BANNER - overrides = dict(m=LAST_MLIST, r=r) + overrides = dict(m=LAST_MLIST, r=r, flush=config.db.flush) interact.interact(upframe=False, banner=banner, overrides=overrides) |
