Commit f23ac8ca authored by Barry Warsaw's avatar Barry Warsaw

Add a 'name' attribute to the Switchboards. This is so 'whichq' can be set

for bin/mailman unshunt.
parent 8c7ee646
......@@ -32,8 +32,11 @@ from zope.interface import Interface, Attribute
class ISwitchboard(Interface):
"""The switchboard."""
name = Attribute(
"""The name of the switchboard's queue.""")
queue_directory = Attribute(
"""The name of the queue directory this switchboard is responsible for.
"""The queue directory this switchboard is responsible for.
This should be a subdirectory of the system-wide top-level queue
directory.
......
......@@ -246,7 +246,7 @@ are receiving the only remaining copy of the discarded message.
subject=_('Content filtered message notification'))
if mlist.filter_action == 3 and \
config.OWNERS_CAN_PRESERVE_FILTERED_MESSAGES:
badq = Switchboard(config.BADQUEUE_DIR)
badq = Switchboard('bad', config.BADQUEUE_DIR)
badq.enqueue(msg, msgdata)
# Most cases also discard the message
raise errors.DiscardMessage
......
......@@ -90,12 +90,14 @@ class Switchboard:
substitutions = config.paths
substitutions['name'] = name
path = expand(conf.path, substitutions)
config.switchboards[name] = Switchboard(path)
config.switchboards[name] = Switchboard(name, path)
def __init__(self, queue_directory,
def __init__(self, name, queue_directory,
slice=None, numslices=1, recover=False):
"""Create a switchboard object.
:param name: The queue name.
:type name: str
:param queue_directory: The queue directory.
:type queue_directory: str
:param slice: The slice number for this switchboard, or None. If not
......@@ -109,6 +111,7 @@ class Switchboard:
"""
assert (numslices & (numslices - 1)) == 0, (
'Not a power of 2: {0}'.format(numslices))
self.name = name
self.queue_directory = queue_directory
# Create the directory if it doesn't yet exist.
makedirs(self.queue_directory, 0770)
......@@ -300,7 +303,7 @@ class Runner:
self.queue_directory = expand(section.path, substitutions)
numslices = int(section.instances)
self.switchboard = Switchboard(
self.queue_directory, slice, numslices, True)
name, self.queue_directory, slice, numslices, True)
self.sleep_time = as_timedelta(section.sleep_time)
# sleep_time is a timedelta; turn it into a float for time.sleep().
self.sleep_float = (86400 * self.sleep_time.days +
......@@ -378,7 +381,7 @@ class Runner:
# intervention.
self._log(error)
# Put a marker in the metadata for unshunting.
msgdata['whichq'] = self.switchboard.queue_directory
msgdata['whichq'] = self.switchboard.name
# It is possible that shunting can throw an exception, e.g. a
# permissions problem or a MemoryError due to a really large
# message. Try to be graceful.
......
......@@ -11,12 +11,14 @@ instance of a switchboard is responsible for one queue directory.
... A test message.
... """)
Create a switchboard by giving its queue directory.
Create a switchboard by giving its queue name and directory.
>>> import os
>>> queue_directory = os.path.join(config.QUEUE_DIR, 'test')
>>> from mailman.queue import Switchboard
>>> switchboard = Switchboard(queue_directory)
>>> switchboard = Switchboard('test', queue_directory)
>>> print switchboard.name
test
>>> switchboard.queue_directory == queue_directory
True
......@@ -136,7 +138,7 @@ place. These can be recovered when the switchboard is instantiated.
... # Don't call .finish()
>>> check_qfiles()
.bak: 3
>>> switchboard_2 = Switchboard(queue_directory, recover=True)
>>> switchboard_2 = Switchboard('test', queue_directory, recover=True)
>>> check_qfiles()
.pck: 3
......
......@@ -153,29 +153,29 @@ class MaildirRunner(Runner):
msgdata = {'listname': listname}
# -admin is deprecated
if subq in ('bounces', 'admin'):
queue = Switchboard(config.BOUNCEQUEUE_DIR)
queue = Switchboard('bounces', config.BOUNCEQUEUE_DIR)
elif subq == 'confirm':
msgdata['toconfirm'] = 1
queue = Switchboard(config.CMDQUEUE_DIR)
queue = Switchboard('command', config.CMDQUEUE_DIR)
elif subq in ('join', 'subscribe'):
msgdata['tojoin'] = 1
queue = Switchboard(config.CMDQUEUE_DIR)
queue = Switchboard('command', config.CMDQUEUE_DIR)
elif subq in ('leave', 'unsubscribe'):
msgdata['toleave'] = 1
queue = Switchboard(config.CMDQUEUE_DIR)
queue = Switchboard('command', config.CMDQUEUE_DIR)
elif subq == 'owner':
msgdata.update({
'toowner': True,
'envsender': config.SITE_OWNER_ADDRESS,
'pipeline': config.OWNER_PIPELINE,
})
queue = Switchboard(config.INQUEUE_DIR)
queue = Switchboard('in', config.INQUEUE_DIR)
elif subq is None:
msgdata['tolist'] = 1
queue = Switchboard(config.INQUEUE_DIR)
queue = Switchboard('in', config.INQUEUE_DIR)
elif subq == 'request':
msgdata['torequest'] = 1
queue = Switchboard(config.CMDQUEUE_DIR)
queue = Switchboard('command', config.CMDQUEUE_DIR)
else:
log.error('Unknown sub-queue: %s', subq)
os.rename(dstname, xdstname)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment