From eacf34cc95661c5d6a7e826e1b8b769b9c26b11e Mon Sep 17 00:00:00 2001 From: Anders F Bjorklund Date: Sat, 2 Jul 2011 11:30:19 +0200 Subject: [PATCH] get port archs too --- tests/macports/port | 8 ++++++++ tests/testdistro.py | 4 ++-- zeroinstall/injector/distro.py | 25 +++++++++++++++++++++---- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/tests/macports/port b/tests/macports/port index 6dd34c7..97b3900 100755 --- a/tests/macports/port +++ b/tests/macports/port @@ -1,4 +1,12 @@ #!/bin/sh +if [ "$1 $2" == "echo installed" ]; then cat << EOF zeroinstall-injector @0.54_0 EOF +elif [ "$1 $2" == "-v installed" ]; then +cat << EOF +The following ports are currently installed: + zeroinstall-injector @0.54_0 + zeroinstall-injector @1.0_0 (active) platform='darwin 10' archs='noarch' +EOF +fi diff --git a/tests/testdistro.py b/tests/testdistro.py index 32157d8..45d31d3 100755 --- a/tests/testdistro.py +++ b/tests/testdistro.py @@ -225,8 +225,8 @@ class TestDistro(BaseTest): factory = self.make_factory(ports) ports.get_package_info('zeroinstall-injector', factory) self.assertEquals(1, len(self.feed.implementations)) - impl = self.feed.implementations['package:macports:zeroinstall-injector:0.54-0:*'] - self.assertEquals('0.54-0', impl.get_version()) + impl = self.feed.implementations['package:macports:zeroinstall-injector:1.0-0:*'] + self.assertEquals('1.0-0', impl.get_version()) self.assertEquals(None, impl.machine) def testCleanVersion(self): diff --git a/zeroinstall/injector/distro.py b/zeroinstall/injector/distro.py index 2ab5494..29e40e2 100644 --- a/zeroinstall/injector/distro.py +++ b/zeroinstall/injector/distro.py @@ -323,6 +323,7 @@ _canonical_machine = { 'any' : '*', 'noarch' : '*', '(none)' : '*', + 'x86_64': 'x86_64', 'amd64': 'x86_64', 'i386': 'i386', 'i486': 'i486', @@ -600,14 +601,30 @@ class MacPortsDistribution(CachedDistribution): def generate_cache(self): cache = [] - for line in os.popen("port echo active"): - package, version = line.split() +# for line in os.popen("port echo active"): + for line in os.popen("port -v installed"): + if line == 'The following ports are currently installed:\n': + continue + if line.strip().count(" ") > 1: + package, version, extra = line.split(None, 2) + else: + package, version = line.split() + extra = "" + if not extra.startswith("(active)"): + continue version = version.lstrip('@') version = re.sub(r"\+.*","",version) # strip variants - zi_arch = '*' # TODO: get port archs too + zi_arch = '*' clean_version = try_cleanup_distro_version(version) if clean_version: - cache.append('%s\t%s\t%s' % (package, clean_version, zi_arch)) + match = re.match(r" platform='([^' ]*)( \d+)?' archs='([^']*)'", extra) + if match: + platform, major, archs = match.groups() + for arch in archs.split(): + zi_arch = canonical_machine(arch) + cache.append('%s\t%s\t%s' % (package, clean_version, zi_arch)) + else: + cache.append('%s\t%s\t%s' % (package, clean_version, zi_arch)) else: warn(_("Can't parse distribution version '%(version)s' for package '%(package)s'"), {'version': version, 'package': package}) -- 2.11.4.GIT