Merge lp:~cjwatson/launchpad/publisher-xz-checksums into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18892
Proposed branch: lp:~cjwatson/launchpad/publisher-xz-checksums
Merge into: lp:launchpad
Diff against target: 93 lines (+48/-2)
2 files modified
lib/lp/archivepublisher/publishing.py (+9/-1)
lib/lp/archivepublisher/tests/test_publisher.py (+39/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/publisher-xz-checksums
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+363438@code.launchpad.net

Commit message

Teach Publisher._readIndexFileHashes to compute uncompressed checksums of .xz files.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/archivepublisher/publishing.py'
2--- lib/lp/archivepublisher/publishing.py 2018-05-08 15:18:43 +0000
3+++ lib/lp/archivepublisher/publishing.py 2019-02-20 16:32:05 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 __all__ = [
10@@ -19,6 +19,7 @@
11 timedelta,
12 )
13 import errno
14+from functools import partial
15 import gzip
16 import hashlib
17 from itertools import (
18@@ -34,6 +35,10 @@
19 _multivalued,
20 Release,
21 )
22+try:
23+ import lzma
24+except ImportError:
25+ from backports import lzma
26 import scandir
27 from storm.expr import Desc
28 from zope.component import getUtility
29@@ -1417,6 +1422,9 @@
30 elif os.path.exists(full_name + '.bz2'):
31 open_func = bz2.BZ2File
32 full_name = full_name + '.bz2'
33+ elif os.path.exists(full_name + '.xz'):
34+ open_func = partial(lzma.LZMAFile, format=lzma.FORMAT_XZ)
35+ full_name = full_name + '.xz'
36 else:
37 # The file we were asked to write out doesn't exist.
38 # Most likely we have an incomplete archive (e.g. no sources
39
40=== modified file 'lib/lp/archivepublisher/tests/test_publisher.py'
41--- lib/lp/archivepublisher/tests/test_publisher.py 2018-05-08 15:18:43 +0000
42+++ lib/lp/archivepublisher/tests/test_publisher.py 2019-02-20 16:32:05 +0000
43@@ -1,4 +1,4 @@
44-# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
45+# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
46 # GNU Affero General Public License version 3 (see the file LICENSE).
47
48 """Tests for publisher class."""
49@@ -2408,6 +2408,44 @@
50
51 self.assertFalse(os.path.exists(os.path.join(i18n_root, 'Index')))
52
53+ def testReadIndexFileHashesCompression(self):
54+ """Test compressed file handling in _readIndexFileHashes."""
55+ publisher = Publisher(
56+ self.logger, self.config, self.disk_pool,
57+ self.ubuntutest.main_archive)
58+ contents = b'test'
59+ path = os.path.join(
60+ publisher._config.distsroot, 'breezy-autotest', 'Test')
61+ os.makedirs(os.path.dirname(path))
62+ for suffix, open_func in (
63+ ('', open),
64+ ('.gz', gzip.open),
65+ ('.bz2', bz2.BZ2File),
66+ ('.xz', partial(lzma.LZMAFile, format=lzma.FORMAT_XZ)),
67+ ):
68+ with open_func(path + suffix, mode='wb') as f:
69+ f.write(contents)
70+ self.assertEqual(
71+ {
72+ 'md5sum': {
73+ 'md5sum': hashlib.md5(contents).hexdigest(),
74+ 'name': 'Test',
75+ 'size': len(contents),
76+ },
77+ 'sha1': {
78+ 'sha1': hashlib.sha1(contents).hexdigest(),
79+ 'name': 'Test',
80+ 'size': len(contents),
81+ },
82+ 'sha256': {
83+ 'sha256': hashlib.sha256(contents).hexdigest(),
84+ 'name': 'Test',
85+ 'size': len(contents),
86+ },
87+ },
88+ publisher._readIndexFileHashes('breezy-autotest', 'Test'))
89+ os.remove(path + suffix)
90+
91
92 class TestArchiveIndices(TestPublisherBase):
93 """Tests for the native publisher's index generation.