euscan: detect version type

In the formatted output display the version type (beta, alpha, rc, ...)

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-05-23 23:08:07 +02:00
parent 1efeee4134
commit 9989433ad5
2 changed files with 15 additions and 1 deletions

View File

@ -131,11 +131,13 @@ class EuscanOutput(object):
raise TypeError("Invalid output format") raise TypeError("Invalid output format")
def result(self, cp, version, url, handler, confidence): def result(self, cp, version, url, handler, confidence):
from euscan.helpers import get_version_type
if self.config['format']: if self.config['format']:
_curr = self.queries[self.current_query] _curr = self.queries[self.current_query]
_curr["result"].append( _curr["result"].append(
{"version": version, "urls": [url], "handler": handler, {"version": version, "urls": [url], "handler": handler,
"confidence": confidence} "confidence": confidence, "type": get_version_type(version)}
) )
else: else:
if not self.config['quiet']: if not self.config['quiet']:

View File

@ -42,6 +42,18 @@ _v_end = '((-|_)(pre|p|beta|b|alpha|a|rc|r)\d*)'
_v = r'((\d+)((\.\d+)*)([a-zA-Z]*?)(' + _v_end + '*))' _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 # Stolen from g-pypi
def gentoo_mangle_version(up_pv): def gentoo_mangle_version(up_pv):
"""Convert PV to MY_PV if needed """Convert PV to MY_PV if needed