2012-06-08 14:43:18 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
import os
|
2012-06-08 14:43:18 +02:00
|
|
|
import sys
|
2012-05-23 16:30:43 +02:00
|
|
|
from datetime import datetime
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
import portage
|
|
|
|
|
|
|
|
import gentoolkit.pprinter as pp
|
|
|
|
from gentoolkit.query import Query
|
2012-05-24 23:44:05 +02:00
|
|
|
from gentoolkit.package import Package
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2011-12-11 14:32:38 +01:00
|
|
|
from euscan import CONFIG, BLACKLIST_PACKAGES
|
2012-07-17 12:27:22 +02:00
|
|
|
from euscan import handlers, output
|
2012-08-06 23:30:29 +02:00
|
|
|
from euscan.out import from_mirror
|
2012-07-20 09:06:22 +02:00
|
|
|
from euscan.helpers import version_blacklisted
|
2012-07-20 09:04:15 +02:00
|
|
|
from euscan.version import is_version_stable
|
2012-05-24 23:44:05 +02:00
|
|
|
from euscan.ebuild import package_from_ebuild
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2011-12-11 14:32:38 +01:00
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
def filter_versions(cp, versions):
|
|
|
|
filtered = {}
|
|
|
|
|
2012-05-23 16:44:44 +02:00
|
|
|
for url, version, handler, confidence in versions:
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-05-23 16:30:43 +02:00
|
|
|
# Try to keep the most specific urls (determinted by the length)
|
2011-08-31 15:38:32 +02:00
|
|
|
if version in filtered and len(url) < len(filtered[version]):
|
|
|
|
continue
|
|
|
|
|
2012-05-23 16:30:43 +02:00
|
|
|
# Remove blacklisted versions
|
2012-07-17 12:27:22 +02:00
|
|
|
if version_blacklisted(cp, version):
|
2011-08-31 15:38:32 +02:00
|
|
|
continue
|
|
|
|
|
2012-05-23 16:44:44 +02:00
|
|
|
filtered[version] = {
|
|
|
|
"url": url,
|
|
|
|
"handler": handler,
|
|
|
|
"confidence": confidence
|
|
|
|
}
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-05-23 16:30:43 +02:00
|
|
|
return [
|
2012-05-23 16:44:44 +02:00
|
|
|
(cp, filtered[version]["url"], version, filtered[version]["handler"],
|
|
|
|
filtered[version]["confidence"])
|
2012-05-23 16:30:43 +02:00
|
|
|
for version in filtered
|
|
|
|
]
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2012-08-07 09:39:49 +02:00
|
|
|
|
2012-08-06 23:30:29 +02:00
|
|
|
def parse_src_uri(uris):
|
|
|
|
ret = {}
|
|
|
|
|
|
|
|
uris = uris.split()
|
|
|
|
uris.reverse()
|
|
|
|
while uris:
|
|
|
|
uri = uris.pop()
|
|
|
|
|
|
|
|
if '://' not in uri:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if uris and uris[-1] == "->":
|
|
|
|
operator = uris.pop()
|
2012-08-07 09:39:49 +02:00
|
|
|
file_ = uris.pop()
|
2012-08-06 23:30:29 +02:00
|
|
|
else:
|
2012-08-07 09:39:49 +02:00
|
|
|
file_ = os.path.basename(uri)
|
2012-08-06 23:30:29 +02:00
|
|
|
|
2012-08-07 09:39:49 +02:00
|
|
|
if file_ not in ret:
|
|
|
|
ret[file_] = []
|
2012-08-06 23:30:29 +02:00
|
|
|
|
2012-08-07 09:39:49 +02:00
|
|
|
ret[file_].append(uri)
|
2012-08-06 23:30:29 +02:00
|
|
|
|
|
|
|
return ret
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-08-07 09:39:49 +02:00
|
|
|
|
2012-08-07 08:43:23 +02:00
|
|
|
def reload_gentoolkit():
|
|
|
|
import gentoolkit
|
|
|
|
|
|
|
|
# Not used in recent versions
|
|
|
|
if not hasattr(gentoolkit.package, 'PORTDB'):
|
|
|
|
return
|
|
|
|
|
|
|
|
PORTDB = portage.db[portage.root]["porttree"].dbapi
|
|
|
|
|
|
|
|
if hasattr(gentoolkit.dbapi, 'PORTDB'):
|
|
|
|
gentoolkit.dbapi.PORTDB = PORTDB
|
|
|
|
if hasattr(gentoolkit.package, 'PORTDB'):
|
|
|
|
gentoolkit.package.PORTDB = PORTDB
|
|
|
|
if hasattr(gentoolkit.query, 'PORTDB'):
|
|
|
|
gentoolkit.query.PORTDB = PORTDB
|
|
|
|
|
2012-08-07 09:39:49 +02:00
|
|
|
|
2012-05-27 10:09:39 +02:00
|
|
|
def scan_upstream(query, on_progress=None):
|
|
|
|
"""
|
|
|
|
Scans the upstream searching new versions for the given query
|
|
|
|
"""
|
2012-05-24 23:44:05 +02:00
|
|
|
matches = []
|
|
|
|
|
|
|
|
if query.endswith(".ebuild"):
|
|
|
|
cpv = package_from_ebuild(query)
|
2012-08-07 08:43:23 +02:00
|
|
|
reload_gentoolkit()
|
2012-05-24 23:44:05 +02:00
|
|
|
if cpv:
|
|
|
|
matches = [Package(cpv)]
|
|
|
|
else:
|
|
|
|
matches = Query(query).find(
|
|
|
|
include_masked=True,
|
2012-08-15 11:04:29 +02:00
|
|
|
in_installed=False,
|
2012-05-24 23:44:05 +02:00
|
|
|
)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2011-12-11 14:32:38 +01:00
|
|
|
if not matches:
|
2012-05-23 16:30:43 +02:00
|
|
|
output.ewarn(
|
2012-04-28 18:16:05 +02:00
|
|
|
pp.warn("No package matching '%s'" % pp.pkgquery(query))
|
|
|
|
)
|
2012-05-23 16:30:43 +02:00
|
|
|
return None
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2011-12-11 14:32:38 +01:00
|
|
|
matches = sorted(matches)
|
|
|
|
pkg = matches.pop()
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2011-12-11 14:32:38 +01:00
|
|
|
while '9999' in pkg.version and len(matches):
|
|
|
|
pkg = matches.pop()
|
2011-10-08 08:33:25 +02:00
|
|
|
|
2011-12-11 14:32:38 +01:00
|
|
|
if not pkg:
|
2012-05-23 16:30:43 +02:00
|
|
|
output.ewarn(
|
|
|
|
pp.warn("Package '%s' only have a dev version (9999)"
|
|
|
|
% pp.pkgquery(pkg.cp))
|
|
|
|
)
|
|
|
|
return None
|
|
|
|
|
|
|
|
# useful data only for formatted output
|
2012-05-24 20:27:18 +02:00
|
|
|
start_time = datetime.now()
|
|
|
|
output.metadata("datetime", start_time.isoformat(), show=False)
|
2012-05-23 16:30:43 +02:00
|
|
|
output.metadata("cp", pkg.cp, show=False)
|
|
|
|
output.metadata("cpv", pkg.cpv, show=False)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-05-27 10:09:39 +02:00
|
|
|
if on_progress:
|
2012-06-28 12:20:57 +02:00
|
|
|
on_progress(increment=10)
|
2012-05-27 10:09:39 +02:00
|
|
|
|
2011-12-11 14:32:38 +01:00
|
|
|
if pkg.cp in BLACKLIST_PACKAGES:
|
2012-05-23 16:30:43 +02:00
|
|
|
output.ewarn(
|
2012-04-28 18:16:05 +02:00
|
|
|
pp.warn("Package '%s' is blacklisted" % pp.pkgquery(pkg.cp))
|
|
|
|
)
|
2012-05-23 16:30:43 +02:00
|
|
|
return None
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2011-12-11 14:32:38 +01:00
|
|
|
if not CONFIG['quiet']:
|
2012-05-23 16:30:43 +02:00
|
|
|
if not CONFIG['format']:
|
|
|
|
pp.uprint(
|
|
|
|
" * %s [%s]" % (pp.cpv(pkg.cpv), pp.section(pkg.repo_name()))
|
|
|
|
)
|
|
|
|
pp.uprint()
|
|
|
|
else:
|
|
|
|
output.metadata("overlay", pp.section(pkg.repo_name()))
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
ebuild_path = pkg.ebuild_path()
|
|
|
|
if ebuild_path:
|
2012-05-23 16:30:43 +02:00
|
|
|
output.metadata(
|
|
|
|
"ebuild", pp.path(os.path.normpath(ebuild_path))
|
|
|
|
)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-08-07 09:39:49 +02:00
|
|
|
uris, homepage, description = pkg.environment(
|
|
|
|
('SRC_URI', 'HOMEPAGE', 'DESCRIPTION')
|
|
|
|
)
|
2012-08-06 23:30:29 +02:00
|
|
|
|
2012-05-23 16:30:43 +02:00
|
|
|
output.metadata("repository", pkg.repo_name())
|
2012-08-06 23:30:29 +02:00
|
|
|
output.metadata("homepage", homepage)
|
|
|
|
output.metadata("description", description)
|
|
|
|
else:
|
|
|
|
uris = pkg.environment('SRC_URI')
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2011-12-11 14:32:38 +01:00
|
|
|
cpv = pkg.cpv
|
|
|
|
|
2012-08-15 11:04:29 +02:00
|
|
|
uris = parse_src_uri(uris)
|
|
|
|
uris_expanded = [ from_mirror(uri) if 'mirror://' in uri else uri for uri in uris ]
|
|
|
|
pkg._uris = uris
|
|
|
|
pkg._uris_expanded = uris_expanded
|
|
|
|
|
|
|
|
versions = handlers.scan(pkg, uris, on_progress)
|
2012-05-24 20:27:18 +02:00
|
|
|
|
2012-07-26 10:44:10 +02:00
|
|
|
cp, ver, rev = portage.pkgsplit(pkg.cpv)
|
|
|
|
|
|
|
|
result = filter_versions(cp, versions)
|
2012-05-27 10:09:39 +02:00
|
|
|
|
|
|
|
if on_progress:
|
2012-06-28 12:20:57 +02:00
|
|
|
on_progress(increment=10)
|
2012-05-27 10:09:39 +02:00
|
|
|
|
2012-07-26 10:44:10 +02:00
|
|
|
# output scan time for formatted output
|
|
|
|
scan_time = (datetime.now() - start_time).total_seconds()
|
|
|
|
output.metadata("scan_time", scan_time, show=False)
|
|
|
|
|
|
|
|
is_current_version_stable = is_version_stable(ver)
|
2012-06-08 14:43:18 +02:00
|
|
|
if len(result) > 0:
|
|
|
|
if not (CONFIG['format'] or CONFIG['quiet']):
|
2012-07-26 21:31:10 +02:00
|
|
|
print("")
|
2012-06-08 14:43:18 +02:00
|
|
|
for cp, url, version, handler, confidence in result:
|
2012-07-17 12:27:22 +02:00
|
|
|
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
|
2012-07-26 21:31:10 +02:00
|
|
|
if CONFIG['progress']:
|
2012-07-27 11:33:27 +02:00
|
|
|
print("", file=sys.stderr)
|
2012-06-08 14:43:18 +02:00
|
|
|
output.result(cp, version, url, handler, confidence)
|
|
|
|
|
2012-05-27 10:09:39 +02:00
|
|
|
return result
|