Merge lp:~jml/pkgme/missing-lsb-release into lp:pkgme

Proposed by Jonathan Lange
Status: Merged
Approved by: James Westby
Approved revision: 148
Merged at revision: 147
Proposed branch: lp:~jml/pkgme/missing-lsb-release
Merge into: lp:pkgme
Diff against target: 97 lines (+41/-6)
3 files modified
NEWS.txt (+9/-0)
pkgme/info_elements.py (+12/-4)
pkgme/tests/test_info_elements.py (+20/-2)
To merge this branch: bzr merge lp:~jml/pkgme/missing-lsb-release
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+125976@code.launchpad.net

Commit message

Handle missing lsb-release

Description of the change

Applies Natalia's patch from bug 1010411.

Changes Distribution to default to UNRELEASED if there's no lsb-release,
rather than just erroring out.

I've updated the patch to use try/except for the main logic, and to have
a test for missing lsb-release, by adding another (bad) layer of abstraction.
Obviously the correct thing to do is to have a full filesystem abstraction.

Thanks,
jml

To post a comment you must log in.
Revision history for this message
James Westby (james-w) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS.txt'
2--- NEWS.txt 2012-09-12 14:10:16 +0000
3+++ NEWS.txt 2012-09-24 11:10:24 +0000
4@@ -2,6 +2,15 @@
5 NEWS for pkgme
6 ==============
7
8+0.4.2 (2012-XX-XX)
9+==================
10+
11+Improvements
12+------------
13+
14+ * Distribution defaults to "UNRELEASED" if there is no ``/etc/lsb-release``
15+ file, rather than erroring out. (Natalia)
16+
17
18 0.4.1 (2012-09-12)
19 ==================
20
21=== modified file 'pkgme/info_elements.py'
22--- pkgme/info_elements.py 2012-09-12 03:31:40 +0000
23+++ pkgme/info_elements.py 2012-09-24 11:10:24 +0000
24@@ -1,3 +1,4 @@
25+import errno
26 import json
27 import re
28 import rfc822
29@@ -151,12 +152,19 @@
30 e.g. 'unstable', 'natty', 'oneiric'.
31 """
32
33+ LSB_RELEASE = '/etc/lsb-release'
34+
35 @classmethod
36 def get_default(cls):
37- with open('/etc/lsb-release') as fp:
38- release_keys = dict(
39- line.strip().split('=') for line in fp.readlines())
40- return release_keys['DISTRIB_CODENAME']
41+ try:
42+ with open(cls.LSB_RELEASE) as fp:
43+ release_keys = dict(
44+ line.strip().split('=') for line in fp.readlines())
45+ return release_keys['DISTRIB_CODENAME']
46+ except IOError, e:
47+ if e.errno == errno.ENOENT:
48+ return 'UNRELEASED'
49+ raise
50
51
52 class BuildDepends(InfoElement):
53
54=== modified file 'pkgme/tests/test_info_elements.py'
55--- pkgme/tests/test_info_elements.py 2012-09-03 14:35:54 +0000
56+++ pkgme/tests/test_info_elements.py 2012-09-24 11:10:24 +0000
57@@ -1,7 +1,15 @@
58 import json
59+import os
60
61-from fixtures import EnvironmentVariableFixture
62-from testtools import TestCase
63+from fixtures import (
64+ EnvironmentVariableFixture,
65+ MonkeyPatch,
66+ TempDir,
67+ )
68+from testtools import (
69+ skipUnless,
70+ TestCase,
71+ )
72
73 from ..info_elements import (
74 BuildDepends,
75@@ -146,6 +154,7 @@
76
77 class DistributionTestCase(TestCase):
78
79+ @skipUnless(os.path.isfile('/etc/lsb-release'), "No current distro")
80 def test_defaults_to_current_distro(self):
81 with open('/etc/lsb-release') as fp:
82 release_keys = dict(
83@@ -153,6 +162,15 @@
84 self.assertEqual(
85 Distribution.get_default(), release_keys['DISTRIB_CODENAME'])
86
87+ def test_nonexistent_lsb_release(self):
88+ tmp_path = self.useFixture(TempDir()).path
89+ nonexistent = os.path.join(tmp_path, 'nonexistent')
90+ patch = MonkeyPatch(
91+ 'pkgme.info_elements.Distribution.LSB_RELEASE', nonexistent)
92+ with patch:
93+ default_distro = Distribution.get_default()
94+ self.assertEqual('UNRELEASED', default_distro)
95+
96
97 class DebianFormattedTextTests(TestCase):
98

Subscribers

People subscribed via source and target branches