diff --git a/bin/euscan b/bin/euscan index ade3993..507148a 100755 --- a/bin/euscan +++ b/bin/euscan @@ -102,34 +102,38 @@ def print_usage(_error=None, help=None): if _error in ('global-options',) or help: print("Available ", yellow("options") + ":", file=out) print(yellow(" -C, --nocolor") + - " - turn off colors on output", file=out) + " - turn off colors on output", file=out) print(yellow(" -q, --quiet") + - " - be as quiet as possible", file=out) + " - be as quiet as possible", file=out) print(yellow(" -h, --help") + - " - display the help screen", file=out) + " - display the help screen", file=out) print(yellow(" -V, --version") + - " - display version info", file=out) + " - display version info", file=out) print(file=out) print(yellow(" -1, --oneshot") + - " - stop as soon as a new version is found", + " - stop as soon as a new version is found", file=out) print(yellow(" -b, --brute-force=") + - " - define the brute force " + yellow("") + + " - define the brute force " + yellow("") + " (default: 2)\n" + - " " * 29 + "bigger levels will generate more versions numbers\n" + - " " * 29 + "0 means disabled", file=out) + " " * 38 + "bigger levels will generate more versions numbers\n" + + " " * 38 + "0 means disabled", file=out) print(yellow(" -f, --format=") + - " - define the output " + yellow("") + + " - define the output " + yellow("") + " (available: json)", file=out) print(yellow(" -p, --progress") + - " - display a progress bar", file=out) - print(yellow(" -m, --mirror") + - " - use mirror:// urls", file=out) + " - display a progress bar", file=out) + print(yellow(" -i, --ignore-pre-release") + + " " * 11 + "- Ignore non-stable versions", file=out) + print(yellow(" -I, --ignore-pre-release-if-stable") + + " - Ignore non-stable versions only if current\n" + + " " * 38 + "version is stable", file=out) + print(file=out) if _error in ('packages',) or help: print(green(" package") + - " - the packages (or ebuilds) you want to scan", + " " * 28 + "- the packages (or ebuilds) you want to scan", file=out) print(file=out) @@ -180,6 +184,10 @@ def parse_args(): CONFIG['progress'] = isatty elif o in ("-m", "--mirror"): CONFIG['mirror'] = True + elif o in ("-i", "--ignore-pre-release"): + CONFIG['ignore-pre-release'] = True + elif o in ("-I", "--ignore-pre-release-if-stable"): + CONFIG['ignore-pre-release-if-stable'] = True else: return_code = False @@ -187,10 +195,11 @@ def parse_args(): # here are the different allowed command line options (getopt args) getopt_options = {'short': {}, 'long': {}} - getopt_options['short']['global'] = "hVCqv1bf:pm" + getopt_options['short']['global'] = "hVCqv1bf:pmiI" getopt_options['long']['global'] = [ "help", "version", "nocolor", "quiet", "verbose", "oneshot", - "brute-force=", "format=", "progress" + "brute-force=", "format=", "progress", "mirror", "ignore-pre-release", + "ignore-pre-release-if-stable", ] short_opts = getopt_options['short']['global'] diff --git a/pym/euscan/__init__.py b/pym/euscan/__init__.py index 0f0ed9c..53d51f6 100644 --- a/pym/euscan/__init__.py +++ b/pym/euscan/__init__.py @@ -22,6 +22,8 @@ CONFIG = { 'indent': 2, 'progress': False, 'mirror': False, + 'ignore-pre-release': False, + 'ignore-pre-release-if-stable': False, } BLACKLIST_VERSIONS = [ diff --git a/pym/euscan/helpers.py b/pym/euscan/helpers.py index 5315dd4..eea4382 100644 --- a/pym/euscan/helpers.py +++ b/pym/euscan/helpers.py @@ -34,6 +34,10 @@ _v_end = '((-|_)(pre|p|beta|b|alpha|a|rc|r)\d*)' _v = r'((\d+)((\.\d+)*)([a-zA-Z]*?)(' + _v_end + '*))' +def is_version_stable(version): + return get_version_type(version) not in ("alpha", "beta", "pre", "rc") + + def get_version_type(version): types = [] gentoo_types = ("alpha", "beta", "pre", "rc", "p") diff --git a/pym/euscan/scan.py b/pym/euscan/scan.py index fa573f3..ded800a 100644 --- a/pym/euscan/scan.py +++ b/pym/euscan/scan.py @@ -12,7 +12,8 @@ from gentoolkit.query import Query from gentoolkit.package import Package from euscan import CONFIG, BLACKLIST_PACKAGES -from euscan import handlers, helpers, output +from euscan import handlers, output +from euscan.helpers import version_blacklisted, is_version_stable from euscan.ebuild import package_from_ebuild @@ -26,7 +27,7 @@ def filter_versions(cp, versions): continue # Remove blacklisted versions - if helpers.version_blacklisted(cp, version): + if version_blacklisted(cp, version): continue filtered[version] = { @@ -186,6 +187,10 @@ def scan_upstream(query, on_progress=None): output.metadata("description", pkg.environment("DESCRIPTION")) cpv = pkg.cpv + + _, _, ver, _ = portage.catpkgsplit(cpv) + is_current_version_stable = is_version_stable(ver) + metadata = { "EAPI": portage.settings["EAPI"], "SRC_URI": pkg.environment("SRC_URI", False), @@ -220,6 +225,13 @@ def scan_upstream(query, on_progress=None): print("\n", file=sys.stderr) for cp, url, version, handler, confidence in result: + if CONFIG["ignore-pre-release"]: + if not is_version_stable(version): + continue + if CONFIG["ignore-pre-release-if-stable"]: + if is_current_version_stable and \ + not is_version_stable(version): + continue output.result(cp, version, url, handler, confidence) return result