euscan: naive implementation of --mirror
Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
parent
71f71c5b58
commit
6407efa14f
12
bin/euscan
12
bin/euscan
@ -121,10 +121,12 @@ def print_usage(_error=None, help=None):
|
|||||||
" " * 29 + "bigger levels will generate more versions numbers\n" +
|
" " * 29 + "bigger levels will generate more versions numbers\n" +
|
||||||
" " * 29 + "0 means disabled", file=out)
|
" " * 29 + "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") +
|
||||||
|
" - use mirror:// urls", file=out)
|
||||||
print(file=out)
|
print(file=out)
|
||||||
|
|
||||||
if _error in ('packages',) or help:
|
if _error in ('packages',) or help:
|
||||||
@ -178,6 +180,8 @@ 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"):
|
||||||
|
CONFIG['mirror'] = True
|
||||||
else:
|
else:
|
||||||
return_code = False
|
return_code = False
|
||||||
|
|
||||||
@ -185,7 +189,7 @@ 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:p"
|
getopt_options['short']['global'] = "hVCqv1bf:pm"
|
||||||
getopt_options['long']['global'] = [
|
getopt_options['long']['global'] = [
|
||||||
"help", "version", "nocolor", "quiet", "verbose", "oneshot",
|
"help", "version", "nocolor", "quiet", "verbose", "oneshot",
|
||||||
"brute-force=", "format="
|
"brute-force=", "format="
|
||||||
|
@ -20,7 +20,8 @@ CONFIG = {
|
|||||||
'cache': False,
|
'cache': False,
|
||||||
'format': None,
|
'format': None,
|
||||||
'indent': 2,
|
'indent': 2,
|
||||||
'progress': False
|
'progress': False,
|
||||||
|
'mirror': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
BLACKLIST_VERSIONS = [
|
BLACKLIST_VERSIONS = [
|
||||||
|
@ -58,6 +58,28 @@ def progress_bar():
|
|||||||
yield None
|
yield None
|
||||||
|
|
||||||
|
|
||||||
|
def clean_colors(string):
|
||||||
|
if type(string) is str:
|
||||||
|
string = re.sub("\033\[[0-9;]+m", "", string)
|
||||||
|
string = re.sub(r"\\u001b\[[0-9;]+m", "", string)
|
||||||
|
string = re.sub(r"\x1b\[[0-9;]+m", "", string)
|
||||||
|
return string
|
||||||
|
|
||||||
|
|
||||||
|
def to_mirror(url):
|
||||||
|
mirrors = portage.settings.thirdpartymirrors()
|
||||||
|
for mirror_name in mirrors:
|
||||||
|
for mirror_url in mirrors[mirror_name]:
|
||||||
|
if url.startswith(mirror_url):
|
||||||
|
url_part = url.split(mirror_url)[1]
|
||||||
|
return "mirror://%s%s%s" % (
|
||||||
|
mirror_name,
|
||||||
|
"" if url_part.startswith("/") else "/",
|
||||||
|
url_part
|
||||||
|
)
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
class EOutputMem(EOutput):
|
class EOutputMem(EOutput):
|
||||||
"""
|
"""
|
||||||
Override of EOutput, allows to specify an output file for writes
|
Override of EOutput, allows to specify an output file for writes
|
||||||
@ -73,14 +95,6 @@ class EOutputMem(EOutput):
|
|||||||
super(EOutputMem, self)._write(self.out, msg)
|
super(EOutputMem, self)._write(self.out, msg)
|
||||||
|
|
||||||
|
|
||||||
def clean_colors(string):
|
|
||||||
if type(string) is str:
|
|
||||||
string = re.sub("\033\[[0-9;]+m", "", string)
|
|
||||||
string = re.sub(r"\\u001b\[[0-9;]+m", "", string)
|
|
||||||
string = re.sub(r"\x1b\[[0-9;]+m", "", string)
|
|
||||||
return string
|
|
||||||
|
|
||||||
|
|
||||||
class EuscanOutput(object):
|
class EuscanOutput(object):
|
||||||
"""
|
"""
|
||||||
Class that handles output for euscan
|
Class that handles output for euscan
|
||||||
@ -131,14 +145,20 @@ class EuscanOutput(object):
|
|||||||
else:
|
else:
|
||||||
raise TypeError("Invalid output format")
|
raise TypeError("Invalid output format")
|
||||||
|
|
||||||
def result(self, cp, version, url, 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']:
|
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,
|
{
|
||||||
"confidence": confidence, "type": get_version_type(version)}
|
"version": version,
|
||||||
|
"urls": [to_mirror(url) if self.config['mirror'] else url
|
||||||
|
for url in urls.split()],
|
||||||
|
"handler": handler,
|
||||||
|
"confidence": confidence,
|
||||||
|
"type": get_version_type(version)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if not self.config['quiet']:
|
if not self.config['quiet']:
|
||||||
|
Loading…
Reference in New Issue
Block a user