summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-08-09 05:07:06 +0200
committerDan McGee <dan@archlinux.org>2012-08-09 05:07:06 +0200
commit241ff8fbd79f9f17cd326a34eb39096851f630ba (patch)
treef95a16608c41545b759dce1d6a4303a48374fdf1
parent411ccfb3c74c521969ca6b68459289134976547d (diff)
downloadarchweb-241ff8fbd79f9f17cd326a34eb39096851f630ba.tar.gz
archweb-241ff8fbd79f9f17cd326a34eb39096851f630ba.tar.xz
Extract parse_version function from reporead logic
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--devel/management/commands/reporead.py9
-rw-r--r--packages/utils.py18
2 files changed, 20 insertions, 7 deletions
diff --git a/devel/management/commands/reporead.py b/devel/management/commands/reporead.py
index 8b55b09..af0a2dc 100644
--- a/devel/management/commands/reporead.py
+++ b/devel/management/commands/reporead.py
@@ -34,6 +34,7 @@ from devel.utils import UserFinder
from main.models import Arch, Package, PackageFile, Repo
from main.utils import database_vendor
from packages.models import Depend, Conflict, Provision, Replacement, Update
+from packages.utils import parse_version
logging.basicConfig(
@@ -84,8 +85,6 @@ class RepoPackage(object):
'conflicts', 'provides', 'replaces', 'groups', 'license',
'files' )
- version_re = re.compile(r'^((\d+):)?(.+)-([^-]+)$')
-
def __init__(self, repo):
self.repo = repo
self.ver = None
@@ -112,11 +111,7 @@ class RepoPackage(object):
# do NOT prune these values at all
setattr(self, k, v[0])
elif k == 'version':
- match = self.version_re.match(v[0])
- self.ver = match.group(3)
- self.rel = match.group(4)
- if match.group(2):
- self.epoch = int(match.group(2))
+ self.ver, self.rel, self.epoch = parse_version(v[0])
elif k == 'builddate':
try:
builddate = datetime.utcfromtimestamp(int(v[0]))
diff --git a/packages/utils.py b/packages/utils.py
index 6d54d71..d4b4e61 100644
--- a/packages/utils.py
+++ b/packages/utils.py
@@ -1,6 +1,7 @@
from collections import defaultdict
from itertools import chain
from operator import itemgetter
+import re
from django.core.serializers.json import DjangoJSONEncoder
from django.db import connection
@@ -14,6 +15,23 @@ from .models import (PackageGroup, PackageRelation,
License, Depend, Conflict, Provision, Replacement,
SignoffSpecification, Signoff, DEFAULT_SIGNOFF_SPEC)
+
+VERSION_RE = re.compile(r'^((\d+):)?(.+)-([^-]+)$')
+
+
+def parse_version(version):
+ match = VERSION_RE.match(version)
+ if not match:
+ return None, None, 0
+ ver = match.group(3)
+ rel = match.group(4)
+ if match.group(2):
+ epoch = int(match.group(2))
+ else:
+ epoch = 0
+ return ver, rel, epoch
+
+
@cache_function(127)
def get_group_info(include_arches=None):
raw_groups = PackageGroup.objects.values_list(