From 7e635b380f10cbc1b1c5e74b2e69de5a0af51e60 Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Sat, 24 Nov 2012 00:42:11 +0100 Subject: [PATCH 1/2] Add gnome handler --- pym/euscan/handlers/gnome.py | 85 ++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 pym/euscan/handlers/gnome.py diff --git a/pym/euscan/handlers/gnome.py b/pym/euscan/handlers/gnome.py new file mode 100644 index 0000000..512f634 --- /dev/null +++ b/pym/euscan/handlers/gnome.py @@ -0,0 +1,85 @@ +# -*- 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 = guess_package(pkg.cpv, url) + return scan_pkg(pkg, package) + + +def scan_pkg(pkg, options): + # For some weird reasons package with no metadata + # will fail without this hack + options = { + 'data': options, + 'type': 'gnome', + } + package = options['data'] + + output.einfo("Using Gnome json cache: " + package) + + print 'Opening', '/'.join([GNOME_URL_SOURCE, package, 'cache.json']) + 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: + raise Exception('Unknow cache format detected') + + versions = cache[2][package] + + if not versions: + return versions + + 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: + raise Exception('No tarball for release ' + up_pv) + ret.append((url, pv, HANDLER_NAME, CONFIDENCE)) + return ret From e249199caec7e325cb8d3e37f2fefa1bbcf47844 Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Fri, 30 Nov 2012 23:39:25 +0100 Subject: [PATCH 2/2] Fix issues raised in pull request #19 * Replace print/raise by eoutput usage. * Fix scan_url function to properly format arguments of scan_pkg. --- pym/euscan/handlers/gnome.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pym/euscan/handlers/gnome.py b/pym/euscan/handlers/gnome.py index 512f634..9836e91 100644 --- a/pym/euscan/handlers/gnome.py +++ b/pym/euscan/handlers/gnome.py @@ -34,22 +34,18 @@ def guess_package(cp, url): def scan_url(pkg, url, options): 'http://ftp.gnome.org/pub/GNOME/sources/' - package = guess_package(pkg.cpv, url) + package = { + 'data': guess_package(pkg.cpv, url), + 'type': 'gnome', + } return scan_pkg(pkg, package) def scan_pkg(pkg, options): - # For some weird reasons package with no metadata - # will fail without this hack - options = { - 'data': options, - 'type': 'gnome', - } package = options['data'] output.einfo("Using Gnome json cache: " + package) - print 'Opening', '/'.join([GNOME_URL_SOURCE, package, 'cache.json']) fp = urllib2.urlopen('/'.join([GNOME_URL_SOURCE, package, 'cache.json'])) content = fp.read() fp.close() @@ -57,12 +53,13 @@ def scan_pkg(pkg, options): cache = json.loads(content, encoding='ascii') if cache[0] != 4: - raise Exception('Unknow cache format detected') + output.eerror('Unknow cache format detected') + return [] versions = cache[2][package] if not versions: - return versions + return [] versions.reverse() @@ -80,6 +77,7 @@ def scan_pkg(pkg, options): up_files[tarball_comp]]) break else: - raise Exception('No tarball for release ' + up_pv) + output.ewarn('No tarball for release %s' % up_pv) ret.append((url, pv, HANDLER_NAME, CONFIDENCE)) + return ret