Changeset View
Changeset View
Standalone View
Standalone View
wallace/module_resources.py
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
policy_name_map = { | policy_name_map = { | ||||
'ACT_MANUAL': ACT_MANUAL, | 'ACT_MANUAL': ACT_MANUAL, | ||||
'ACT_ACCEPT': ACT_ACCEPT, | 'ACT_ACCEPT': ACT_ACCEPT, | ||||
'ACT_REJECT': ACT_REJECT, | 'ACT_REJECT': ACT_REJECT, | ||||
'ACT_ACCEPT_AND_NOTIFY': ACT_ACCEPT_AND_NOTIFY | 'ACT_ACCEPT_AND_NOTIFY': ACT_ACCEPT_AND_NOTIFY | ||||
} | } | ||||
log = pykolab.getLogger('pykolab.wallace') | log = pykolab.getLogger('pykolab.wallace/resources') | ||||
extra_log_params = {'qid': '-'} | |||||
log = pykolab.logger.LoggerAdapter(log, extra_log_params) | |||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
mybasepath = '/var/spool/pykolab/wallace/resources/' | mybasepath = '/var/spool/pykolab/wallace/resources/' | ||||
auth = None | auth = None | ||||
imap = None | imap = None | ||||
def __init__(): | def __init__(): | ||||
Show All 10 Lines | def accept(filepath): | ||||
os.rename(filepath, new_filepath) | os.rename(filepath, new_filepath) | ||||
filepath = new_filepath | filepath = new_filepath | ||||
exec('modules.cb_action_ACCEPT(%r, %r)' % ('resources',filepath)) | exec('modules.cb_action_ACCEPT(%r, %r)' % ('resources',filepath)) | ||||
def description(): | def description(): | ||||
return """Resource management module.""" | return """Resource management module.""" | ||||
def cleanup(): | def cleanup(): | ||||
global auth, imap | global auth, imap, extra_log_params | ||||
log.debug("cleanup(): %r, %r" % (auth, imap), level=8) | log.debug("cleanup(): %r, %r" % (auth, imap), level=8) | ||||
extra_log_params['qid'] = '-' | |||||
auth.disconnect() | auth.disconnect() | ||||
del auth | del auth | ||||
# Disconnect IMAP or we lock the mailbox almost constantly | # Disconnect IMAP or we lock the mailbox almost constantly | ||||
imap.disconnect() | imap.disconnect() | ||||
del imap | del imap | ||||
def execute(*args, **kw): | def execute(*args, **kw): | ||||
global auth, imap | global auth, imap, extra_log_params | ||||
# TODO: Test for correct call. | |||||
filepath = args[0] | |||||
extra_log_params['qid'] = os.path.basename(filepath) | |||||
# (re)set language to default | # (re)set language to default | ||||
pykolab.translate.setUserLanguage(conf.get('kolab','default_locale')) | pykolab.translate.setUserLanguage(conf.get('kolab','default_locale')) | ||||
if not os.path.isdir(mybasepath): | if not os.path.isdir(mybasepath): | ||||
os.makedirs(mybasepath) | os.makedirs(mybasepath) | ||||
for stage in ['incoming', 'ACCEPT', 'REJECT', 'HOLD', 'DEFER' ]: | for stage in ['incoming', 'ACCEPT', 'REJECT', 'HOLD', 'DEFER' ]: | ||||
if not os.path.isdir(os.path.join(mybasepath, stage)): | if not os.path.isdir(os.path.join(mybasepath, stage)): | ||||
os.makedirs(os.path.join(mybasepath, stage)) | os.makedirs(os.path.join(mybasepath, stage)) | ||||
log.debug(_("Resource Management called for %r, %r") % (args, kw), level=8) | log.debug(_("Resource Management called for %r, %r") % (args, kw), level=8) | ||||
auth = Auth() | auth = Auth() | ||||
imap = IMAP() | imap = IMAP() | ||||
# TODO: Test for correct call. | |||||
filepath = args[0] | |||||
if kw.has_key('stage'): | if kw.has_key('stage'): | ||||
log.debug( | log.debug( | ||||
_("Issuing callback after processing to stage %s") % ( | _("Issuing callback after processing to stage %s") % ( | ||||
kw['stage'] | kw['stage'] | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 1,324 Lines • Show Last 20 Lines |