euscan: handlers now use a Package object instead of cpv

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-07-24 08:56:00 +02:00
parent fd12bf1cb4
commit 8e08b6a33b
9 changed files with 52 additions and 52 deletions

View File

@ -14,22 +14,22 @@ handlers = sorted(
)
def find_best_handler(cpv, url):
def find_best_handler(pkg, url):
for handler in handlers:
if handler.can_handle(cpv, url):
if handler.can_handle(pkg, url):
return handler
return None
def scan(cpv, url):
handler = find_best_handler(cpv, url)
def scan(pkg, url):
handler = find_best_handler(pkg, url)
if handler:
return handler.scan(cpv, url)
return handler.scan(pkg, url)
return []
def brute_force(cpv, url):
handler = find_best_handler(cpv, url)
def brute_force(pkg, url):
handler = find_best_handler(pkg, url)
if handler:
return handler.brute_force(cpv, url)
return handler.brute_force(pkg, url)
return []

View File

@ -12,7 +12,7 @@ PRIORITY = 100
_cpan_package_name_re = re.compile("mirror://cpan/authors/.*/([^/.]*).*")
def can_handle(cpv, url):
def can_handle(pkg, url):
return url.startswith('mirror://cpan/')
@ -79,8 +79,8 @@ def cpan_vercmp(cp, a, b):
return 1
def scan(cpv, url):
cp, ver, rev = portage.pkgsplit(cpv)
def scan(pkg, url):
cp, ver, rev = portage.pkgsplit(pkg.cpv)
pkg = guess_package(cp, url)
orig_url = url
@ -133,5 +133,5 @@ def scan(cpv, url):
return ret
def brute_force(cpv, url):
def brute_force(pkg, url):
return []

View File

@ -104,7 +104,7 @@ def scan_directory_recursive(cp, ver, rev, url, steps, orig_url):
return versions
def scan(cpv, url):
def scan(pkg, url):
for bu in SCANDIR_BLACKLIST_URLS:
if re.match(bu, url):
output.einfo("%s is blacklisted by rule %s" % (url, bu))
@ -114,7 +114,7 @@ def scan(cpv, url):
if not resolved_url:
return []
cp, ver, rev = portage.pkgsplit(cpv)
cp, ver, rev = portage.pkgsplit(pkg.cpv)
# 'Hack' for _beta/_rc versions where _ is used instead of -
if ver not in resolved_url:
@ -141,8 +141,8 @@ def scan(cpv, url):
return ret
def brute_force(cpv, url):
cp, ver, rev = portage.pkgsplit(cpv)
def brute_force(pkg, url):
cp, ver, rev = portage.pkgsplit(pkg.cpv)
url = helpers.parse_mirror(url)
if not url:
@ -226,5 +226,5 @@ def brute_force(cpv, url):
return result
def can_handle(cpv, url):
def can_handle(pkg, url):
return True

View File

@ -11,7 +11,7 @@ CONFIDENCE = 100.0
PRIORITY = 100
def can_handle(cpv, url):
def can_handle(pkg, url):
return url.startswith('mirror://github/')
@ -22,13 +22,13 @@ def guess_package(cp, url):
return (match.group(1), match.group(2), match.group(3))
def scan(cpv, url):
def scan(pkg, url):
'http://developer.github.com/v3/repos/downloads/'
user, project, filename = guess_package(cpv, url)
user, project, filename = guess_package(pkg.cpv, url)
# find out where version is expected to be found
cp, ver, rev = portage.pkgsplit(cpv)
cp, ver, rev = portage.pkgsplit(pkg.cpv)
if ver not in filename:
return
@ -54,5 +54,5 @@ def scan(cpv, url):
yield (dl['html_url'], pv, HANDLER_NAME, CONFIDENCE)
def brute_force(cpv, url):
def brute_force(pkg, url):
return []

View File

@ -5,7 +5,7 @@ PRIORITY = 100
HANDLER_NAME = "kde"
def can_handle(cpv, url):
def can_handle(pkg, url):
if url.startswith('mirror://kde/'):
return True
return False
@ -22,21 +22,21 @@ def clean_results(results):
return ret
def scan(cpv, url):
results = generic.scan(cpv, url)
def scan(pkg, url):
results = generic.scan(pkg.cpv, url)
if url.startswith('mirror://kde/unstable/'):
url = url.replace('mirror://kde/unstable/', 'mirror://kde/stable/')
results += generic.scan(cpv, url)
results += generic.scan(pkg.cpv, url)
return clean_results(results)
def brute_force(cpv, url):
results = generic.brute_force(cpv, url)
def brute_force(pkg, url):
results = generic.brute_force(pkg.cpv, url)
if url.startswith('mirror://kde/unstable/'):
url = url.replace('mirror://kde/unstable/', 'mirror://kde/stable/')
results += generic.brute_force(cpv, url)
results += generic.brute_force(pkg.cpv, url)
return clean_results(results)

