euscan: plugin system for handlers

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-06-28 11:08:05 +02:00
parent 951624759a
commit b06965f386
8 changed files with 27 additions and 3 deletions

View File

@ -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): def find_best_handler(cpv, url):

View File

@ -7,6 +7,7 @@ from euscan import helpers, output
HANDLER_NAME = "cpan" HANDLER_NAME = "cpan"
CONFIDENCE = 100.0 CONFIDENCE = 100.0
PRIORITY = 100
_cpan_package_name_re = re.compile("mirror://cpan/authors/.*/([^/.]*).*") _cpan_package_name_re = re.compile("mirror://cpan/authors/.*/([^/.]*).*")

View File

@ -14,6 +14,7 @@ from euscan import CONFIG, SCANDIR_BLACKLIST_URLS, \
HANDLER_NAME = "generic" HANDLER_NAME = "generic"
CONFIDENCE = 50.0 CONFIDENCE = 50.0
PRIORITY = 0
BRUTEFORCE_HANDLER_NAME = "brute_force" BRUTEFORCE_HANDLER_NAME = "brute_force"
BRUTEFORCE_CONFIDENCE = 30.0 BRUTEFORCE_CONFIDENCE = 30.0

View File

@ -1,4 +1,5 @@
import json, urllib2 import json
import urllib2
import re import re
import portage import portage
@ -7,16 +8,20 @@ from euscan import helpers, output
HANDLER_NAME = "github" HANDLER_NAME = "github"
CONFIDENCE = 100.0 CONFIDENCE = 100.0
PRIORITY = 100
def can_handle(cpv, url): def can_handle(cpv, url):
return url.startswith('mirror://github/') return url.startswith('mirror://github/')
def guess_package(cp, url): def guess_package(cp, url):
match = re.search('^mirror://github/(.*?)/(.*?)/(.*)$', url) match = re.search('^mirror://github/(.*?)/(.*?)/(.*)$', url)
assert(match) assert(match)
return (match.group(1), match.group(2), match.group(3)) return (match.group(1), match.group(2), match.group(3))
def scan(cpv, url): def scan(cpv, url):
'http://developer.github.com/v3/repos/downloads/' 'http://developer.github.com/v3/repos/downloads/'
@ -46,5 +51,6 @@ def scan(cpv, url):
continue continue
yield (dl['html_url'], pv, HANDLER_NAME, CONFIDENCE) yield (dl['html_url'], pv, HANDLER_NAME, CONFIDENCE)
def brute_force(cpv, url): def brute_force(cpv, url):
return [] return []

View File

@ -1,5 +1,7 @@
from euscan.handlers import generic from euscan.handlers import generic
PRIORITY = 100
HANDLER_NAME = "kde" HANDLER_NAME = "kde"

View File

@ -7,6 +7,7 @@ from euscan import helpers, output
HANDLER_NAME = "php" HANDLER_NAME = "php"
CONFIDENCE = 100.0 CONFIDENCE = 100.0
PRIORITY = 100
def can_handle(cpv, url): def can_handle(cpv, url):

View File

@ -7,6 +7,7 @@ from euscan import helpers, output
HANDLER_NAME = "pypi" HANDLER_NAME = "pypi"
CONFIDENCE = 100.0 CONFIDENCE = 100.0
PRIORITY = 100
def can_handle(cpv, url): def can_handle(cpv, url):

View File

@ -7,6 +7,7 @@ from euscan import helpers, output
HANDLER_NAME = "rubygem" HANDLER_NAME = "rubygem"
CONFIDENCE = 100.0 CONFIDENCE = 100.0
PRIORITY = 100
def can_handle(cpv, url): def can_handle(cpv, url):