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