From 565c5823c1cc35b5c447468d1aa9beecbd0d0e9f Mon Sep 17 00:00:00 2001 From: volpino Date: Fri, 21 Sep 2012 19:03:53 +0200 Subject: [PATCH] euscan: deb handler - adding support for Packages.gz or Packages.bz2 and version detection fix Signed-off-by: volpino --- TODO | 3 +-- pym/euscan/handlers/deb.py | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index 994f72b..9fda0b9 100644 --- a/TODO +++ b/TODO @@ -38,8 +38,7 @@ euscan ### handlers - remote-id type deb repository: - - Fix handler to support Packages.gz or Packages.bz2 - - find out how to get download url + - find out how to get download url (not sure it's possible) ### remote-id - Propose new remote-id: deb diff --git a/pym/euscan/handlers/deb.py b/pym/euscan/handlers/deb.py index 156158b..b559263 100644 --- a/pym/euscan/handlers/deb.py +++ b/pym/euscan/handlers/deb.py @@ -1,5 +1,7 @@ import urllib import re +import bz2 +import zlib import portage @@ -24,17 +26,22 @@ def scan_pkg(pkg, options): fp = urllib.urlopen(packages_url) content = fp.read() - # TODO: Add support for .gz and .bz2 Packages file + # Support for .gz and .bz2 Packages file + if packages_url.endswith(".bz2"): + content = bz2.decompress(content) + if packages_url.endswith(".gz"): + content = zlib.decompress(content, 16 + zlib.MAX_WBITS) content = content.split("\n\n") result = [] for package_info in content: - for line in package_info.split("\n"): - res = re.search("^Version: (.*)$", line) - if res: - result.append(res.group(1)) + package_line = re.search(r"^Package: (.*)$", package_info, re.M) + version_line = re.search(r"^Version: (.*)$", package_info, re.M) + if package_line and package_line.group(1) == package_name: + if version_line: + result.append(version_line.group(1)) ret = [] for up_pv in result: