Merge lp:~vila/bzr-builddeb/904704-safe-decode-changelogs into lp:bzr-builddeb

Proposed by Vincent Ladeuil
Status: Merged
Approved by: James Westby
Approved revision: 663
Merged at revision: 663
Proposed branch: lp:~vila/bzr-builddeb/904704-safe-decode-changelogs
Merge into: lp:bzr-builddeb
Diff against target: 60 lines (+23/-8)
2 files modified
import_dsc.py (+11/-8)
tests/test_import_dsc.py (+12/-0)
To merge this branch: bzr merge lp:~vila/bzr-builddeb/904704-safe-decode-changelogs
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+85854@code.launchpad.net

Description of the change

While locally testing mass-import I came across import failures during the
parsing of changelog (part of python-debian).

It turns out I'm locally using oneiric with python-debian-0.1.20ubuntu2
while jubany is still using 0.1.14ubuntu2.

Based on a discussion on IRC, this fixes the issue in a way that should be
compatible with all versions.

I've tested locally against python-debian-0.1.20ubuntu2.

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 'import_dsc.py'
2--- import_dsc.py 2011-12-02 11:53:30 +0000
3+++ import_dsc.py 2011-12-15 12:54:25 +0000
4@@ -997,12 +997,8 @@
5 changelog_path = os.path.join(self.tree.basedir, 'debian',
6 'changelog')
7 if os.path.exists(changelog_path):
8- f = open(changelog_path)
9- try:
10- changelog_contents = f.read()
11- finally:
12- f.close()
13- changelog = Changelog(file=changelog_contents, max_blocks=1)
14+ changelog = self.get_changelog_from_source(
15+ self.tree.basedir, max_blocks=1)
16 message, authors, thanks, bugs = \
17 get_commit_info_from_changelog(changelog, self.branch)
18 if message is None:
19@@ -1077,10 +1073,17 @@
20 # FIXME: What about other versions ?
21 return { None: parents }
22
23- def get_changelog_from_source(self, dir):
24+ def get_changelog_from_source(self, dir, max_blocks=None):
25 cl_filename = os.path.join(dir, "debian", "changelog")
26+ content = open(cl_filename).read()
27+ # Older versions of python-debian were accepting various encodings in
28+ # the changelog. This is not true with 0.1.20ubuntu2 at least which
29+ # force an 'utf-8' encoding. This leads to failures when trying to
30+ # parse old changelogs. Using safe_decode() below will fallback to
31+ # iso-8859-1 (latin_1) in this case.
32+ content = safe_decode(content)
33 cl = Changelog()
34- cl.parse_changelog(open(cl_filename).read(), strict=False)
35+ cl.parse_changelog(content, strict=False, max_blocks=max_blocks)
36 return cl
37
38 def _fetch_from_branch(self, branch, revid):
39
40=== modified file 'tests/test_import_dsc.py'
41--- tests/test_import_dsc.py 2011-12-02 11:53:30 +0000
42+++ tests/test_import_dsc.py 2011-12-15 12:54:25 +0000
43@@ -1889,6 +1889,18 @@
44 builder.build()
45 self.db1.import_package(builder.dsc_name())
46
47+ def test_parsechangelog_with_latin1(self):
48+ self.build_tree_contents(
49+ [('unstable/debian/',),
50+ ('unstable/debian/changelog', u'''\
51+package (1.0-1) UNRELEASED; urgency=low
52+
53+ * Lots of work.
54+
55+ -- Jo\xe9 Master <joe@example.com> Thu, 2 Dec 2004 16:59:43 +0100
56+'''.encode('latin_1'))])
57+ cl = self.db1.get_changelog_from_source(self.db1.tree.basedir)
58+
59
60 class OneZeroSourceExtractorTests(tests.TestCaseInTempDir):
61

Subscribers

People subscribed via source and target branches