aboutsummaryrefslogtreecommitdiff
blob: a5cb03717aa982b1c76b652537b605ed682333b9 (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
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