Changeset View
Changeset View
Standalone View
Standalone View
wallace/module_optout.py
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | def execute(*args, **kw): | ||||
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)) | ||||
# TODO: Test for correct call. | # TODO: Test for correct call. | ||||
filepath = args[0] | filepath = args[0] | ||||
if kw.has_key('stage'): | if 'stage' in kw: | ||||
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) | ||||
log.debug(_("Testing cb_action_%s()") % (kw['stage']), level=8) | log.debug(_("Testing cb_action_%s()") % (kw['stage']), level=8) | ||||
if hasattr(modules, 'cb_action_%s' % (kw['stage'])): | if hasattr(modules, 'cb_action_%s' % (kw['stage'])): | ||||
log.debug(_("Attempting to execute cb_action_%s()") % (kw['stage']), level=8) | log.debug(_("Attempting to execute cb_action_%s()") % (kw['stage']), level=8) | ||||
exec('modules.cb_action_%s(%r, %r)' % (kw['stage'],'optout',filepath)) | exec('modules.cb_action_%s(%r, %r)' % (kw['stage'],'optout',filepath)) | ||||
return | return | ||||
#modules.next_module('optout') | #modules.next_module('optout') | ||||
Show All 16 Lines | def execute(*args, **kw): | ||||
_recipients = {} | _recipients = {} | ||||
for answer in answers: | for answer in answers: | ||||
_recipients[answer] = { | _recipients[answer] = { | ||||
"To": [], | "To": [], | ||||
"Cc": [] | "Cc": [] | ||||
} | } | ||||
for recipient_type in recipients.keys(): | for recipient_type in recipients: | ||||
for recipient in recipients[recipient_type]: | for recipient in recipients[recipient_type]: | ||||
log.debug( | log.debug( | ||||
_("Running opt-out consult from envelope sender '%s " + \ | _("Running opt-out consult from envelope sender '%s " + \ | ||||
"<%s>' to recipient %s <%s>") % ( | "<%s>' to recipient %s <%s>") % ( | ||||
envelope_sender[0][0], | envelope_sender[0][0], | ||||
envelope_sender[0][1], | envelope_sender[0][1], | ||||
recipient[0], | recipient[0], | ||||
recipient[1] | recipient[1] | ||||
Show All 29 Lines | for answer in answers: | ||||
new_filepath = os.path.join(mybasepath, answer, os.path.basename(filepath)) | new_filepath = os.path.join(mybasepath, answer, os.path.basename(filepath)) | ||||
# Write out a message file representing the new contents for the message | # Write out a message file representing the new contents for the message | ||||
# use formataddr(recipient) | # use formataddr(recipient) | ||||
_message = message_from_file(open(filepath, 'r')) | _message = message_from_file(open(filepath, 'r')) | ||||
use_this = False | use_this = False | ||||
for recipient_type in _recipients[answer].keys(): | for recipient_type in _recipients[answer]: | ||||
_message.__delitem__(recipient_type) | _message.__delitem__(recipient_type) | ||||
if not len(_recipients[answer][recipient_type]) == 0: | if not len(_recipients[answer][recipient_type]) == 0: | ||||
_message.__setitem__( | _message.__setitem__( | ||||
recipient_type, | recipient_type, | ||||
',\n '.join( | ',\n '.join( | ||||
[formataddr(x) for x in _recipients[answer][recipient_type]] | [formataddr(x) for x in _recipients[answer][recipient_type]] | ||||
) | ) | ||||
) | ) | ||||
Show All 13 Lines | for answer in answers: | ||||
exec('modules.cb_action_%s(%r, %r)' % (answer,'optout', filename)) | exec('modules.cb_action_%s(%r, %r)' % (answer,'optout', filename)) | ||||
os.unlink(filepath) | os.unlink(filepath) | ||||
#print "Moving filepath %s to new_filepath %s" % (filepath, new_filepath) | #print "Moving filepath %s to new_filepath %s" % (filepath, new_filepath) | ||||
#os.rename(filepath, new_filepath) | #os.rename(filepath, new_filepath) | ||||
#if hasattr(modules, 'cb_action_%s' % (optout_answer)): | #if hasattr(modules, 'cb_action_%s' % (optout_answer)): | ||||
#log.debug(_("Attempting to execute cb_action_%s()") % (optout_answer), level=8) | #log.debug(_("Attempting to execute cb_action_%s()") % (optout_answer), level=8) | ||||
Lint: PEP8 E116: unexpected indentation (comment) | |||||
#exec('modules.cb_action_%s(%r, %r)' % (optout_answer,'optout', new_filepath)) | #exec('modules.cb_action_%s(%r, %r)' % (optout_answer,'optout', new_filepath)) | ||||
Lint: PEP8 E116 unexpected indentation (comment) Lint: PEP8 E116: unexpected indentation (comment) | |||||
#return | #return | ||||
Lint: PEP8 E116 unexpected indentation (comment) Lint: PEP8 E116: unexpected indentation (comment) | |||||
def request(params=None): | def request(params=None): | ||||
params = json.dumps(params) | params = json.dumps(params) | ||||
optout_url = conf.get('wallace_optout', 'optout_url') | optout_url = conf.get('wallace_optout', 'optout_url') | ||||
try: | try: | ||||
f = urllib.urlopen(optout_url, params) | f = urllib.urlopen(optout_url, params) | ||||
except Exception, e: | except Exception: | ||||
log.error(_("Could not send request to optout_url %s") % (optout_url)) | log.error(_("Could not send request to optout_url %s") % (optout_url)) | ||||
return "DEFER" | return "DEFER" | ||||
response = f.read() | response = f.read() | ||||
try: | try: | ||||
response_data = json.loads(response) | response_data = json.loads(response) | ||||
except ValueError, e: | except ValueError: | ||||
# Some data is not JSON | # Some data is not JSON | ||||
print "Response data is not JSON" | print("Response data is not JSON") | ||||
return response_data['result'] | return response_data['result'] |
unexpected indentation (comment)