Commit 71664a3b authored by Enrico Zini's avatar Enrico Zini
Browse files

Ported archive-process-email to python3

parent 2f7adf14
#!/usr/bin/python
#!/usr/bin/python3
"""
Dispatch an email to the right mailbox
"""
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import sys
import re
import shutil
......@@ -62,7 +66,7 @@ class Dispatcher(object):
self._db = psycopg2.connect("service=nm user=nm")
except:
import sqlite3
self._db = sqlite3.connect("db-used-for-development.sqlite")
self._db = sqlite3.connect("data/db-used-for-development.sqlite")
global Q
Q = lambda s: s.replace("%s", "?").replace("true", "1")
return self._db
......@@ -94,15 +98,15 @@ class Dispatcher(object):
reason = "exception %s: %s" % (exc.__class__.__name__, str(exc))
self.msg["NM-Archive-Failsafe-Reason"] = reason
with umask_override(037) as uo:
with umask_override(0o037) as uo:
with open(os.path.join(self.destdir, "failsafe.mbox"), "a") as out:
print >>out, self.msg.as_string(True)
print(self.msg.as_string(True), file=out)
shutil.copyfileobj(sys.stdin, self.infd)
def deliver_to_archive_key(self, arc_key):
with umask_override(037) as uo:
with umask_override(0o037) as uo:
with open(os.path.join(self.destdir, "%s.mbox" % arc_key), "a") as out:
print >>out, self.msg.as_string(True)
print(self.msg.as_string(True), file=out)
shutil.copyfileobj(sys.stdin, self.infd)
def archive_key_from_dest_key(self, dest_key):
......@@ -256,17 +260,17 @@ def main():
msgid = dispatcher.msg.get("message-id", "(no message id)")
try:
for arc_key in dispatcher.get_arc_keys():
print msgid, arc_key
print(msgid, arc_key)
return 0
except Exception, e:
print msgid, "failsafe"
except Exception as e:
print(msgid, "failsafe")
return 1
else:
try:
for arc_key in dispatcher.get_arc_keys():
dispatcher.deliver_to_archive_key(arc_key)
return 0
except Exception, e:
except Exception as e:
dispatcher.deliver_to_failsafe(exc=e)
return 1
......
......@@ -122,7 +122,7 @@ TEMPLATE_DIRS = (
"./", "templates"
)
INSTALLED_APPS = (
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
......@@ -150,7 +150,7 @@ INSTALLED_APPS = (
'minechangelogs',
'api',
'contributors',
)
]
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
"django.core.context_processors.request",
......
# Settings module for test-archive-process-email
# It deletes minechangelogs because it's not needed, and it needs
# python3-xapian which does not exist yet (#647441)
from .settings import *
INSTALLED_APPS.remove("minechangelogs")
#!/usr/bin/python
#!/usr/bin/python3
import sys
# Avoid creating archive-process-emailc
......@@ -9,9 +9,9 @@ import imp
import unittest
import os
import django
from cStringIO import StringIO
import io
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "nm2.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "nm2.settings_tapi")
django.setup()
import backend.models as bmodels
......@@ -53,7 +53,7 @@ class TestLookup(unittest.TestCase):
return res.as_string()
def make_dispatcher(self, **kw):
return Dispatcher(StringIO(self.make_email(**kw)))
return Dispatcher(io.StringIO(self.make_email(**kw)))
def testDestkeyEmail(self):
dest = self.proc.person.email.replace("@", "=")
......
Supports Markdown
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