summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-06-24 03:11:07 +0200
committerDan McGee <dan@archlinux.org>2011-06-24 03:11:07 +0200
commit82289ebb4432b3372b959430581afa0a2158acb9 (patch)
treeae28c0ff8f9a1d779c913ed641bde4ac084fef38
parent9156003d2d93de57c663901c39ac66316a3d969e (diff)
downloadarchweb-82289ebb4432b3372b959430581afa0a2158acb9.tar.gz
archweb-82289ebb4432b3372b959430581afa0a2158acb9.tar.xz
Add a rematch_packager management command
This allows quick resolution of all unmatched packages, especially after tweaking the way find_user works. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--devel/management/commands/rematch_packager.py64
-rw-r--r--devel/tests.py12
-rw-r--r--devel/utils.py8
3 files changed, 80 insertions, 4 deletions
diff --git a/devel/management/commands/rematch_packager.py b/devel/management/commands/rematch_packager.py
new file mode 100644
index 0000000..ba6e6a5
--- /dev/null
+++ b/devel/management/commands/rematch_packager.py
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+"""
+rematch_packager 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
+"""
+
+from django.core.management.base import NoArgsCommand
+
+import sys
+import logging
+
+from devel.utils import UserFinder
+from main.models import Package
+
+logging.basicConfig(
+ level=logging.INFO,
+ format='%(asctime)s -> %(levelname)s: %(message)s',
+ datefmt='%Y-%m-%d %H:%M:%S',
+ stream=sys.stderr)
+logger = logging.getLogger()
+
+class Command(NoArgsCommand):
+ help = "Runs a check on all active mirror URLs to determine if they are reachable via IPv4 and/or v6."
+
+ def handle_noargs(self, **options):
+ v = int(options.get('verbosity', None))
+ if v == 0:
+ logger.level = logging.ERROR
+ elif v == 1:
+ logger.level = logging.INFO
+ elif v == 2:
+ logger.level = logging.DEBUG
+
+ return match_packager()
+
+def match_packager():
+ finder = UserFinder()
+ logger.info("getting all unmatched packages")
+ package_count = matched_count = 0
+ unknown = set()
+
+ for package in Package.objects.filter(packager__isnull=True):
+ logger.debug("package %s, packager string %s",
+ package.pkgname, package.packager_str)
+ package_count += 1
+ user = finder.find(package.packager_str)
+ if user:
+ package.packager = user
+ logger.debug(" found user %s" % user.username)
+ package.save()
+ matched_count += 1
+ else:
+ unknown.add(package.packager_str)
+
+ logger.info("%d packages checked, %d newly matched",
+ package_count, matched_count)
+ logger.debug("unknown packagers:\n%s",
+ "\n".join(unknown))
+
+# vim: set ts=4 sw=4 et:
diff --git a/devel/tests.py b/devel/tests.py
index c982e50..3669117 100644
--- a/devel/tests.py
+++ b/devel/tests.py
@@ -1,7 +1,7 @@
from django.test import TestCase
from django.contrib.auth.models import User
-from devel.utils import UserFinder
+from devel.utils import UserFinder
from main.models import UserProfile
class DevelTest(TestCase):
@@ -87,6 +87,16 @@ class FindUserTest(TestCase):
self.assertEqual(self.user3,
self.finder.find("Bob Jones <bjones AT Arch Linux DOT org>"))
+ def test_by_invalid(self):
+ self.assertEqual(self.user1,
+ self.finder.find("Joe User <user1@example.com"))
+ self.assertEqual(self.user1,
+ self.finder.find("Joe 'nickname' User <user1@example.com"))
+ self.assertEqual(self.user1,
+ self.finder.find("Joe \"nickname\" User <user1@example.com"))
+ self.assertEqual(self.user1,
+ self.finder.find("Joe User <joe@differentdomain.com"))
+
def test_cache(self):
# simply look two of them up, but then do it repeatedly
for i in range(50):
diff --git a/devel/utils.py b/devel/utils.py
index 3a6ad69..6bc52c8 100644
--- a/devel/utils.py
+++ b/devel/utils.py
@@ -88,10 +88,12 @@ class UserFinder(object):
return None
if userstring in self.cache:
return self.cache[userstring]
- matches = re.match(r'^([^<]+)? ?<([^>]*)>', userstring)
+
+ name = email = None
+
+ matches = re.match(r'^([^<]+)? ?<([^>]*)>?', userstring)
if not matches:
- name = userstring
- email = None
+ name = userstring.strip()
else:
name = matches.group(1)
email = matches.group(2)