Changeset View
Standalone View
wallace/__init__.py
Show All 33 Lines | |||||
import pykolab | import pykolab | ||||
from pykolab import utils | from pykolab import utils | ||||
from pykolab.translate import _ | from pykolab.translate import _ | ||||
log = pykolab.getLogger('pykolab.wallace') | log = pykolab.getLogger('pykolab.wallace') | ||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
from modules import cb_action_ACCEPT | from modules import cb_action_ACCEPT | ||||
Lint: PEP8 E402: module level import not at top of file | |||||
def pickup_message(filepath, *args, **kw): | def pickup_message(filepath, *args, **kw): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
wallace_modules = args[0] | wallace_modules = args[0] | ||||
if kw.has_key('module'): | if kw.has_key('module'): | ||||
# Cause the previous modules to be skipped | # Cause the previous modules to be skipped | ||||
wallace_modules = wallace_modules[(wallace_modules.index(kw['module'])+1):] | wallace_modules = wallace_modules[(wallace_modules.index(kw['module'])+1):] | ||||
Lint: PEP8 E501 line too long (83 > 79 characters) Lint: PEP8 E501: line too long (83 > 79 characters) | |||||
log.debug(_("Wallace modules: %r") % (wallace_modules), level=8) | log.debug(_("Wallace modules: %r") % (wallace_modules), level=8) | ||||
# Execute the module | # Execute the module | ||||
if kw.has_key('stage'): | if kw.has_key('stage'): | ||||
modules.execute(kw['module'], filepath, stage=kw['stage']) | modules.execute(kw['module'], filepath, stage=kw['stage']) | ||||
else: | else: | ||||
modules.execute(kw['module'], filepath) | modules.execute(kw['module'], filepath) | ||||
# After all modules are executed, continue with a call to | # After all modules are executed, continue with a call to | ||||
# accept the message and re-inject in to Postfix. | # accept the message and re-inject in to Postfix. | ||||
continue_with_accept = True | continue_with_accept = True | ||||
for module in wallace_modules: | for module in wallace_modules: | ||||
try: | try: | ||||
result_filepath = modules.execute(module, filepath) | result_filepath = modules.execute(module, filepath) | ||||
except: | except: | ||||
log.error(_("Module %s.execute() failed on message %r with error: %s" % (module, filepath, traceback.format_exc()))) | log.error(_("Module %s.execute() failed on message %r with error: %s" % (module, filepath, traceback.format_exc()))) | ||||
Lint: PEP8 E501 line too long (128 > 79 characters) Lint: PEP8 E501: line too long (128 > 79 characters) | |||||
result_filepath = False | result_filepath = False | ||||
if not result_filepath == None and not result_filepath == False: | if not result_filepath == None and not result_filepath == False: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
filepath = result_filepath | filepath = result_filepath | ||||
else: | else: | ||||
# A module has returned False or None | # A module has returned False or None | ||||
continue_with_accept = False | continue_with_accept = False | ||||
# The message very likely has been consumed by the module that returned False | # The message very likely has been consumed by the module that returned False | ||||
Lint: PEP8 E501 line too long (89 > 79 characters) Lint: PEP8 E501: line too long (89 > 79 characters) | |||||
if not os.path.isfile(filepath): | if not os.path.isfile(filepath): | ||||
break | break | ||||
if continue_with_accept: | if continue_with_accept: | ||||
cb_action_ACCEPT('wallace', filepath) | cb_action_ACCEPT('wallace', filepath) | ||||
def modules_heartbeat(wallace_modules): | def modules_heartbeat(wallace_modules): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
lastrun = 0 | lastrun = 0 | ||||
while True: | while True: | ||||
try: | try: | ||||
for module in wallace_modules: | for module in wallace_modules: | ||||
try: | try: | ||||
modules.heartbeat(module, lastrun) | modules.heartbeat(module, lastrun) | ||||
except: | except: | ||||
log.error(_("Module %s.heartbeat() failed with error: %s" % (module, traceback.format_exc()))) | log.error(_("Module %s.heartbeat() failed with error: %s" % (module, traceback.format_exc()))) | ||||
Lint: PEP8 E501 line too long (114 > 79 characters) Lint: PEP8 E501: line too long (114 > 79 characters) | |||||
lastrun = int(time.time()) | lastrun = int(time.time()) | ||||
time.sleep(60) | time.sleep(60) | ||||
except (SystemExit, KeyboardInterrupt), e: | except (SystemExit, KeyboardInterrupt), e: | ||||
log.info("Terminating heartbeat process") | log.info("Terminating heartbeat process") | ||||
break | break | ||||
def worker_process(*args, **kw): | def worker_process(*args, **kw): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
log.debug(_("Worker process %s initializing") % (multiprocessing.current_process().name), level=1) | log.debug(_("Worker process %s initializing") % (multiprocessing.current_process().name), level=1) | ||||
Lint: PEP8 E501 line too long (102 > 79 characters) Lint: PEP8 E501: line too long (102 > 79 characters) | |||||
class WallaceDaemon(object): | class WallaceDaemon(object): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
def __init__(self): | def __init__(self): | ||||
self.current_connections = 0 | self.current_connections = 0 | ||||
self.max_connections = 24 | self.max_connections = 24 | ||||
daemon_group = conf.add_cli_parser_option_group(_("Daemon Options")) | daemon_group = conf.add_cli_parser_option_group(_("Daemon Options")) | ||||
daemon_group.add_option( | daemon_group.add_option( | ||||
"--fork", | "--fork", | ||||
dest = "fork_mode", | dest = "fork_mode", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
action = "store_true", | action = "store_true", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
default = False, | default = False, | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
help = _("Fork to the background.") | help = _("Fork to the background.") | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
) | ) | ||||
daemon_group.add_option( | daemon_group.add_option( | ||||
"-b", "--bind", | "-b", "--bind", | ||||
dest = "wallace_bind_address", | dest = "wallace_bind_address", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
action = "store", | action = "store", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
default = "localhost", | default = "localhost", | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
help = _("Bind address for Wallace.") | help = _("Bind address for Wallace.") | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
) | ) | ||||
daemon_group.add_option( | daemon_group.add_option( | ||||
"-g", | "-g", | ||||
"--group", | "--group", | ||||
dest = "process_groupname", | dest = "process_groupname", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
action = "store", | action = "store", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
default = "kolab", | default = "kolab", | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
help = _("Run as group GROUPNAME"), | help = _("Run as group GROUPNAME"), | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
metavar = "GROUPNAME" | metavar = "GROUPNAME" | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
) | ) | ||||
daemon_group.add_option( | daemon_group.add_option( | ||||
"--threads", | "--threads", | ||||
dest = "max_threads", | dest = "max_threads", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
action = "store", | action = "store", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
default = 24, | default = 24, | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
type = int, | type = int, | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
help = _("Number of threads to use.") | help = _("Number of threads to use.") | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
) | ) | ||||
daemon_group.add_option( | daemon_group.add_option( | ||||
"-p", "--pid-file", | "-p", "--pid-file", | ||||
dest = "pidfile", | dest = "pidfile", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
action = "store", | action = "store", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
default = "/var/run/wallaced/wallaced.pid", | default = "/var/run/wallaced/wallaced.pid", | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
help = _("Path to the PID file to use.") | help = _("Path to the PID file to use.") | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
) | ) | ||||
daemon_group.add_option( | daemon_group.add_option( | ||||
"--port", | "--port", | ||||
dest = "wallace_port", | dest = "wallace_port", | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
action = "store", | action = "store", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
default = 10026, | default = 10026, | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
type = int, | type = int, | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
help = _("Port that Wallace is supposed to use.") | help = _("Port that Wallace is supposed to use.") | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
) | ) | ||||
daemon_group.add_option( | daemon_group.add_option( | ||||
"-u", | "-u", | ||||
"--user", | "--user", | ||||
dest = "process_username", | dest = "process_username", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
action = "store", | action = "store", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
default = "kolab", | default = "kolab", | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
help = _("Run as user USERNAME"), | help = _("Run as user USERNAME"), | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
metavar = "USERNAME" | metavar = "USERNAME" | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
) | ) | ||||
conf.finalize_conf() | conf.finalize_conf() | ||||
utils.ensure_directory( | utils.ensure_directory( | ||||
os.path.dirname(conf.pidfile), | os.path.dirname(conf.pidfile), | ||||
conf.process_username, | conf.process_username, | ||||
conf.process_groupname | conf.process_groupname | ||||
) | ) | ||||
import modules | import modules | ||||
modules.__init__() | modules.__init__() | ||||
self.modules = conf.get_list('wallace', 'modules') | self.modules = conf.get_list('wallace', 'modules') | ||||
if self.modules == None: | if self.modules == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.modules = [] | self.modules = [] | ||||
def do_wallace(self): | def do_wallace(self): | ||||
if version.StrictVersion(sys.version[:3]) >= version.StrictVersion("2.7"): | if version.StrictVersion(sys.version[:3]) >= version.StrictVersion("2.7"): | ||||
Lint: PEP8 E501 line too long (82 > 79 characters) Lint: PEP8 E501: line too long (82 > 79 characters) | |||||
self.pool = multiprocessing.Pool(conf.max_threads, worker_process, (), 1) | self.pool = multiprocessing.Pool(conf.max_threads, worker_process, (), 1) | ||||
Lint: PEP8 E501 line too long (85 > 79 characters) Lint: PEP8 E501: line too long (85 > 79 characters) | |||||
else: | else: | ||||
self.pool = multiprocessing.Pool(conf.max_threads, worker_process, ()) | self.pool = multiprocessing.Pool(conf.max_threads, worker_process, ()) | ||||
Lint: PEP8 E501 line too long (82 > 79 characters) Lint: PEP8 E501: line too long (82 > 79 characters) | |||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | ||||
bound = False | bound = False | ||||
shutdown = False | shutdown = False | ||||
while not bound: | while not bound: | ||||
try: | try: | ||||
if shutdown: | if shutdown: | ||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | ||||
s.bind((conf.wallace_bind_address, conf.wallace_port)) | s.bind((conf.wallace_bind_address, conf.wallace_port)) | ||||
bound = True | bound = True | ||||
except Exception, e: | except Exception, e: | ||||
log.warning( | log.warning( | ||||
_("Could not bind to socket on port %d on bind " + \ | _("Could not bind to socket on port %d on bind " + \ | ||||
Lint: PEP8 E502 the backslash is redundant between brackets Lint: PEP8 E502: the backslash is redundant between brackets | |||||
"address %s") % ( | "address %s") % ( | ||||
conf.wallace_port, | conf.wallace_port, | ||||
conf.wallace_bind_address | conf.wallace_bind_address | ||||
) | ) | ||||
) | ) | ||||
while not shutdown: | while not shutdown: | ||||
try: | try: | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | def do_wallace(self): | ||||
if stage.lower() == "hold": | if stage.lower() == "hold": | ||||
continue | continue | ||||
# Do not handle messages in a defer state. | # Do not handle messages in a defer state. | ||||
if stage.lower() == "defer": | if stage.lower() == "defer": | ||||
continue | continue | ||||
self.current_connections += 1 | self.current_connections += 1 | ||||
self.pool.apply_async(pickup_message, (filepath, (self.modules), {'module': module, 'stage': stage})) | self.pool.apply_async(pickup_message, (filepath, (self.modules), {'module': module, 'stage': stage})) | ||||
Lint: PEP8 E501 line too long (121 > 79 characters) Lint: PEP8 E501: line too long (121 > 79 characters) | |||||
self.current_connections -= 1 | self.current_connections -= 1 | ||||
continue | continue | ||||
self.current_connections += 1 | self.current_connections += 1 | ||||
self.pool.apply_async(pickup_message, (filepath, (self.modules))) | self.pool.apply_async(pickup_message, (filepath, (self.modules))) | ||||
Lint: PEP8 E501 line too long (81 > 79 characters) Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
self.current_connections -= 1 | self.current_connections -= 1 | ||||
# start background process to run periodic jobs in active modules | # start background process to run periodic jobs in active modules | ||||
self.heartbeat = multiprocessing.Process(target=modules_heartbeat, args=[self.modules]) | self.heartbeat = multiprocessing.Process(target=modules_heartbeat, args=[self.modules]) | ||||
Lint: PEP8 E501 line too long (95 > 79 characters) Lint: PEP8 E501: line too long (95 > 79 characters) | |||||
self.heartbeat.daemon = True | self.heartbeat.daemon = True | ||||
self.heartbeat.start() | self.heartbeat.start() | ||||
try: | try: | ||||
while 1: | while 1: | ||||
while self.current_connections >= self.max_connections: | while self.current_connections >= self.max_connections: | ||||
time.sleep(0.5) | time.sleep(0.5) | ||||
pair = s.accept() | pair = s.accept() | ||||
log.info(_("Accepted connection")) | log.info(_("Accepted connection")) | ||||
if not pair == None: | if not pair == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.current_connections += 1 | self.current_connections += 1 | ||||
connection, address = pair | connection, address = pair | ||||
channel = SMTPChannel(self, connection, address) | channel = SMTPChannel(self, connection, address) | ||||
asyncore.loop() | asyncore.loop() | ||||
except Exception, errmsg: | except Exception, errmsg: | ||||
traceback.print_exc() | traceback.print_exc() | ||||
s.shutdown(1) | s.shutdown(1) | ||||
s.close() | s.close() | ||||
# shut down hearbeat process | # shut down hearbeat process | ||||
self.heartbeat.terminate() | self.heartbeat.terminate() | ||||
def data_header(self, mailfrom, rcpttos): | def data_header(self, mailfrom, rcpttos): | ||||
COMMASPACE = ', ' | COMMASPACE = ', ' | ||||
return "X-Kolab-From: " + mailfrom + "\r\n" + \ | return "X-Kolab-From: " + mailfrom + "\r\n" + \ | ||||
"X-Kolab-To: " + COMMASPACE.join(rcpttos) + "\r\n" | "X-Kolab-To: " + COMMASPACE.join(rcpttos) + "\r\n" | ||||
Lint: PEP8 E127 continuation line over-indented for visual indent Lint: PEP8 E127: continuation line over-indented for visual indent | |||||
def process_message(self, peer, mailfrom, rcpttos, data): | def process_message(self, peer, mailfrom, rcpttos, data): | ||||
""" | """ | ||||
We have retrieved the message. This should be as fast as possible, | We have retrieved the message. This should be as fast as possible, | ||||
and not ever block. | and not ever block. | ||||
""" | """ | ||||
header = self.data_header(mailfrom, rcpttos) | header = self.data_header(mailfrom, rcpttos) | ||||
(fp, filename) = tempfile.mkstemp(dir="/var/spool/pykolab/wallace/") | (fp, filename) = tempfile.mkstemp(dir="/var/spool/pykolab/wallace/") | ||||
# @TODO: and add line separator (\n or \r\n?) | # @TODO: and add line separator (\n or \r\n?) | ||||
# we should make sure there's only one line separator between | # we should make sure there's only one line separator between | ||||
# kolab headers and the original message (data) | # kolab headers and the original message (data) | ||||
os.write(fp, header); | os.write(fp, header); | ||||
Lint: PEP8 E703 statement ends with a semicolon Lint: PEP8 E703: statement ends with a semicolon | |||||
os.write(fp, data) | os.write(fp, data) | ||||
os.close(fp) | os.close(fp) | ||||
self.pool.apply_async(pickup_message, (filename, (self.modules))) | self.pool.apply_async(pickup_message, (filename, (self.modules))) | ||||
self.current_connections -= 1 | self.current_connections -= 1 | ||||
return | return | ||||
def reload_config(self, *args, **kw): | def reload_config(self, *args, **kw): | ||||
pass | pass | ||||
def remove_pid(self, *args, **kw): | def remove_pid(self, *args, **kw): | ||||
if os.access(conf.pidfile, os.R_OK): | if os.access(conf.pidfile, os.R_OK): | ||||
os.remove(conf.pidfile) | os.remove(conf.pidfile) | ||||
if hasattr(self, 'pool'): | |||||
self.pool.close() | self.pool.close() | ||||
self.pool.join() | self.pool.join() | ||||
raise SystemExit | raise SystemExit | ||||
def run(self): | def run(self): | ||||
""" | """ | ||||
Run the Wallace daemon. | Run the Wallace daemon. | ||||
""" | """ | ||||
Show All 24 Lines | def run(self): | ||||
conf.process_groupname | conf.process_groupname | ||||
) | ) | ||||
sys.exit(1) | sys.exit(1) | ||||
# Set real and effective group if not the same as current. | # Set real and effective group if not the same as current. | ||||
if not group_gid == rgid: | if not group_gid == rgid: | ||||
log.debug( | log.debug( | ||||
_("Switching real and effective group id to %d") % ( | _("Switching real and effective group id to %d") % ( | ||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
group_gid | group_gid | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
os.setregid(group_gid, group_gid) | os.setregid(group_gid, group_gid) | ||||
if ruid == 0: | if ruid == 0: | ||||
Show All 12 Lines | def run(self): | ||||
except KeyError: | except KeyError: | ||||
print >> sys.stderr, _("User %s does not exist") % ( | print >> sys.stderr, _("User %s does not exist") % ( | ||||
conf.process_username | conf.process_username | ||||
) | ) | ||||
sys.exit(1) | sys.exit(1) | ||||
# Set real and effective user if not the same as current. | # Set real and effective user if not the same as current. | ||||
Lint: PEP8 E303 too many blank lines (2) Lint: PEP8 E303: too many blank lines (2) | |||||
if not user_uid == ruid: | if not user_uid == ruid: | ||||
log.debug( | log.debug( | ||||
_("Switching real and effective user id to %d") % ( | _("Switching real and effective user id to %d") % ( | ||||
Lint: PEP8 E501 line too long (83 > 79 characters) Lint: PEP8 E501: line too long (83 > 79 characters) | |||||
user_uid | user_uid | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
os.setreuid(user_uid, user_uid) | os.setreuid(user_uid, user_uid) | ||||
except: | except: | ||||
Show All 38 Lines | def run(self): | ||||
except SystemExit, e: | except SystemExit, e: | ||||
exitcode = e | exitcode = e | ||||
except KeyboardInterrupt: | except KeyboardInterrupt: | ||||
exitcode = 1 | exitcode = 1 | ||||
log.info(_("Interrupted by user")) | log.info(_("Interrupted by user")) | ||||
except AttributeError, e: | except AttributeError, e: | ||||
exitcode = 1 | exitcode = 1 | ||||
traceback.print_exc() | traceback.print_exc() | ||||
print >> sys.stderr, _("Traceback occurred, please report a bug at https://issues.kolab.org") | print >> sys.stderr, _("Traceback occurred, please report a bug at https://issues.kolab.org") | ||||
Lint: PEP8 E501 line too long (105 > 79 characters) Lint: PEP8 E501: line too long (105 > 79 characters) | |||||
except TypeError, e: | except TypeError, e: | ||||
exitcode = 1 | exitcode = 1 | ||||
traceback.print_exc() | traceback.print_exc() | ||||
log.error(_("Type Error: %s") % e) | log.error(_("Type Error: %s") % e) | ||||
except: | except: | ||||
exitcode = 2 | exitcode = 2 | ||||
traceback.print_exc() | traceback.print_exc() | ||||
print >> sys.stderr, _("Traceback occurred, please report a bug at https://issues.kolab.org") | print >> sys.stderr, _("Traceback occurred, please report a bug at https://issues.kolab.org") | ||||
Lint: PEP8 E501 line too long (105 > 79 characters) Lint: PEP8 E501: line too long (105 > 79 characters) | |||||
sys.exit(exitcode) | sys.exit(exitcode) | ||||
def set_signal_handlers(self): | def set_signal_handlers(self): | ||||
import signal | import signal | ||||
signal.signal(signal.SIGHUP, self.reload_config) | signal.signal(signal.SIGHUP, self.reload_config) | ||||
signal.signal(signal.SIGTERM, self.remove_pid) | signal.signal(signal.SIGTERM, self.remove_pid) | ||||
def write_pid(self): | def write_pid(self): | ||||
pid = os.getpid() | pid = os.getpid() | ||||
if os.access(os.path.dirname(conf.pidfile), os.W_OK): | if os.access(os.path.dirname(conf.pidfile), os.W_OK): | ||||
fp = open(conf.pidfile,'w') | fp = open(conf.pidfile,'w') | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
fp.write("%d\n" % (pid)) | fp.write("%d\n" % (pid)) | ||||
fp.close() | fp.close() | ||||
else: | else: | ||||
print >> sys.stderr, _("Could not write pid file %s") % (conf.pidfile) | print >> sys.stderr, _("Could not write pid file %s") % (conf.pidfile) | ||||
Lint: PEP8 E501 line too long (82 > 79 characters) Lint: PEP8 E501: line too long (82 > 79 characters) |
module level import not at top of file