euscan: added --ignore-pre-release and --ignore-pre-release-if-stable

options

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-07-17 12:27:22 +02:00
parent c4577c5279
commit 33a06d99fb
4 changed files with 44 additions and 17 deletions

View File

@ -102,34 +102,38 @@ def print_usage(_error=None, help=None):
if _error in ('global-options',) or help: if _error in ('global-options',) or help:
print("Available ", yellow("options") + ":", file=out) print("Available ", yellow("options") + ":", file=out)
print(yellow(" -C, --nocolor") + print(yellow(" -C, --nocolor") +
" - turn off colors on output", file=out) " - turn off colors on output", file=out)
print(yellow(" -q, --quiet") + print(yellow(" -q, --quiet") +
" - be as quiet as possible", file=out) " - be as quiet as possible", file=out)
print(yellow(" -h, --help") + print(yellow(" -h, --help") +
" - display the help screen", file=out) " - display the help screen", file=out)
print(yellow(" -V, --version") + print(yellow(" -V, --version") +
" - display version info", file=out) " - display version info", file=out)
print(file=out) print(file=out)
print(yellow(" -1, --oneshot") + print(yellow(" -1, --oneshot") +
" - stop as soon as a new version is found", " - stop as soon as a new version is found",
file=out) file=out)
print(yellow(" -b, --brute-force=<level>") + print(yellow(" -b, --brute-force=<level>") +
" - define the brute force " + yellow("<level>") + " - define the brute force " + yellow("<level>") +
" (default: 2)\n" + " (default: 2)\n" +
" " * 29 + "bigger levels will generate more versions numbers\n" + " " * 38 + "bigger levels will generate more versions numbers\n" +
" " * 29 + "0 means disabled", file=out) " " * 38 + "0 means disabled", file=out)
print(yellow(" -f, --format=<format>") + print(yellow(" -f, --format=<format>") +
" - define the output " + yellow("<format>") + " - define the output " + yellow("<format>") +
" (available: json)", file=out) " (available: json)", file=out)
print(yellow(" -p, --progress") + print(yellow(" -p, --progress") +
" - display a progress bar", file=out) " - display a progress bar", file=out)
print(yellow(" -m, --mirror") + print(yellow(" -i, --ignore-pre-release") +
" - use mirror:// urls", file=out) " " * 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) print(file=out)
if _error in ('packages',) or help: if _error in ('packages',) or help:
print(green(" package") + print(green(" package") +
" - the packages (or ebuilds) you want to scan", " " * 28 + "- the packages (or ebuilds) you want to scan",
file=out) file=out)
print(file=out) print(file=out)
@ -180,6 +184,10 @@ def parse_args():
CONFIG['progress'] = isatty CONFIG['progress'] = isatty
elif o in ("-m", "--mirror"): elif o in ("-m", "--mirror"):
CONFIG['mirror'] = True 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: else:
return_code = False return_code = False
@ -187,10 +195,11 @@ def parse_args():
# here are the different allowed command line options (getopt args) # here are the different allowed command line options (getopt args)
getopt_options = {'short': {}, 'long': {}} getopt_options = {'short': {}, 'long': {}}
getopt_options['short']['global'] = "hVCqv1bf:pm" getopt_options['short']['global'] = "hVCqv1bf:pmiI"
getopt_options['long']['global'] = [ getopt_options['long']['global'] = [
"help", "version", "nocolor", "quiet", "verbose", "oneshot", "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'] short_opts = getopt_options['short']['global']

View File

@ -22,6 +22,8 @@ CONFIG = {
'indent': 2, 'indent': 2,
'progress': False, 'progress': False,
'mirror': False, 'mirror': False,
'ignore-pre-release': False,
'ignore-pre-release-if-stable': False,
} }
BLACKLIST_VERSIONS = [ BLACKLIST_VERSIONS = [

View File

@ -34,6 +34,10 @@ _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 is_version_stable(version):
return get_version_type(version) not in ("alpha", "beta", "pre", "rc")
def get_version_type(version): def get_version_type(version):
types = [] types = []
gentoo_types = ("alpha", "beta", "pre", "rc", "p") gentoo_types = ("alpha", "beta", "pre", "rc", "p")

View File

@ -12,7 +12,8 @@ from gentoolkit.query import Query
from gentoolkit.package import Package from gentoolkit.package import Package
from euscan import CONFIG, BLACKLIST_PACKAGES 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 from euscan.ebuild import package_from_ebuild
@ -26,7 +27,7 @@ def filter_versions(cp, versions):
continue continue
# Remove blacklisted versions # Remove blacklisted versions
if helpers.version_blacklisted(cp, version): if version_blacklisted(cp, version):
continue continue
filtered[version] = { filtered[version] = {
@ -186,6 +187,10 @@ def scan_upstream(query, on_progress=None):
output.metadata("description", pkg.environment("DESCRIPTION")) output.metadata("description", pkg.environment("DESCRIPTION"))
cpv = pkg.cpv cpv = pkg.cpv
_, _, ver, _ = portage.catpkgsplit(cpv)
is_current_version_stable = is_version_stable(ver)
metadata = { metadata = {
"EAPI": portage.settings["EAPI"], "EAPI": portage.settings["EAPI"],
"SRC_URI": pkg.environment("SRC_URI", False), "SRC_URI": pkg.environment("SRC_URI", False),
@ -220,6 +225,13 @@ def scan_upstream(query, on_progress=None):
print("\n", file=sys.stderr) print("\n", file=sys.stderr)
for cp, url, version, handler, confidence in result: 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) output.result(cp, version, url, handler, confidence)
return result return result