Merge lp:~james-w/pkgme-devportal/strip-epochs into lp:pkgme-devportal

Proposed by James Westby
Status: Merged
Approved by: Jonathan Lange
Approved revision: 92
Merged at revision: 92
Proposed branch: lp:~james-w/pkgme-devportal/strip-epochs
Merge into: lp:pkgme-devportal
Diff against target: 75 lines (+42/-1)
2 files modified
devportalbinary/database.py (+4/-1)
devportalbinary/tests/test_database.py (+38/-0)
To merge this branch: bzr merge lp:~james-w/pkgme-devportal/strip-epochs
Reviewer Review Type Date Requested Status
Jonathan Lange Approve
Review via email: mp+121894@code.launchpad.net

Commit message

Strip epochs from version numbers when calculating the .deb url on LP.

Description of the change

Hi,

We have a large number of libraries not in the dependency db because
we can't currently fetch the .deb from LP. That's becuase they have epochs
in the version numbers, but they aren't in the filename. This changes
the url calculation to strip epochs.

This is rather hacky in a number of ways:

  * The epoch stripping. This could be done with code from python-debian
    if we want the extra dependency.

  * The tests. This could be done with mock, or could be done with better
    fakes for the launchpadlib stuff.

As ever, happy to make any changes that you feel are warranted.

Thanks,

James

To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote :

Looks good. Thanks.

I guess it would be nice if Python had a thing that took nested dicts and turned them into nested objects.

review: Approve
Revision history for this message
James Westby (james-w) wrote :

That would indeed be nice.

Thanks,

James

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'devportalbinary/database.py'
2--- devportalbinary/database.py 2012-08-29 14:39:18 +0000
3+++ devportalbinary/database.py 2012-08-29 16:11:29 +0000
4@@ -128,10 +128,13 @@
5
6 def get_url(self):
7 """Get the download URL for this binary package."""
8+ version = self.bpph.binary_package_version
9+ if ':' in version:
10+ version = version[version.index(':')+1:]
11 return '%s/+files/%s_%s_%s.deb' % (
12 self.bpph.archive.web_link,
13 self.bpph.binary_package_name,
14- self.bpph.binary_package_version,
15+ version,
16 self.bpph.distro_arch_series.architecture_tag,
17 )
18
19
20=== modified file 'devportalbinary/tests/test_database.py'
21--- devportalbinary/tests/test_database.py 2012-08-29 14:39:18 +0000
22+++ devportalbinary/tests/test_database.py 2012-08-29 16:11:29 +0000
23@@ -1,3 +1,4 @@
24+from collections import namedtuple
25 import gzip
26 import os
27
28@@ -15,6 +16,7 @@
29
30 from devportalbinary.database import (
31 AptFilePackageDatabase,
32+ BinaryPackage,
33 build_symbol_list,
34 load_configuration,
35 PackageDatabase,
36@@ -203,3 +205,39 @@
37 db.get_dependencies("libfoo.so.2", arch="i386"),
38 set(["pkgfoo", "pkgbar"]))
39 self.assertEqual(len(db._get_lib_to_pkgs_mapping("oneiric", "i386")), 1)
40+
41+
42+class FakeBPPH(object):
43+
44+ def __init__(self):
45+ self.archive = namedtuple(
46+ 'Archive', 'web_link')('http://lp.net/archive')
47+ self.distro_arch_series = namedtuple(
48+ 'DistroArchSeries', 'architecture_tag')('i386')
49+ self.binary_package_name = 'foo'
50+ self.binary_package_version = '1'
51+
52+
53+class TestBinaryPackage(TestCase):
54+
55+ def test_get_url(self):
56+ bpph = FakeBPPH()
57+ expected_url = '%s/+files/%s_%s_%s.deb' % (
58+ bpph.archive.web_link,
59+ bpph.binary_package_name,
60+ bpph.binary_package_version,
61+ bpph.distro_arch_series.architecture_tag,
62+ )
63+ self.assertEqual(expected_url, BinaryPackage(bpph).get_url())
64+
65+ def test_get_url_with_epoch(self):
66+ # epochs are stripped from the version number
67+ bpph = FakeBPPH()
68+ bpph.binary_package_version = '1:1'
69+ expected_url = '%s/+files/%s_%s_%s.deb' % (
70+ bpph.archive.web_link,
71+ bpph.binary_package_name,
72+ '1',
73+ bpph.distro_arch_series.architecture_tag,
74+ )
75+ self.assertEqual(expected_url, BinaryPackage(bpph).get_url())

Subscribers

People subscribed via source and target branches