diff options
author | 2010-08-05 09:53:40 +0300 | |
---|---|---|
committer | 2010-08-05 09:53:40 +0300 | |
commit | 6df173a72b3e3b24a3b16f9eb63329a81ab8a63a (patch) | |
tree | d355988d383d581d81c3604399a49a8c6658a2ab | |
parent | Added tests for pkg devs (diff) | |
download | gsoc2010-grumpy-6df173a72b3e3b24a3b16f9eb63329a81ab8a63a.tar.gz gsoc2010-grumpy-6df173a72b3e3b24a3b16f9eb63329a81ab8a63a.tar.bz2 gsoc2010-grumpy-6df173a72b3e3b24a3b16f9eb63329a81ab8a63a.zip |
Added few convenience utils for version checks
-rw-r--r-- | grumpy/models.py | 12 | ||||
-rw-r--r-- | grumpy/utils.py | 8 |
2 files changed, 17 insertions, 3 deletions
diff --git a/grumpy/models.py b/grumpy/models.py index 4de3b80..e099069 100644 --- a/grumpy/models.py +++ b/grumpy/models.py @@ -9,7 +9,6 @@ :copyright: (c) by 2010 Priit Laes. :license: BSD, see LICENSE for details. """ -from . import app from datetime import datetime from flaskext.sqlalchemy import SQLAlchemy from sqlalchemy.sql import func @@ -17,6 +16,9 @@ from sqlalchemy.orm.collections import column_mapped_collection import json, random, string, time +from . import app +from .utils import compare_version + db = SQLAlchemy(app) # Association tables @@ -175,6 +177,13 @@ class Package(db.Model): def __repr__(self): return '<%s> - %s' % (self.__class__.__name__, self.key) + @property + def versions(self): + """Returns sorted list of versions package has in Portage""" + return sorted(list(set(\ + [e.version for e in self.ebuilds.values()])), \ + compare_version, reverse=True) + def _parse_maintainers(self, ebuild_src): """Update package maintainers.""" devs = [] @@ -244,7 +253,6 @@ class Category(db.Model): def __repr__(self): return '<%s> "%s"' % (self.__class__.__name__, self.name) - class PkgIssue(db.Model): """Package-related issues""" diff --git a/grumpy/utils.py b/grumpy/utils.py index 3fe7506..4891c3d 100644 --- a/grumpy/utils.py +++ b/grumpy/utils.py @@ -7,13 +7,19 @@ :copyright: (c) 2010 Priit Laes """ -from email.mime.text import MIMEText from flask import request, Response from functools import wraps from smtplib import SMTP, SMTPException +from email.mime.text import MIMEText +from pkgcore.ebuild.cpv import native_ver_cmp + from . import app +def compare_version(ver1, ver2): + """Compares two version strings.""" + return native_ver_cmp(ver1, '', ver2, '') + def authenticate(): """Sends a 401 response that enables basic HTTP auth""" return Response('Could not verify your access level for that URL.\n' |