aboutsummaryrefslogtreecommitdiff
blob: bbfe6e197a1e0eb179db14a88f5b7e3de9222d26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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 = 90


berlios_regex = r"mirror://berlios/([^/]+)/([^/]+)"


def can_handle(pkg, url=None):
    return url and re.search(berlios_regex, url)


def scan_url(pkg, url, options):
    output.einfo("Using BerliOS handler")

    cp, ver, rev = portage.pkgsplit(pkg.cpv)

    project, filename = re.search(berlios_regex, 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