summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-02-07 00:46:21 -0600
committerDan McGee <dan@archlinux.org>2012-02-07 00:46:21 -0600
commitf0a858aab6691438eeec9094c2d46d95b5ddb306 (patch)
treec0f3d7d49f58c5a05a5342a54ae62f4e26c2a43d
parentd7d01e3c592a68226edc7dfd435913b0f0781ddd (diff)
Make rematch command do a bit more
Now that we have a few objects that can potentially link back to developers, allow flag requests to also be rematched. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--devel/management/commands/rematch_developers.py (renamed from devel/management/commands/rematch_packager.py)47
-rw-r--r--devel/utils.py21
2 files changed, 61 insertions, 7 deletions
diff --git a/devel/management/commands/rematch_packager.py b/devel/management/commands/rematch_developers.py
index 461d83ab..8383cc8d 100644
--- a/devel/management/commands/rematch_packager.py
+++ b/devel/management/commands/rematch_developers.py
@@ -1,20 +1,25 @@
# -*- coding: utf-8 -*-
"""
-rematch_packager command
+rematch_developers command
Match all packages with a packager_str but NULL packager_id to a packager if we
can find one.
-Usage: ./manage.py rematch_packager
+Also, match all flag requests with a NULL user_id that have a user_email
+matching up to a developer if we can find one.
+
+Usage: ./manage.py rematch_developers
"""
from django.core.management.base import NoArgsCommand
+from django.db import transaction
import sys
import logging
from devel.utils import UserFinder
from main.models import Package
+from packages.models import FlagRequest
logging.basicConfig(
level=logging.INFO,
@@ -24,7 +29,7 @@ logging.basicConfig(
logger = logging.getLogger()
class Command(NoArgsCommand):
- help = "Match all packages with a packager_str but NULL packager_id to a packager if we can find one."
+ help = "Match and map objects in database to developer emails"
def handle_noargs(self, **options):
v = int(options.get('verbosity', None))
@@ -35,15 +40,19 @@ class Command(NoArgsCommand):
elif v == 2:
logger.level = logging.DEBUG
- return match_packager()
+ finder = UserFinder()
+ match_packager(finder)
+ match_flagrequest(finder)
-def match_packager():
- finder = UserFinder()
+@transaction.commit_on_success
+def match_packager(finder):
logger.info("getting all unmatched packages")
package_count = matched_count = 0
unknown = set()
for package in Package.objects.filter(packager__isnull=True):
+ if package.packager_str in unknown:
+ continue
logger.debug("package %s, packager string %s",
package.pkgname, package.packager_str)
package_count += 1
@@ -56,9 +65,33 @@ def match_packager():
else:
unknown.add(package.packager_str)
- logger.info("%d packages checked, %d newly matched",
+ logger.info("%d packager strings checked, %d newly matched",
package_count, matched_count)
logger.debug("unknown packagers:\n%s",
"\n".join(unknown))
+
+@transaction.commit_on_success
+def match_flagrequest(finder):
+ logger.info("getting all non-user flag requests")
+ req_count = matched_count = 0
+ unknown = set()
+
+ for request in FlagRequest.objects.filter(user__isnull=True):
+ if request.user_email in unknown:
+ continue
+ logger.debug("email %s", request.user_email)
+ req_count += 1
+ user = finder.find_by_email(request.user_email)
+ if user:
+ request.user = user
+ logger.debug(" found user %s" % user.username)
+ request.save()
+ matched_count += 1
+ else:
+ unknown.add(request.user_email)
+
+ logger.info("%d request emails checked, %d newly matched",
+ req_count, matched_count)
+
# vim: set ts=4 sw=4 et:
diff --git a/devel/utils.py b/devel/utils.py
index 62b12cd5..ec035d13 100644
--- a/devel/utils.py
+++ b/devel/utils.py
@@ -48,6 +48,7 @@ class UserFinder(object):
def __init__(self):
self.cache = {}
self.username_cache = {}
+ self.email_cache = {}
@staticmethod
def user_email(name, email):
@@ -110,6 +111,7 @@ class UserFinder(object):
pass
self.cache[userstring] = user
+ self.email_cache[email] = user
return user
def find_by_username(self, username):
@@ -126,8 +128,27 @@ class UserFinder(object):
self.username_cache[username] = user
return user
+ def find_by_email(self, email):
+ if not email:
+ return None
+ if email in self.email_cache:
+ return self.email_cache[email]
+
+ user = None
+ try:
+ user = self.user_email(None, email)
+ except User.DoesNotExist:
+ try:
+ user = self.profile_email(None, email)
+ except User.DoesNotExist:
+ pass
+
+ self.email_cache[email] = user
+ return user
+
def clear_cache(self):
self.cache = {}
self.username_cache = {}
+ self.email_cache = {}
# vim: set ts=4 sw=4 et: