Changeset View
Changeset View
Standalone View
Standalone View
wallace/module_invitationpolicy.py
Show First 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | |||||
policy_value_map = dict([(v &~ COND_TYPE_ALL, k) for (k, v) in policy_name_map.iteritems()]) | policy_value_map = dict([(v &~ COND_TYPE_ALL, k) for (k, v) in policy_name_map.iteritems()]) | ||||
object_type_conditons = { | object_type_conditons = { | ||||
'event': COND_TYPE_EVENT, | 'event': COND_TYPE_EVENT, | ||||
'task': COND_TYPE_TASK | 'task': COND_TYPE_TASK | ||||
} | } | ||||
log = pykolab.getLogger('pykolab.wallace') | log = pykolab.getLogger('pykolab.wallace/invitationpolicy') | ||||
extra_log_params = {'qid': '-'} | |||||
log = pykolab.logger.LoggerAdapter(log, extra_log_params) | |||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
mybasepath = '/var/spool/pykolab/wallace/invitationpolicy/' | mybasepath = '/var/spool/pykolab/wallace/invitationpolicy/' | ||||
auth = None | auth = None | ||||
imap = None | imap = None | ||||
write_locks = [] | write_locks = [] | ||||
Show All 22 Lines | def reject(filepath): | ||||
os.rename(filepath, new_filepath) | os.rename(filepath, new_filepath) | ||||
filepath = new_filepath | filepath = new_filepath | ||||
exec('modules.cb_action_REJECT(%r, %r)' % ('invitationpolicy',filepath)) | exec('modules.cb_action_REJECT(%r, %r)' % ('invitationpolicy',filepath)) | ||||
def description(): | def description(): | ||||
return """Invitation policy execution module.""" | return """Invitation policy execution module.""" | ||||
def cleanup(): | def cleanup(): | ||||
global auth, imap, write_locks | global auth, imap, write_locks, 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 | ||||
# remove remaining write locks | # remove remaining write locks | ||||
for key in write_locks: | for key in write_locks: | ||||
remove_write_lock(key, False) | remove_write_lock(key, False) | ||||
def execute(*args, **kw): | def execute(*args, **kw): | ||||
global auth, imap | global auth, imap, extra_log_params | ||||
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', 'locks']: | for stage in ['incoming', 'ACCEPT', 'REJECT', 'HOLD', 'DEFER', 'locks']: | ||||
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(_("Invitation policy called for %r, %r") % (args, kw), level=8) | log.debug(_("Invitation policy called for %r, %r") % (args, kw), level=8) | ||||
auth = Auth() | auth = Auth() | ||||
imap = IMAP() | imap = IMAP() | ||||
filepath = args[0] | |||||
# ignore calls on lock files | # ignore calls on lock files | ||||
if '/locks/' in filepath or kw.has_key('stage') and kw['stage'] == 'locks': | if '/locks/' in filepath or kw.has_key('stage') and kw['stage'] == 'locks': | ||||
return False | return False | ||||
log.debug("Invitation policy executing for %r, %r" % (filepath, '/locks/' in filepath), level=8) | log.debug("Invitation policy executing for %r, %r" % (filepath, '/locks/' in filepath), level=8) | ||||
if kw.has_key('stage'): | if kw.has_key('stage'): | ||||
log.debug(_("Issuing callback after processing to stage %s") % (kw['stage']), level=8) | log.debug(_("Issuing callback after processing to stage %s") % (kw['stage']), level=8) | ||||
▲ Show 20 Lines • Show All 1,244 Lines • Show Last 20 Lines |