2012-08-07 16:42:27 +02:00
|
|
|
import re
|
2019-12-05 17:46:19 +01:00
|
|
|
import urllib.request, urllib.parse, urllib.error
|
2012-08-07 16:42:27 +02:00
|
|
|
|
|
|
|
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
|
2012-08-08 12:20:33 +02:00
|
|
|
PRIORITY = 90
|
|
|
|
|
|
|
|
|
2012-08-15 11:04:29 +02:00
|
|
|
berlios_regex = r"mirror://berlios/([^/]+)/([^/]+)"
|
2012-08-07 16:42:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
def can_handle(pkg, url=None):
|
2012-10-29 13:05:20 +01:00
|
|
|
if not url:
|
|
|
|
return False
|
|
|
|
|
|
|
|
cp, ver, rev = portage.pkgsplit(pkg.cpv)
|
|
|
|
if ver not in url:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return re.search(berlios_regex, url)
|
2012-08-07 16:42:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
def scan_url(pkg, url, options):
|
|
|
|
output.einfo("Using BerliOS handler")
|
|
|
|
|
|
|
|
cp, ver, rev = portage.pkgsplit(pkg.cpv)
|
|
|
|
|
2012-08-08 12:20:33 +02:00
|
|
|
project, filename = re.search(berlios_regex, url).groups()
|
2012-08-07 16:42:27 +02:00
|
|
|
|
|
|
|
project_page = "http://developer.berlios.de/projects/%s" % project
|
2019-12-05 17:46:19 +01:00
|
|
|
content = urllib.request.urlopen(project_page).read()
|
2012-08-07 16:42:27 +02:00
|
|
|
|
|
|
|
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
|