euscan: Adding support for disabling handlers

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-09-14 11:33:57 +02:00
parent 80ca711565
commit 14854dbadd
4 changed files with 16 additions and 6 deletions

1
TODO
View File

@ -9,7 +9,6 @@ euscan
- Check other distros (youri, distrowatch, distromatch, whoas; Equivalent-Packages) - Check other distros (youri, distrowatch, distromatch, whoas; Equivalent-Packages)
- Steal ideas from other tools (uscan, portscout) - Steal ideas from other tools (uscan, portscout)
- Steal data from other tools (dehs) - Steal data from other tools (dehs)
- Add a way to enable/disable handlers (--no-handler-kde --no-handler-sourceforge)
### Command line interface ### Command line interface

View File

@ -133,6 +133,9 @@ def print_usage(_error=None, help=None):
" - use mirror:// URIs", file=out) " - use mirror:// URIs", file=out)
print(yellow(" --ebuild-uri") + print(yellow(" --ebuild-uri") +
" - use ebuild variables in URIs", file=out) " - use ebuild variables in URIs", file=out)
print(yellow(" --no-handlers") +
" - exclude handlers (comma-separated list)",
file=out)
print(file=out) print(file=out)
if _error in ('packages',) or help: if _error in ('packages',) or help:
@ -194,6 +197,8 @@ def parse_args():
CONFIG['ignore-pre-release-if-stable'] = True CONFIG['ignore-pre-release-if-stable'] = True
elif o in ("--ebuild-uri"): elif o in ("--ebuild-uri"):
CONFIG['ebuild-uri'] = True CONFIG['ebuild-uri'] = True
elif o in ("--no-handlers"):
CONFIG['handlers-exclude'] = a.split(",")
else: else:
return_code = False return_code = False
@ -205,7 +210,7 @@ def parse_args():
getopt_options['long']['global'] = [ getopt_options['long']['global'] = [
"help", "version", "nocolor", "quiet", "verbose", "oneshot", "help", "version", "nocolor", "quiet", "verbose", "oneshot",
"brute-force=", "format=", "progress", "mirror", "ignore-pre-release", "brute-force=", "format=", "progress", "mirror", "ignore-pre-release",
"ignore-pre-release-if-stable", "ebuild-uri" "ignore-pre-release-if-stable", "ebuild-uri", "no-handlers="
] ]
short_opts = getopt_options['short']['global'] short_opts = getopt_options['short']['global']

View File

@ -7,6 +7,7 @@ __version__ = "git"
import ConfigParser import ConfigParser
import os import os
from ast import literal_eval
CONFIG = { CONFIG = {
@ -29,6 +30,7 @@ CONFIG = {
'ignore-pre-release': False, 'ignore-pre-release': False,
'ignore-pre-release-if-stable': False, 'ignore-pre-release-if-stable': False,
'ebuild-uri': False, 'ebuild-uri': False,
'handlers-exclude': [],
} }
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
@ -36,7 +38,7 @@ config.read(['/etc/euscan.conf', os.path.expanduser('~/.euscan.conf')])
if config.has_section("euscan"): if config.has_section("euscan"):
for key, value in config.items("euscan"): for key, value in config.items("euscan"):
if key in CONFIG: if key in CONFIG:
CONFIG[key] = value CONFIG[key] = literal_eval(value)
BLACKLIST_VERSIONS = [ BLACKLIST_VERSIONS = [
# Compatibility package for running binaries linked against a # Compatibility package for running binaries linked against a

View File

@ -37,7 +37,8 @@ def find_best_handler(kind, pkg, *args):
Find the best handler for the given package Find the best handler for the given package
""" """
for handler in handlers[kind]: for handler in handlers[kind]:
if handler.can_handle(pkg, *args): if (handler.HANDLER_NAME not in CONFIG["handlers-exclude"] and
handler.can_handle(pkg, *args)):
return handler return handler
return None return None
@ -149,8 +150,11 @@ def scan_url(pkg, urls, options, on_progress=None):
try: try:
url_handler = find_best_handler('url', pkg, url) url_handler = find_best_handler('url', pkg, url)
for o in options: if url_handler:
versions += url_handler.scan_url(pkg, url, o) for o in options:
versions += url_handler.scan_url(pkg, url, o)
else:
output.eerror("Can't find a suitable handler!")
except Exception as e: except Exception as e:
output.ewarn( output.ewarn(
"Handler failed: [%s] %s" % "Handler failed: [%s] %s" %