diff options
author | Corentin Chary <corentin.chary@gmail.com> | 2012-12-01 04:55:11 -0800 |
---|---|---|
committer | Corentin Chary <corentin.chary@gmail.com> | 2012-12-01 04:55:11 -0800 |
commit | dfb7a7b98698883d3f8403bdf84caf04fc96adf7 (patch) | |
tree | 1ed82ea06268f3b042b592cfe7a4720793325b06 | |
parent | euscanwww: handle '' handler (diff) | |
parent | Fix issues raised in pull request #19 (diff) | |
download | euscan-dfb7a7b98698883d3f8403bdf84caf04fc96adf7.tar.gz euscan-dfb7a7b98698883d3f8403bdf84caf04fc96adf7.tar.bz2 euscan-dfb7a7b98698883d3f8403bdf84caf04fc96adf7.zip |
Merge pull request #19 from EvaSDK/master
Add gnome handler
-rw-r--r-- | pym/euscan/handlers/gnome.py | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/pym/euscan/handlers/gnome.py b/pym/euscan/handlers/gnome.py new file mode 100644 index 0000000..9836e91 --- /dev/null +++ b/pym/euscan/handlers/gnome.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- + +import re +import urllib2 + +try: + import simplejson as json +except ImportError: + import json + +import portage + +from euscan import mangling, helpers, output + +HANDLER_NAME = "gnome" +CONFIDENCE = 100 +PRIORITY = 90 + +GNOME_URL_SOURCE = 'http://ftp.gnome.org/pub/GNOME/sources' + +def can_handle(_pkg, url=None): + return url and url.startswith('mirror://gnome/') + + +def guess_package(cp, url): + match = re.search('mirror://gnome/sources/([^/]+)/.*', url) + if match: + return match.group(1) + + _cat, pkg = cp.split("/") + + return pkg + + +def scan_url(pkg, url, options): + 'http://ftp.gnome.org/pub/GNOME/sources/' + package = { + 'data': guess_package(pkg.cpv, url), + 'type': 'gnome', + } + return scan_pkg(pkg, package) + + +def scan_pkg(pkg, options): + package = options['data'] + + output.einfo("Using Gnome json cache: " + package) + + fp = urllib2.urlopen('/'.join([GNOME_URL_SOURCE, package, 'cache.json'])) + content = fp.read() + fp.close() + + cache = json.loads(content, encoding='ascii') + + if cache[0] != 4: + output.eerror('Unknow cache format detected') + return [] + + versions = cache[2][package] + + if not versions: + return [] + + versions.reverse() + + cp, ver, _rev = portage.pkgsplit(pkg.cpv) + + ret = [] + for up_pv in versions: + pv = mangling.mangle_version(up_pv, options) + if helpers.version_filtered(cp, ver, pv): + continue + up_files = cache[1][package][up_pv] + for tarball_comp in ('tar.xz', 'tar.bz2', 'tar.gz'): + if tarball_comp in up_files: + url = '/'.join([GNOME_URL_SOURCE, package, + up_files[tarball_comp]]) + break + else: + output.ewarn('No tarball for release %s' % up_pv) + ret.append((url, pv, HANDLER_NAME, CONFIDENCE)) + + return ret |