euscan: Adding new handlers: google-code, berlios, sourceforge

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-08-07 16:42:27 +02:00
parent ea6e421d16
commit a31b6fa4a8
6 changed files with 133 additions and 6 deletions

View File

@ -0,0 +1,49 @@
import re
import urllib
import portage
from euscan.helpers import regex_from_template
from euscan.handlers.url import process_scan as url_scan
from euscan import output
HANDLER_NAME = "berlios"
CONFIDENCE = 90
PRIORITY = 95
def can_handle(pkg, url=None):
return url and "berlios.de/" in url
def scan_url(pkg, url, options):
output.einfo("Using BerliOS handler")
cp, ver, rev = portage.pkgsplit(pkg.cpv)
project, filename = re.search(r"berlios.de/(.+)/(.+)", url).groups()
project_page = "http://developer.berlios.de/projects/%s" % project
content = urllib.urlopen(project_page).read()
project_id = re.search(
r"/project/filelist.php\?group_id=(\d+)",
content
).group(1)
base_url = (
"http://developer.berlios.de/project/filelist.php?group_id=%s" %
project_id
)
file_pattern = regex_from_template(
filename.replace(ver, "${PV}")
)
result = url_scan(pkg, base_url, file_pattern)
ret = []
for found_url, pv, _, _ in result:
found_url = found_url.replace("prdownload", "download")
ret.append((found_url, pv, HANDLER_NAME, CONFIDENCE))
return ret

View File

@ -11,8 +11,8 @@ except ImportError:
import portage import portage
from euscan import CONFIG, SCANDIR_BLACKLIST_URLS, \ from euscan import output, helpers, mangling, CONFIG, SCANDIR_BLACKLIST_URLS, \
BRUTEFORCE_BLACKLIST_PACKAGES, BRUTEFORCE_BLACKLIST_URLS, output, helpers, mangling BRUTEFORCE_BLACKLIST_PACKAGES, BRUTEFORCE_BLACKLIST_URLS
HANDLER_NAME = "generic" HANDLER_NAME = "generic"
CONFIDENCE = 45 CONFIDENCE = 45

View File

@ -14,12 +14,14 @@ PRIORITY = 90
def can_handle(pkg, url=None): def can_handle(pkg, url=None):
return url and url.startswith('mirror://github/') return url and 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_url(pkg, url, options): def scan_url(pkg, url, options):
'http://developer.github.com/v3/repos/downloads/' 'http://developer.github.com/v3/repos/downloads/'

View File

@ -0,0 +1,37 @@
import re
import portage
from euscan import output
from euscan.helpers import regex_from_template
from euscan.handlers.url import process_scan as url_scan
HANDLER_NAME = "google-code"
CONFIDENCE = 90
PRIORITY = 90
package_name_regex = r"http://(.+).googlecode.com/files/.+"
def can_handle(pkg, url=None):
return url and re.match(package_name_regex, url)
def scan_url(pkg, url, options):
output.einfo("Using Google Code handler")
cp, ver, rev = portage.pkgsplit(pkg.cpv)
package_name = re.match(package_name_regex, url).group(1)
base_url = "http://code.google.com/p/%s/downloads/list" % package_name
file_pattern = regex_from_template(
url.split("/")[-1].replace(ver, "${PV}")
)
result = url_scan(pkg, base_url, file_pattern)
ret = []
for found_url, pv, _, _ in result:
ret.append((found_url, pv, HANDLER_NAME, CONFIDENCE))
return ret

View File

@ -0,0 +1,34 @@
import re
import portage
from euscan.helpers import regex_from_template
from euscan.handlers.url import process_scan as url_scan
from euscan import output
HANDLER_NAME = "sourceforge"
CONFIDENCE = 90
PRIORITY = 95
def can_handle(pkg, url=None):
return url and "sourceforge.net/" in url
def scan_url(pkg, url, options):
output.einfo("Using SourceForge handler")
cp, ver, rev = portage.pkgsplit(pkg.cpv)
project, filename = re.search("sourceforge.net/(.+)/(.+)", url).groups()
base_url = "http://qa.debian.org/watch/sf.php/%s" % project
file_pattern = regex_from_template(
filename.replace(ver, "${PV}")
)
result = url_scan(pkg, base_url, file_pattern)
ret = []
for found_url, pv, _, _ in result:
ret.append((found_url, pv, HANDLER_NAME, CONFIDENCE))
return ret

View File

@ -77,13 +77,12 @@ def read_options(options):
return base, file_pattern return base, file_pattern
def scan_pkg(pkg, options): def process_scan(pkg, base, file_pattern, options=None):
output.einfo("Using watch data") if options is None:
options = {}
cp, ver, rev = pkg.cp, pkg.version, pkg.revision cp, ver, rev = pkg.cp, pkg.version, pkg.revision
base, file_pattern = read_options(options)
results = [] results = []
if not re.search(is_pattern, base): if not re.search(is_pattern, base):
steps = [(base, file_pattern)] steps = [(base, file_pattern)]
@ -97,3 +96,9 @@ def scan_pkg(pkg, options):
) )
return results return results
def scan_pkg(pkg, options):
output.einfo("Using watch data")
base, file_pattern = read_options(options)
return process_scan(pkg, base, file_pattern, options)