From 9989433ad5e5b5f33474113ac8e6c0c82448cacd Mon Sep 17 00:00:00 2001 From: volpino Date: Wed, 23 May 2012 23:08:07 +0200 Subject: [PATCH] euscan: detect version type In the formatted output display the version type (beta, alpha, rc, ...) Signed-off-by: volpino --- pym/euscan/__init__.py | 4 +++- pym/euscan/helpers.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pym/euscan/__init__.py b/pym/euscan/__init__.py index 796c56a..bb83dc8 100644 --- a/pym/euscan/__init__.py +++ b/pym/euscan/__init__.py @@ -131,11 +131,13 @@ class EuscanOutput(object): raise TypeError("Invalid output format") def result(self, cp, version, url, handler, confidence): + from euscan.helpers import get_version_type + if self.config['format']: _curr = self.queries[self.current_query] _curr["result"].append( {"version": version, "urls": [url], "handler": handler, - "confidence": confidence} + "confidence": confidence, "type": get_version_type(version)} ) else: if not self.config['quiet']: diff --git a/pym/euscan/helpers.py b/pym/euscan/helpers.py index 3f7b767..c73c45e 100644 --- a/pym/euscan/helpers.py +++ b/pym/euscan/helpers.py @@ -42,6 +42,18 @@ _v_end = '((-|_)(pre|p|beta|b|alpha|a|rc|r)\d*)' _v = r'((\d+)((\.\d+)*)([a-zA-Z]*?)(' + _v_end + '*))' +def get_version_type(version): + types = [] + gentoo_types = ("alpha", "beta", "pre", "rc", "p") + + for token in re.findall("[\._-]([a-zA-Z]+)", version): + if token in gentoo_types: + types.append(token) + if types: + return types[0] + return "release" + + # Stolen from g-pypi def gentoo_mangle_version(up_pv): """Convert PV to MY_PV if needed