euscan: add --ebuild-uri to use ${PV}, etc.

Signed-off-by: Corentin Chary <corentin.chary@gmail.com>
This commit is contained in:
Corentin Chary 2012-07-20 08:22:52 +02:00
parent c483ac41f1
commit bcda1a7ce3
3 changed files with 41 additions and 9 deletions

View File

@ -128,7 +128,10 @@ def print_usage(_error=None, help=None):
print(yellow(" -I, --ignore-pre-release-if-stable") + print(yellow(" -I, --ignore-pre-release-if-stable") +
" - Ignore non-stable versions only if current\n" + " - Ignore non-stable versions only if current\n" +
" " * 38 + "version is stable", file=out) " " * 38 + "version is stable", file=out)
print(yellow(" --mirror") +
" - use mirror:// URIs", file=out)
print(yellow(" --ebuild-uri") +
" - use ebuild variables in URIs", file=out)
print(file=out) print(file=out)
if _error in ('packages',) or help: if _error in ('packages',) or help:
@ -182,12 +185,14 @@ def parse_args():
pp.output.nocolor() pp.output.nocolor()
elif o in ("-p", "--progress"): elif o in ("-p", "--progress"):
CONFIG['progress'] = isatty CONFIG['progress'] = isatty
elif o in ("-m", "--mirror"): elif o in ("--mirror"):
CONFIG['mirror'] = True CONFIG['mirror'] = True
elif o in ("-i", "--ignore-pre-release"): elif o in ("-i", "--ignore-pre-release"):
CONFIG['ignore-pre-release'] = True CONFIG['ignore-pre-release'] = True
elif o in ("-I", "--ignore-pre-release-if-stable"): elif o in ("-I", "--ignore-pre-release-if-stable"):
CONFIG['ignore-pre-release-if-stable'] = True CONFIG['ignore-pre-release-if-stable'] = True
elif o in ("--ebuild-uri"):
CONFIG['ebuild-uri'] = True
else: else:
return_code = False return_code = False
@ -195,11 +200,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:pmiI" getopt_options['short']['global'] = "hVCqv1bf:piI"
getopt_options['long']['global'] = [ getopt_options['long']['global'] = [
"help", "version", "nocolor", "quiet", "verbose", "oneshot", "help", "version", "nocolor", "quiet", "verbose", "oneshot",
"brute-force=", "format=", "progress", "mirror", "ignore-pre-release", "brute-force=", "format=", "progress", "mirror", "ignore-pre-release",
"ignore-pre-release-if-stable", "ignore-pre-release-if-stable", "ebuild-uri"
] ]
short_opts = getopt_options['short']['global'] short_opts = getopt_options['short']['global']

View File

@ -24,6 +24,7 @@ CONFIG = {
'mirror': False, 'mirror': False,
'ignore-pre-release': False, 'ignore-pre-release': False,
'ignore-pre-release-if-stable': False, 'ignore-pre-release-if-stable': False,
'ebuild-uri': False,
} }
BLACKLIST_VERSIONS = [ BLACKLIST_VERSIONS = [

View File

@ -5,10 +5,9 @@ import signal
import time import time
import re import re
from gentoolkit import pprinter as pp
import portage import portage
from portage.output import EOutput, TermProgressBar from portage.output import EOutput, TermProgressBar
from gentoolkit import pprinter as pp
class ProgressHandler(object): class ProgressHandler(object):
def __init__(self, progress_bar): def __init__(self, progress_bar):
@ -66,6 +65,31 @@ def clean_colors(string):
return string return string
def transform_url(config, cpv, url):
if config['mirror']:
url = to_mirror(url)
if config['ebuild-uri']:
url = to_ebuild_uri(cpv, url)
return url
def to_ebuild_uri(cpv, url):
cat, pkg, ver, rev = portage.catpkgsplit(cpv)
p = '%s-%s' % (pkg, ver)
pvr = '%s%s' % (ver, '-%s' % rev if rev != 'r0' else '')
pf = '%s-%s' % (pkg, pvr)
evars = (
(p , 'P'),
(pkg, 'PN'),
(ver, 'PV'),
(rev, 'PR'),
(pvr, 'PVR'),
(pf , 'PF'),
(cat, 'CATEGORY')
)
for src, dst in evars:
url = url.replace(src, '${%s}' % dst)
return url
def to_mirror(url): def to_mirror(url):
mirrors = portage.settings.thirdpartymirrors() mirrors = portage.settings.thirdpartymirrors()
for mirror_name in mirrors: for mirror_name in mirrors:
@ -148,13 +172,15 @@ class EuscanOutput(object):
def result(self, cp, version, urls, handler, confidence): def result(self, cp, version, urls, handler, confidence):
from euscan.helpers import get_version_type from euscan.helpers import get_version_type
if self.config['format']: cpv = '%s-%s' % (cp, version)
urls = ' '.join(transform_url(self.config, cpv, url) for url in urls.split())
if self.config['format'] in ['json']:
_curr = self.queries[self.current_query] _curr = self.queries[self.current_query]
_curr["result"].append( _curr["result"].append(
{ {
"version": version, "version": version,
"urls": [to_mirror(url) if self.config['mirror'] else url "urls": urls.split(),
for url in urls.split()],
"handler": handler, "handler": handler,
"confidence": confidence, "confidence": confidence,
"type": get_version_type(version) "type": get_version_type(version)