Merge lp:~james-w/pkgme/clean-maintainer into lp:pkgme

Proposed by James Westby
Status: Merged
Approved by: Jonathan Lange
Approved revision: 107
Merged at revision: 110
Proposed branch: lp:~james-w/pkgme/clean-maintainer
Merge into: lp:pkgme
Diff against target: 115 lines (+57/-2)
4 files modified
pkgme/info_elements.py (+15/-0)
pkgme/tests/test_info_elements.py (+29/-0)
pkgme/tests/test_package_files.py (+1/-1)
pkgme/tests/test_script.py (+12/-1)
To merge this branch: bzr merge lp:~james-w/pkgme/clean-maintainer
Reviewer Review Type Date Requested Status
Jonathan Lange Approve
Review via email: mp+108591@code.launchpad.net

Commit message

Ensure the maintainer value will always be accepted by dpkg.

Description of the change

Hi,

Daniel reported in https://bugs.launchpad.net/bugs/1007355 that he was getting
a failure as the maintainer info in the changelog was not recognised.

The docs say that the backend should provide the info in the accepted format,
but it's pretty easy for pkgme to fix up anything that isn't in that format
to get a working package.

I don't really see a downside to this, as if the backend provides something
valid this code shouldn't change it, and if they provide something invalid
the other choice is to fail, which isn't helpful to users.

There's a drive-by here to fix a test-isolation issue I found while running
with DEBEMAIL set in the environment. If it's set and invalid then those
tests fail as they run debuild which will fail. The fix actually means that
debuild would no longer fail, but being explicit about the isolation would
seem to be a good idea.

Thanks,

James

To post a comment you must log in.
Revision history for this message
Daniel Holbach (dholbach) wrote :

Well done. The code looks clean to me and it certainly fixes the issue I ran into.

Revision history for this message
Jonathan Lange (jml) wrote :

Looks good. Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pkgme/info_elements.py'
2--- pkgme/info_elements.py 2012-03-30 16:04:51 +0000
3+++ pkgme/info_elements.py 2012-06-04 17:00:26 +0000
4@@ -1,5 +1,6 @@
5 import json
6 import re
7+import rfc822
8 import os
9
10
11@@ -112,6 +113,20 @@
12 def get_default(cls):
13 return os.environ.get('DEBEMAIL', cls.default)
14
15+ @classmethod
16+ def clean(cls, value):
17+ name, email = rfc822.parseaddr(value)
18+ if not name:
19+ name = email
20+ if '@' not in email:
21+ email = 'person@example.com'
22+ maintainer = "%s <%s>" % (name, email)
23+ # Check that we get a valid result in all cases
24+ name, email = rfc822.parseaddr(maintainer)
25+ if name is None or email is None:
26+ raise AssertionError("Invalid maintainer format: %s" % maintainer)
27+ return maintainer
28+
29
30 class Homepage(InfoElement):
31
32
33=== modified file 'pkgme/tests/test_info_elements.py'
34--- pkgme/tests/test_info_elements.py 2012-03-26 15:06:45 +0000
35+++ pkgme/tests/test_info_elements.py 2012-06-04 17:00:26 +0000
36@@ -288,6 +288,35 @@
37 self.useFixture(EnvironmentVariableFixture('DEBEMAIL', debemail))
38 self.assertEqual(debemail, Maintainer.get_value(DictInfo({})))
39
40+ def test_clean_full(self):
41+ # A full name <email> is untouched by clean
42+ debemail = 'Dude <dude@example.com>'
43+ self.assertEqual(debemail, Maintainer.clean(debemail))
44+
45+ def test_clean_email(self):
46+ # Just an email is duplicated
47+ debemail = 'dude@example.com'
48+ self.assertEqual("%s <%s>" % (debemail, debemail),
49+ Maintainer.clean(debemail))
50+
51+ def test_clean_email_in_brackets(self):
52+ # An email in brackets is duplicated minus the quotes
53+ debemail = 'dude@example.com'
54+ self.assertEqual("%s <%s>" % (debemail, debemail),
55+ Maintainer.clean("<%s>" % debemail))
56+
57+ def test_clean_name(self):
58+ # A name is given an example email address
59+ debemail = 'Dude'
60+ self.assertEqual("%s <person@example.com>" % (debemail,),
61+ Maintainer.clean(debemail))
62+
63+ def test_name_in_brackets(self):
64+ # A name in brackets is given an example email address
65+ debemail = 'Dude'
66+ self.assertEqual("%s <person@example.com>" % (debemail,),
67+ Maintainer.clean("<%s>" % debemail))
68+
69
70 class TestPackageName(TestCase):
71
72
73=== modified file 'pkgme/tests/test_package_files.py'
74--- pkgme/tests/test_package_files.py 2012-06-01 15:27:15 +0000
75+++ pkgme/tests/test_package_files.py 2012-06-04 17:00:26 +0000
76@@ -330,7 +330,7 @@
77 ControlStanzaHasField(1, "Priority", "extra"))
78
79 def test_get_contents_sets_maintainer(self):
80- maintainer = self.getUniqueString()
81+ maintainer = "%s <dude@example.com>" % (self.getUniqueString(),)
82 args = {Maintainer.name: maintainer}
83 package_file = self.get_object(args)
84 self.assertThat(
85
86=== modified file 'pkgme/tests/test_script.py'
87--- pkgme/tests/test_script.py 2012-02-01 18:16:07 +0000
88+++ pkgme/tests/test_script.py 2012-06-04 17:00:26 +0000
89@@ -3,7 +3,10 @@
90 import pkg_resources
91 from StringIO import StringIO
92
93-from fixtures import MonkeyPatch
94+from fixtures import (
95+ EnvironmentVariableFixture,
96+ MonkeyPatch,
97+ )
98 from testtools import TestCase
99 from testtools.matchers import Not
100
101@@ -26,6 +29,14 @@
102 class ScriptTests(TestCase):
103 """Smoke tests for the top-level pkgme script."""
104
105+ def setUp(self):
106+ super(ScriptTests, self).setUp()
107+ # The DEBEMAIL environment variable is consulted when the
108+ # pacakging is written, so set it to a known value for proper
109+ # isolation
110+ debemail = 'Dude <dude@example.com>'
111+ self.useFixture(EnvironmentVariableFixture('DEBEMAIL', debemail))
112+
113 def run_script(self, cwd, argv=None):
114 if argv is None:
115 argv = []

Subscribers

People subscribed via source and target branches

to all changes: