From c63d5405c991ef801c4cf21e4ff34c431d44f753 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Wed, 7 Apr 2010 09:53:35 +0100 Subject: [PATCH] Record correct machine type for distribution packages Before, we used "x86_64" for amd64 packages and "*" for everything else, including 32-bit binaries (which could then be selected with 64-bit binaries). --- tests/dpkg/dpkg-query | 2 +- tests/testdistro.py | 2 ++ zeroinstall/injector/distro.py | 28 ++++++++++++++++++---------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/tests/dpkg/dpkg-query b/tests/dpkg/dpkg-query index b2ea90f..3acd447 100755 --- a/tests/dpkg/dpkg-query +++ b/tests/dpkg/dpkg-query @@ -1,3 +1,3 @@ #!/bin/sh echo "python-bittorrent 3.4.2-10ubuntu2 any" -echo "libxcomposite-dev 1:0.3.1-1 any" +echo "libxcomposite-dev 1:0.3.1-1 i386" diff --git a/tests/testdistro.py b/tests/testdistro.py index 3ae5d7a..7f16f33 100755 --- a/tests/testdistro.py +++ b/tests/testdistro.py @@ -80,12 +80,14 @@ class TestDistro(BaseTest): self.assertEquals('3.4.2-10', bittorrent_installed.get_version()) self.assertTrue(bittorrent_installed.installed) self.assertFalse(bittorrent_uninstalled.installed) + self.assertEquals(None, bittorrent_installed.machine) self.feed = model.ZeroInstallFeed(empty_feed, local_path = '/empty.xml') host.get_package_info('libxcomposite-dev', self.factory) self.assertEquals(1, len(self.feed.implementations)) libxcomposite = self.feed.implementations['package:deb:libxcomposite-dev:0.3.1-1'] self.assertEquals('0.3.1-1', libxcomposite.get_version()) + self.assertEquals('i386', libxcomposite.machine) def testRPM(self): rpmdir = os.path.join(os.path.dirname(__file__), 'rpm') diff --git a/zeroinstall/injector/distro.py b/zeroinstall/injector/distro.py index 4652543..a1f7522 100644 --- a/zeroinstall/injector/distro.py +++ b/zeroinstall/injector/distro.py @@ -215,6 +215,22 @@ class CachedDistribution(Distribution): os.unlink(tmpname) raise +# Maps machine type names used in packages to their Zero Install versions +_canonical_machine = { + 'all' : '*', + 'any' : '*', + 'amd64': 'x86_64', + 'i386': 'i386', +} + +host_machine = os.uname()[-1] +def canonical_machine(package_machine): + machine = _canonical_machine.get(package_machine, None) + if machine is None: + # Safe default if we can't understand the arch + return host_machine + return machine + class DebianDistribution(CachedDistribution): """A dpkg-based distribution.""" @@ -232,13 +248,9 @@ class DebianDistribution(CachedDistribution): if ':' in version: # Debian's 'epoch' system version = version.split(':', 1)[1] - if debarch == 'amd64\n': - zi_arch = 'x86_64' - else: - zi_arch = '*' clean_version = try_cleanup_distro_version(version) if clean_version: - cache.append('%s\t%s\t%s' % (package, clean_version, zi_arch)) + cache.append('%s\t%s\t%s' % (package, clean_version, canonical_machine(debarch.strip()))) else: warn(_("Can't parse distribution version '%(version)s' for package '%(package)s'"), {'version': version, 'package': package}) @@ -274,11 +286,7 @@ class DebianDistribution(CachedDistribution): version = version.split(':', 1)[1] version = try_cleanup_distro_version(version) elif line.startswith('Architecture: '): - debarch = line[14:] - if debarch == 'amd64\n': - arch = 'x86_64' - else: - arch = '*' + arch = canonical_machine(line[14:].strip()) if version and arch: cached = '%s\t%s' % (version, arch) else: -- 2.11.4.GIT