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
|
|
|
|
from portage.dbapi import porttree
|
|
|
|
|
|
|
|
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-05-23 16:30:43 +02:00
|
|
|
from euscan import handlers, helpers, output
|
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
|
2011-08-31 15:38:32 +02:00
|
|
|
if helpers.version_blacklisted(cp, version):
|
|
|
|
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
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-05-27 10:09:39 +02:00
|
|
|
def scan_upstream_urls(cpv, urls, on_progress):
|
2011-08-31 15:38:32 +02:00
|
|
|
versions = []
|
|
|
|
|
2012-05-27 10:09:39 +02:00
|
|
|
maxval = len(urls) + 5
|
|
|
|
curval = 1
|
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
for filename in urls:
|
2012-05-27 10:09:39 +02:00
|
|
|
curval += 1
|
|
|
|
if on_progress:
|
|
|
|
on_progress(maxval, curval)
|
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
for url in urls[filename]:
|
2012-05-21 22:24:44 +02:00
|
|
|
if not CONFIG['quiet'] and not CONFIG['format']:
|
2011-12-11 14:32:38 +01:00
|
|
|
pp.uprint()
|
2012-05-23 16:30:43 +02:00
|
|
|
output.einfo("SRC_URI is '%s'" % url)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
if '://' not in url:
|
2012-05-23 16:30:43 +02:00
|
|
|
output.einfo("Invalid url '%s'" % url)
|
2011-08-31 15:38:32 +02:00
|
|
|
continue
|
|
|
|
|
2012-05-23 16:30:43 +02:00
|
|
|
# Try normal scan
|
2011-08-31 15:38:32 +02:00
|
|
|
if CONFIG["scan-dir"]:
|
2012-06-14 12:38:52 +02:00
|
|
|
try:
|
|
|
|
versions.extend(handlers.scan(cpv, url))
|
|
|
|
except Exception as e:
|
|
|
|
output.ewarn("Handler failed: [%s] %s"
|
|
|
|
% (e.__class__.__name__, e.message))
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
if versions and CONFIG['oneshot']:
|
|
|
|
break
|
|
|
|
|
2012-05-23 16:30:43 +02:00
|
|
|
# Brute Force
|
2011-08-31 15:38:32 +02:00
|
|
|
if CONFIG["brute-force"] > 0:
|
|
|
|
versions.extend(handlers.brute_force(cpv, url))
|
|
|
|
|
|
|
|
if versions and CONFIG['oneshot']:
|
|
|
|
break
|
|
|
|
|
|
|
|
cp, ver, rev = portage.pkgsplit(cpv)
|
2012-05-27 10:09:39 +02:00
|
|
|
|
|
|
|
curval += 1
|
|
|
|
if on_progress:
|
|
|
|
on_progress(maxval, curval)
|
|
|
|
|
|
|
|
result = filter_versions(cp, versions)
|
|
|
|
|
|
|
|
curval += 1
|
|
|
|
if on_progress:
|
|
|
|
on_progress(maxval, curval)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-05-24 23:44:05 +02:00
|
|
|
# gentoolkit stores PORTDB, so even if we modify it to add an overlay
|
|
|
|
# it will still use the old dbapi
|
|
|
|
def reload_gentoolkit():
|
2012-05-28 07:02:41 +02:00
|
|
|
from gentoolkit import dbapi
|
2012-05-24 23:44:05 +02:00
|
|
|
import gentoolkit.package
|
|
|
|
import gentoolkit.query
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-05-24 23:44:05 +02:00
|
|
|
PORTDB = portage.db[portage.root]["porttree"].dbapi
|
2012-05-28 07:02:41 +02:00
|
|
|
dbapi.PORTDB = PORTDB
|
|
|
|
|
|
|
|
if hasattr(dbapi, 'PORTDB'):
|
|
|
|
dbapi.PORTDB = PORTDB
|
2012-05-24 23:44:05 +02:00
|
|
|
if hasattr(gentoolkit.package, 'PORTDB'):
|
|
|
|
gentoolkit.package.PORTDB = PORTDB
|
|
|
|
if hasattr(gentoolkit.query, 'PORTDB'):
|
|
|
|
gentoolkit.query.PORTDB = PORTDB
|
2012-05-05 14:28:48 +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
|
|
|
|
"""
|
|
|
|
|
|
|
|
maxval = 3
|
|
|
|
curval = 0
|
|
|
|
|
2012-05-24 23:44:05 +02:00
|
|
|
matches = []
|
|
|
|
|
|
|
|
if query.endswith(".ebuild"):
|
|
|
|
cpv = package_from_ebuild(query)
|
|
|
|
if cpv:
|
|
|
|
reload_gentoolkit()
|
|
|
|
matches = [Package(cpv)]
|
|
|
|
else:
|
|
|
|
matches = Query(query).find(
|
|
|
|
include_masked=True,
|
|
|
|
in_installed=False
|
|
|
|
)
|
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
|
|
|
curval += 1
|
|
|
|
if on_progress:
|
|
|
|
on_progress(maxval, curval)
|
|
|
|
|
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-05-23 16:30:43 +02:00
|
|
|
output.metadata("repository", pkg.repo_name())
|
|
|
|
output.metadata("homepage", pkg.environment("HOMEPAGE"))
|
|
|
|
output.metadata("description", pkg.environment("DESCRIPTION"))
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2011-12-11 14:32:38 +01:00
|
|
|
cpv = pkg.cpv
|
|
|
|
metadata = {
|
2012-05-28 07:02:41 +02:00
|
|
|
"EAPI": portage.settings["EAPI"],
|
2012-04-28 18:16:05 +02:00
|
|
|
"SRC_URI": pkg.environment("SRC_URI", False),
|
2011-12-11 14:32:38 +01:00
|
|
|
}
|
2012-05-28 07:02:41 +02:00
|
|
|
use = frozenset(portage.settings["PORTAGE_USE"].split())
|
2011-12-11 14:32:38 +01:00
|
|
|
try:
|
|
|
|
alist = porttree._parse_uri_map(cpv, metadata, use=use)
|
|
|
|
aalist = porttree._parse_uri_map(cpv, metadata)
|
|
|
|
except Exception as e:
|
2012-05-23 16:30:43 +02:00
|
|
|
output.ewarn(pp.warn("%s\n" % str(e)))
|
|
|
|
output.ewarn(
|
2012-04-28 18:16:05 +02:00
|
|
|
pp.warn("Invalid SRC_URI for '%s'" % pp.pkgquery(cpv))
|
|
|
|
)
|
2012-05-23 16:30:43 +02:00
|
|
|
return None
|
2011-12-11 14:32:38 +01:00
|
|
|
|
|
|
|
if "mirror" in portage.settings.features:
|
|
|
|
urls = aalist
|
|
|
|
else:
|
|
|
|
urls = alist
|
|
|
|
|
2012-05-24 20:27:18 +02:00
|
|
|
# output scan time for formatted output
|
|
|
|
scan_time = (datetime.now() - start_time).total_seconds()
|
|
|
|
output.metadata("scan_time", scan_time, show=False)
|
|
|
|
|
2012-05-27 10:09:39 +02:00
|
|
|
curval += 1
|
|
|
|
if on_progress:
|
|
|
|
on_progress(maxval, curval)
|
|
|
|
|
|
|
|
result = scan_upstream_urls(pkg.cpv, urls, on_progress)
|
|
|
|
|
|
|
|
curval += 1
|
|
|
|
if on_progress:
|
|
|
|
on_progress(maxval, curval)
|
|
|
|
|
2012-06-08 14:43:18 +02:00
|
|
|
if len(result) > 0:
|
|
|
|
if not (CONFIG['format'] or CONFIG['quiet']):
|
|
|
|
print("\n", file=sys.stderr)
|
|
|
|
|
|
|
|
for cp, url, version, handler, confidence in result:
|
|
|
|
output.result(cp, version, url, handler, confidence)
|
|
|
|
|
2012-05-27 10:09:39 +02:00
|
|
|
return result
|