diff --git a/pym/euscan/handlers/__init__.py b/pym/euscan/handlers/__init__.py index 0b4b510..bcbd680 100644 --- a/pym/euscan/handlers/__init__.py +++ b/pym/euscan/handlers/__init__.py @@ -1,6 +1,17 @@ -from euscan.handlers import generic, php, pypi, rubygem, kde, cpan, github +import pkgutil -handlers = [kde, php, pypi, rubygem, cpan, github, generic] +# autoimport all modules in this directory and append them to handlers list +handlers = [] +for loader, module_name, is_pkg in pkgutil.walk_packages(__path__): + module = loader.find_module(module_name).load_module(module_name) + handlers.append(module) + +# sort handlers by priority (e.g.: generic should be run lastly) +handlers = sorted( + handlers, + key=lambda handler: handler.PRIORITY, + reverse=True +) def find_best_handler(cpv, url): diff --git a/pym/euscan/handlers/cpan.py b/pym/euscan/handlers/cpan.py index 7dcc246..7115c20 100644 --- a/pym/euscan/handlers/cpan.py +++ b/pym/euscan/handlers/cpan.py @@ -7,6 +7,7 @@ from euscan import helpers, output HANDLER_NAME = "cpan" CONFIDENCE = 100.0 +PRIORITY = 100 _cpan_package_name_re = re.compile("mirror://cpan/authors/.*/([^/.]*).*") diff --git a/pym/euscan/handlers/generic.py b/pym/euscan/handlers/generic.py index 92c2984..5c6d467 100644 --- a/pym/euscan/handlers/generic.py +++ b/pym/euscan/handlers/generic.py @@ -14,6 +14,7 @@ from euscan import CONFIG, SCANDIR_BLACKLIST_URLS, \ HANDLER_NAME = "generic" CONFIDENCE = 50.0 +PRIORITY = 0 BRUTEFORCE_HANDLER_NAME = "brute_force" BRUTEFORCE_CONFIDENCE = 30.0 diff --git a/pym/euscan/handlers/github.py b/pym/euscan/handlers/github.py index 10386fd..920e6ef 100644 --- a/pym/euscan/handlers/github.py +++ b/pym/euscan/handlers/github.py @@ -1,4 +1,5 @@ -import json, urllib2 +import json +import urllib2 import re import portage @@ -7,16 +8,20 @@ from euscan import helpers, output HANDLER_NAME = "github" CONFIDENCE = 100.0 +PRIORITY = 100 + def can_handle(cpv, url): return url.startswith('mirror://github/') + def guess_package(cp, url): match = re.search('^mirror://github/(.*?)/(.*?)/(.*)$', url) assert(match) return (match.group(1), match.group(2), match.group(3)) + def scan(cpv, url): 'http://developer.github.com/v3/repos/downloads/' @@ -46,5 +51,6 @@ def scan(cpv, url): continue yield (dl['html_url'], pv, HANDLER_NAME, CONFIDENCE) + def brute_force(cpv, url): return [] diff --git a/pym/euscan/handlers/kde.py b/pym/euscan/handlers/kde.py index 2b27639..406b079 100644 --- a/pym/euscan/handlers/kde.py +++ b/pym/euscan/handlers/kde.py @@ -1,5 +1,7 @@ from euscan.handlers import generic +PRIORITY = 100 + HANDLER_NAME = "kde" diff --git a/pym/euscan/handlers/php.py b/pym/euscan/handlers/php.py index 82c49c5..158280c 100644 --- a/pym/euscan/handlers/php.py +++ b/pym/euscan/handlers/php.py @@ -7,6 +7,7 @@ from euscan import helpers, output HANDLER_NAME = "php" CONFIDENCE = 100.0 +PRIORITY = 100 def can_handle(cpv, url): diff --git a/pym/euscan/handlers/pypi.py b/pym/euscan/handlers/pypi.py index 0b3ed73..1dcad99 100644 --- a/pym/euscan/handlers/pypi.py +++ b/pym/euscan/handlers/pypi.py @@ -7,6 +7,7 @@ from euscan import helpers, output HANDLER_NAME = "pypi" CONFIDENCE = 100.0 +PRIORITY = 100 def can_handle(cpv, url): diff --git a/pym/euscan/handlers/rubygem.py b/pym/euscan/handlers/rubygem.py index 8bbd5ab..c0f7ade 100644 --- a/pym/euscan/handlers/rubygem.py +++ b/pym/euscan/handlers/rubygem.py @@ -7,6 +7,7 @@ from euscan import helpers, output HANDLER_NAME = "rubygem" CONFIDENCE = 100.0 +PRIORITY = 100 def can_handle(cpv, url):