euscan: optimize SRC_URI fetching

Signed-off-by: Corentin Chary <corentin.chary@gmail.com>
This commit is contained in:
Corentin Chary 2012-08-06 23:30:29 +02:00
parent f37b9a7740
commit f6e2882b44
2 changed files with 53 additions and 23 deletions

View File

@ -10,6 +10,7 @@ import portage
from portage.output import EOutput, TermProgressBar from portage.output import EOutput, TermProgressBar
from gentoolkit import pprinter as pp from gentoolkit import pprinter as pp
mirrors_ = None
class ProgressHandler(object): class ProgressHandler(object):
def __init__(self, progress_bar): def __init__(self, progress_bar):
@ -96,10 +97,27 @@ def to_ebuild_uri(cpv, url):
url = url.replace(src, '${%s}' % dst) url = url.replace(src, '${%s}' % dst)
return url return url
def from_mirror(url):
if not url.startswith('mirror://'):
return url
global mirrors_
if mirrors_ is None:
mirrors_ = portage.settings.thirdpartymirrors()
for mirror_name in mirrors_:
prefix = 'mirror://' + mirror_name
if url.startswith(prefix):
return url.replace(prefix, mirrors_[mirror_name][0])
return url
def to_mirror(url): def to_mirror(url):
mirrors = portage.settings.thirdpartymirrors() global mirrors_
for mirror_name in mirrors: if mirrors_ is None:
mirrors_ = portage.settings.thirdpartymirrors()
for mirror_name in mirrors_:
for mirror_url in mirrors[mirror_name]: for mirror_url in mirrors[mirror_name]:
if url.startswith(mirror_url): if url.startswith(mirror_url):
url_part = url.split(mirror_url)[1] url_part = url.split(mirror_url)[1]

View File

@ -13,6 +13,7 @@ from gentoolkit.package import Package
from euscan import CONFIG, BLACKLIST_PACKAGES from euscan import CONFIG, BLACKLIST_PACKAGES
from euscan import handlers, output from euscan import handlers, output
from euscan.out import from_mirror
from euscan.helpers import version_blacklisted from euscan.helpers import version_blacklisted
from euscan.version import is_version_stable from euscan.version import is_version_stable
from euscan.ebuild import package_from_ebuild from euscan.ebuild import package_from_ebuild
@ -43,6 +44,31 @@ def filter_versions(cp, versions):
for version in filtered for version in filtered
] ]
def parse_src_uri(uris):
ret = {}
uris = uris.split()
uris.reverse()
while uris:
uri = uris.pop()
if '://' not in uri:
continue
if 'mirror://' in uri:
uri = from_mirror(uri)
if uris and uris[-1] == "->":
operator = uris.pop()
file = uris.pop()
else:
file = os.path.basename(uri)
if file not in ret:
ret[file] = []
ret[file].append(uri)
return ret
def scan_upstream(query, on_progress=None): def scan_upstream(query, on_progress=None):
""" """
@ -110,30 +136,16 @@ def scan_upstream(query, on_progress=None):
"ebuild", pp.path(os.path.normpath(ebuild_path)) "ebuild", pp.path(os.path.normpath(ebuild_path))
) )
uris, homepage, description = pkg.environment(('SRC_URI', 'HOMEPAGE', 'DESCRIPTION'))
output.metadata("repository", pkg.repo_name()) output.metadata("repository", pkg.repo_name())
output.metadata("homepage", pkg.environment("HOMEPAGE")) output.metadata("homepage", homepage)
output.metadata("description", pkg.environment("DESCRIPTION")) output.metadata("description", description)
else:
uris = pkg.environment('SRC_URI')
cpv = pkg.cpv cpv = pkg.cpv
metadata = { urls = parse_src_uri(uris)
"EAPI": portage.settings["EAPI"],
"SRC_URI": pkg.environment("SRC_URI", False),
}
use = frozenset(portage.settings["PORTAGE_USE"].split())
try:
alist = porttree._parse_uri_map(cpv, metadata, use=use)
aalist = porttree._parse_uri_map(cpv, metadata)
except Exception as e:
output.ewarn(pp.warn("%s\n" % str(e)))
output.ewarn(
pp.warn("Invalid SRC_URI for '%s'" % pp.pkgquery(cpv))
)
return None
if "mirror" in portage.settings.features:
urls = aalist
else:
urls = alist
versions = handlers.scan(pkg, urls, on_progress) versions = handlers.scan(pkg, urls, on_progress)