summaryrefslogtreecommitdiff
path: root/linaro_metrics/parsemail.py
diff options
context:
space:
mode:
Diffstat (limited to 'linaro_metrics/parsemail.py')
-rw-r--r--linaro_metrics/parsemail.py58
1 files changed, 26 insertions, 32 deletions
diff --git a/linaro_metrics/parsemail.py b/linaro_metrics/parsemail.py
index 5c5cd43..18c9065 100644
--- a/linaro_metrics/parsemail.py
+++ b/linaro_metrics/parsemail.py
@@ -9,8 +9,8 @@ from django.conf import settings
from patchwork.models import Patch, Person, Project
from patchwork.parser import parse_patch, subject_check
-from linaro_metrics.crowd import Crowd
-from linaro_metrics.sync_teams import get_or_create_person
+from builtins import str
+unicode = str
log = logging.getLogger('import_emails')
@@ -97,21 +97,17 @@ def find_author_submitter(mail, comment_lines):
return auth, submitter
-def get_linaro_person(crowd, email):
- # the author is linaro
- if crowd.user_valid(email):
- # we need to make sure the "user" exists so that we can apply team
- # credits in _patch_saved_callback
- return get_or_create_person(crowd, email)
+def get_linaro_person(email):
+ p = Person.objects.filter(email=email)
+ if p.count() > 0:
+ pers = p.first()
+ if pers.user and pers.user.is_active is True:
+ return pers
- # the author has linked a non-linaro email to their User
- p = Person.objects.filter(email__iexact=email)
- if p.count() == 1 and p[0].user:
- if crowd.user_valid(p[0].user.email):
- return p[0]
+ return None
-def linaro_parse_mail(crowd, real_parse_mail, mail):
+def linaro_parse_mail(real_parse_mail, mail):
'''Only track patches authored or submitted by "linaro" people. We
determine this by first finding the author's email. Most of the time
this is the simply the "from" address. Occasionally the "from" winds up
@@ -119,7 +115,7 @@ def linaro_parse_mail(crowd, real_parse_mail, mail):
content. Once we have the author email address we check the following
logic:
- * is this author or submitter a valid crowd email?
+ * is this author or submitter a User in patchwork?
* is there a Person in patchwork by this email address?
- if so, is its User part of Linaro? (ie allow tracking of non-linaro
emails
@@ -136,7 +132,8 @@ def linaro_parse_mail(crowd, real_parse_mail, mail):
comment_lines, patch = find_comment_and_patch(mail)
author, submitter = find_author_submitter(mail, comment_lines)
- person = get_linaro_person(crowd, author)
+
+ person = get_linaro_person(author)
if person:
# we have a linaro authored patch
@@ -148,29 +145,26 @@ def linaro_parse_mail(crowd, real_parse_mail, mail):
else:
# see if its a linaro submitter, we'll add the patch but not give
# out team credits
- submitter = get_linaro_person(crowd, submitter)
- if submitter:
+ sub = get_linaro_person(submitter)
+ if sub:
Patch.linaro_author = person
return real_parse_mail(mail)
-
return 0
@contextlib.contextmanager
def monkey_patcher(parser):
- crwd = Crowd(settings.CROWD_USER, settings.CROWD_PASS, settings.CROWD_URL)
def_project, _ = Project.objects.get_or_create(
linkname=settings.DEFAULT_PROJECT)
- with crwd.cached(settings.CROWD_CACHE):
- orig_find = parser.find_project_by_header
- orig_parse = parser.parse_mail
- try:
- parser.find_project_by_header = functools.partial(
- linaro_find_project, orig_find, def_project)
- parser.parse_mail = functools.partial(
- linaro_parse_mail, crwd, orig_parse)
- yield
- finally:
- parser.parse_mail = orig_parse
- parser.find_project_by_header = orig_find
+ orig_find = parser.find_project_by_header
+ orig_parse = parser.parse_mail
+ try:
+ parser.find_project_by_header = functools.partial(
+ linaro_find_project, orig_find, def_project)
+ parser.parse_mail = functools.partial(
+ linaro_parse_mail, orig_parse)
+ yield
+ finally:
+ parser.parse_mail = orig_parse
+ parser.find_project_by_header = orig_find