View File

@ -10,7 +10,7 @@ CONFIDENCE = 100.0
PRIORITY = 100
def can_handle(cpv, url):
def can_handle(pkg, url):
if url.startswith('http://pear.php.net/get/'):
return True
if url.startswith('http://pecl.php.net/get/'):
@ -30,12 +30,12 @@ def guess_package_and_channel(cp, url):
return pkg, host
def scan(cpv, url):
cp, ver, rev = portage.pkgsplit(cpv)
pkg, channel = guess_package_and_channel(cp, url)
def scan(pkg, url):
cp, ver, rev = portage.pkgsplit(pkg.cpv)
package, channel = guess_package_and_channel(cp, url)
orig_url = url
url = 'http://%s/rest/r/%s/allreleases.xml' % (channel, pkg.lower())
url = 'http://%s/rest/r/%s/allreleases.xml' % (channel, package.lower())
output.einfo("Using: " + url)
@ -62,7 +62,7 @@ def scan(cpv, url):
if helpers.version_filtered(cp, ver, pv):
continue
url = 'http://%s/get/%s-%s.tgz' % (channel, pkg, up_pv)
url = 'http://%s/get/%s-%s.tgz' % (channel, package, up_pv)
if url == orig_url:
continue
@ -72,5 +72,5 @@ def scan(cpv, url):
return ret
def brute_force(cpv, url):
def brute_force(pkg, url):
return []

View File

@ -10,7 +10,7 @@ CONFIDENCE = 100.0
PRIORITY = 100
def can_handle(cpv, url):
def can_handle(pkg, url):
return url.startswith('mirror://pypi/')
@ -24,10 +24,10 @@ def guess_package(cp, url):
return pkg
def scan(cpv, url):
def scan(pkg, url):
'http://wiki.python.org/moin/PyPiXmlRpc'
package = guess_package(cpv, url)
package = guess_package(pkg.cpv, url)
output.einfo("Using PyPi XMLRPC: " + package)
@ -39,7 +39,7 @@ def scan(cpv, url):
versions.reverse()
cp, ver, rev = portage.pkgsplit(cpv)
cp, ver, rev = portage.pkgsplit(pkg.cpv)
ret = []
@ -54,5 +54,5 @@ def scan(cpv, url):
return ret
def brute_force(cpv, url):
def brute_force(pkg, url):
return []

View File

@ -10,7 +10,7 @@ CONFIDENCE = 100.0
PRIORITY = 100
def can_handle(cpv, url):
def can_handle(pkg, url):
return url.startswith('mirror://rubygems/')
@ -29,13 +29,13 @@ def guess_gem(cpv, url):
return pkg
def scan(cpv, url):
def scan(pkg, url):
'http://guides.rubygems.org/rubygems-org-api/#gemversion'
gem = guess_gem(cpv, url)
gem = guess_gem(pkg.cpv, url)
if not gem:
output.eerror("Can't guess gem name using %s and %s" % \
(cpv, url))
(pkg.cpv, url))
return []
url = 'http://rubygems.org/api/v1/versions/%s.json' % gem
@ -58,7 +58,7 @@ def scan(cpv, url):
if not versions:
return []
cp, ver, rev = portage.pkgsplit(cpv)
cp, ver, rev = portage.pkgsplit(pkg.cpv)
ret = []
@ -73,5 +73,5 @@ def scan(cpv, url):
return ret
def brute_force(cpv, url):
def brute_force(pkg, url):
return []

View File

@ -44,7 +44,7 @@ def filter_versions(cp, versions):
]
def scan_upstream_urls(cpv, urls, on_progress):
def scan_upstream_urls(pkg, urls, on_progress):
versions = []
if on_progress:
@ -73,7 +73,7 @@ def scan_upstream_urls(cpv, urls, on_progress):
# Try normal scan
if CONFIG["scan-dir"]:
try:
versions.extend(handlers.scan(cpv, url))
versions.extend(handlers.scan(pkg, url))
except Exception as e:
output.ewarn("Handler failed: [%s] %s"
% (e.__class__.__name__, e.message))
@ -83,12 +83,12 @@ def scan_upstream_urls(cpv, urls, on_progress):
# Brute Force
if CONFIG["brute-force"] > 0:
versions.extend(handlers.brute_force(cpv, url))
versions.extend(handlers.brute_force(pkg, url))
if versions and CONFIG['oneshot']:
break
cp, ver, rev = portage.pkgsplit(cpv)
cp, ver, rev = portage.pkgsplit(pkg.cpv)
result = filter_versions(cp, versions)
@ -216,7 +216,7 @@ def scan_upstream(query, on_progress=None):
scan_time = (datetime.now() - start_time).total_seconds()
output.metadata("scan_time", scan_time, show=False)
result = scan_upstream_urls(pkg.cpv, urls, on_progress)
result = scan_upstream_urls(pkg, urls, on_progress)
if on_progress:
on_progress(increment=10)