launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #23667
[Merge] lp:~cjwatson/launchpad/write-file-bytes into lp:launchpad
Colin Watson has proposed merging lp:~cjwatson/launchpad/write-file-bytes into lp:launchpad.
Commit message:
Make the write_file helper explicitly take bytes.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/write-file-bytes/+merge/367898
This makes no difference with Python 2, but will with Python 3, so we might as well sort it out now. I'm working on a branch where I want to write actual binary data using write_file, and I think this is the most sensible direction.
(Maybe eventually we should just use pathlib.)
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/write-file-bytes into lp:launchpad.
=== modified file 'lib/lp/archivepublisher/model/ftparchive.py'
--- lib/lp/archivepublisher/model/ftparchive.py 2018-05-06 08:52:34 +0000
+++ lib/lp/archivepublisher/model/ftparchive.py 2019-05-24 11:18:00 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
from collections import defaultdict
@@ -254,13 +254,13 @@
for path in needed_paths:
write_file(os.path.join(
self._config.overrideroot,
- ".".join(("override", suite) + path)), "")
+ ".".join(("override", suite) + path)), b"")
# Create empty file lists.
def touch_list(*parts):
write_file(os.path.join(
self._config.overrideroot,
- "_".join((suite, ) + parts)), "")
+ "_".join((suite, ) + parts)), b"")
touch_list(comp, "source")
arch_tags = [
=== modified file 'lib/lp/archivepublisher/tests/test_archivesigningkey.py'
--- lib/lp/archivepublisher/tests/test_archivesigningkey.py 2018-05-02 23:42:13 +0000
+++ lib/lp/archivepublisher/tests/test_archivesigningkey.py 2019-05-24 11:18:00 +0000
@@ -1,4 +1,4 @@
-# Copyright 2016-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2016-2019 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test ArchiveSigningKey."""
@@ -56,7 +56,7 @@
def test_signFile_absolute_within_archive(self):
filename = os.path.join(self.archive_root, "signme")
- write_file(filename, "sign this")
+ write_file(filename, b"sign this")
signer = ISignableArchive(self.archive)
self.assertTrue(signer.can_sign)
@@ -66,7 +66,7 @@
def test_signFile_absolute_outside_archive(self):
filename = os.path.join(self.temp_dir, "signme")
- write_file(filename, "sign this")
+ write_file(filename, b"sign this")
signer = ISignableArchive(self.archive)
self.assertTrue(signer.can_sign)
@@ -76,7 +76,7 @@
def test_signFile_relative_within_archive(self):
filename_relative = "signme"
filename = os.path.join(self.archive_root, filename_relative)
- write_file(filename, "sign this")
+ write_file(filename, b"sign this")
signer = ISignableArchive(self.archive)
self.assertTrue(signer.can_sign)
@@ -87,7 +87,7 @@
def test_signFile_relative_outside_archive(self):
filename_relative = "../signme"
filename = os.path.join(self.temp_dir, filename_relative)
- write_file(filename, "sign this")
+ write_file(filename, b"sign this")
signer = ISignableArchive(self.archive)
self.assertTrue(signer.can_sign)
@@ -125,7 +125,7 @@
def test_signRepository_runs_parts(self):
suite_dir = os.path.join(self.archive_root, "dists", self.suite)
release_path = os.path.join(suite_dir, "Release")
- write_file(release_path, "Release contents")
+ write_file(release_path, b"Release contents")
signer = ISignableArchive(self.archive)
self.assertTrue(signer.can_sign)
@@ -150,7 +150,7 @@
pubconf.distsroot = self.makeTemporaryDirectory()
suite_dir = os.path.join(pubconf.distsroot, self.suite)
release_path = os.path.join(suite_dir, "Release")
- write_file(release_path, "Release contents")
+ write_file(release_path, b"Release contents")
signer = ISignableArchive(self.archive)
self.assertTrue(signer.can_sign)
@@ -174,7 +174,7 @@
def test_signFile_runs_parts(self):
filename = os.path.join(self.archive_root, "signme")
- write_file(filename, "sign this")
+ write_file(filename, b"sign this")
signer = ISignableArchive(self.archive)
self.assertTrue(signer.can_sign)
=== modified file 'lib/lp/archivepublisher/tests/test_customupload.py'
--- lib/lp/archivepublisher/tests/test_customupload.py 2018-03-28 09:30:48 +0000
+++ lib/lp/archivepublisher/tests/test_customupload.py 2019-05-24 11:18:00 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for `CustomUploads`."""
@@ -256,7 +256,7 @@
def test_sign_with_signing_key(self):
filename = os.path.join(
getPubConfig(self.archive).archiveroot, "file")
- write_file(filename, "contents")
+ write_file(filename, b"contents")
self.assertIsNone(self.archive.signing_key)
self.useFixture(InProcessKeyServerFixture()).start()
key_path = os.path.join(gpgkeysdir, 'ppa-sample@xxxxxxxxxxxxxxxxx')
@@ -277,7 +277,7 @@
self.enableRunParts(distribution_name=self.distro.name)
archiveroot = getPubConfig(self.archive).archiveroot
filename = os.path.join(archiveroot, "file")
- write_file(filename, "contents")
+ write_file(filename, b"contents")
self.assertIsNone(self.archive.signing_key)
run_parts_fixture = self.useFixture(MonkeyPatch(
"lp.archivepublisher.archivesigningkey.run_parts", FakeMethod()))
=== modified file 'lib/lp/archivepublisher/tests/test_generate_contents_files.py'
--- lib/lp/archivepublisher/tests/test_generate_contents_files.py 2018-02-02 11:40:34 +0000
+++ lib/lp/archivepublisher/tests/test_generate_contents_files.py 2019-05-24 11:18:00 +0000
@@ -1,4 +1,4 @@
-# Copyright 2011-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2011-2019 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test for the `generate-contents-files` script."""
@@ -42,16 +42,16 @@
for suffix in suffixes:
write_file(os.path.join(
script.config.overrideroot,
- "override.%s.%s" % (distroseries.name, suffix)), "")
+ "override.%s.%s" % (distroseries.name, suffix)), b"")
for component in components:
write_file(os.path.join(
script.config.overrideroot,
- "%s_%s_source" % (distroseries.name, component)), "")
+ "%s_%s_source" % (distroseries.name, component)), b"")
for arch in architectures:
write_file(os.path.join(
script.config.overrideroot,
- "%s_%s_binary-%s" % (distroseries.name, component, arch)), "")
+ "%s_%s_binary-%s" % (distroseries.name, component, arch)), b"")
class TestHelpers(TestCaseWithFactory):
=== modified file 'lib/lp/archivepublisher/tests/test_generate_ppa_htaccess.py'
--- lib/lp/archivepublisher/tests/test_generate_ppa_htaccess.py 2018-02-02 11:40:34 +0000
+++ lib/lp/archivepublisher/tests/test_generate_ppa_htaccess.py 2019-05-24 11:18:00 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test the generate_ppa_htaccess.py script. """
@@ -161,7 +161,7 @@
def testReplaceUpdatedHtpasswd(self):
"""Test that the htpasswd file is only replaced if it changes."""
- FILE_CONTENT = "Kneel before Zod!"
+ FILE_CONTENT = b"Kneel before Zod!"
# The publisher Config object does not have an interface, so we
# need to remove the security wrapper.
pub_config = getPubConfig(self.ppa)
@@ -174,7 +174,7 @@
# Write the same contents in a temp file.
def write_tempfile():
fd, temp_filename = tempfile.mkstemp(dir=pub_config.archiveroot)
- file = os.fdopen(fd, "w")
+ file = os.fdopen(fd, "wb")
file.write(FILE_CONTENT)
file.close()
return temp_filename
@@ -188,7 +188,7 @@
self.assertFalse(os.path.exists(temp_filename))
# Writing a different .htpasswd should see it get replaced.
- write_file(filename, "Come to me, son of Jor-El!")
+ write_file(filename, b"Come to me, son of Jor-El!")
temp_filename = write_tempfile()
self.assertTrue(os.path.exists(temp_filename))
=== modified file 'lib/lp/archivepublisher/tests/test_publish_ftpmaster.py'
--- lib/lp/archivepublisher/tests/test_publish_ftpmaster.py 2018-03-02 18:35:42 +0000
+++ lib/lp/archivepublisher/tests/test_publish_ftpmaster.py 2019-05-24 11:18:00 +0000
@@ -1,4 +1,4 @@
-# Copyright 2011-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2011-2019 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test publish-ftpmaster cron script."""
@@ -167,30 +167,30 @@
self.assertFalse(newer_mtime(self.a, self.b))
def test_one_missing(self):
- write_file(self.b, "")
+ write_file(self.b, b"")
self.assertFalse(newer_mtime(self.a, self.b))
def test_other_missing(self):
- write_file(self.a, "")
+ write_file(self.a, b"")
self.assertTrue(newer_mtime(self.a, self.b))
def test_older(self):
- write_file(self.a, "")
+ write_file(self.a, b"")
os.utime(self.a, (0, 0))
- write_file(self.b, "")
+ write_file(self.b, b"")
self.assertFalse(newer_mtime(self.a, self.b))
def test_equal(self):
now = time.time()
- write_file(self.a, "")
+ write_file(self.a, b"")
os.utime(self.a, (now, now))
- write_file(self.b, "")
+ write_file(self.b, b"")
os.utime(self.b, (now, now))
self.assertFalse(newer_mtime(self.a, self.b))
def test_newer(self):
- write_file(self.a, "")
- write_file(self.b, "")
+ write_file(self.a, b"")
+ write_file(self.b, b"")
os.utime(self.b, (0, 0))
self.assertTrue(newer_mtime(self.a, self.b))
=== modified file 'lib/lp/archivepublisher/tests/test_signing.py'
--- lib/lp/archivepublisher/tests/test_signing.py 2018-08-03 16:11:48 +0000
+++ lib/lp/archivepublisher/tests/test_signing.py 2019-05-24 11:18:00 +0000
@@ -1,4 +1,4 @@
-# Copyright 2012-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2012-2019 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test UEFI custom uploads."""
@@ -102,33 +102,33 @@
if description == "UEFI signing":
filename = cmdl[-1]
if filename.endswith(".efi"):
- write_file(filename + ".signed", "")
+ write_file(filename + ".signed", b"")
elif description == "UEFI keygen":
- write_file(self.upload.uefi_key, "")
- write_file(self.upload.uefi_cert, "")
+ write_file(self.upload.uefi_key, b"")
+ write_file(self.upload.uefi_cert, b"")
elif description == "Kmod signing":
filename = cmdl[-1]
if filename.endswith(".ko.sig"):
- write_file(filename, "")
+ write_file(filename, b"")
elif description == "Kmod keygen cert":
- write_file(self.upload.kmod_x509, "")
+ write_file(self.upload.kmod_x509, b"")
elif description == "Kmod keygen key":
- write_file(self.upload.kmod_pem, "")
+ write_file(self.upload.kmod_pem, b"")
elif description == "Opal signing":
filename = cmdl[-1]
if filename.endswith(".opal.sig"):
- write_file(filename, "")
+ write_file(filename, b"")
elif description == "Opal keygen cert":
- write_file(self.upload.opal_x509, "")
+ write_file(self.upload.opal_x509, b"")
elif description == "Opal keygen key":
- write_file(self.upload.opal_pem, "")
+ write_file(self.upload.opal_pem, b"")
else:
raise AssertionError("unknown command executed cmd=(%s)" %
@@ -194,22 +194,22 @@
self.key = os.path.join(self.signing_dir, "uefi.key")
self.cert = os.path.join(self.signing_dir, "uefi.crt")
if create:
- write_file(self.key, "")
- write_file(self.cert, "")
+ write_file(self.key, b"")
+ write_file(self.cert, b"")
def setUpKmodKeys(self, create=True):
self.kmod_pem = os.path.join(self.signing_dir, "kmod.pem")
self.kmod_x509 = os.path.join(self.signing_dir, "kmod.x509")
if create:
- write_file(self.kmod_pem, "")
- write_file(self.kmod_x509, "")
+ write_file(self.kmod_pem, b"")
+ write_file(self.kmod_x509, b"")
def setUpOpalKeys(self, create=True):
self.opal_pem = os.path.join(self.signing_dir, "opal.pem")
self.opal_x509 = os.path.join(self.signing_dir, "opal.x509")
if create:
- write_file(self.opal_pem, "")
- write_file(self.opal_x509, "")
+ write_file(self.opal_pem, b"")
+ write_file(self.opal_x509, b"")
def openArchive(self, loader_type, version, arch):
self.path = os.path.join(
=== modified file 'lib/lp/archiveuploader/tests/test_livefsupload.py'
--- lib/lp/archiveuploader/tests/test_livefsupload.py 2018-05-03 15:10:39 +0000
+++ lib/lp/archiveuploader/tests/test_livefsupload.py 2019-05-24 11:18:00 +0000
@@ -1,4 +1,4 @@
-# Copyright 2014-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2014-2019 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test uploads of LiveFSBuilds."""
@@ -57,8 +57,8 @@
self.assertFalse(self.build.verifySuccessfulUpload())
upload_dir = os.path.join(
self.incoming_folder, "test", str(self.build.id), "ubuntu")
- write_file(os.path.join(upload_dir, "ubuntu.squashfs"), "squashfs")
- write_file(os.path.join(upload_dir, "ubuntu.manifest"), "manifest")
+ write_file(os.path.join(upload_dir, "ubuntu.squashfs"), b"squashfs")
+ write_file(os.path.join(upload_dir, "ubuntu.manifest"), b"manifest")
handler = UploadHandler.forProcessor(
self.uploadprocessor, self.incoming_folder, "test", self.build)
result = handler.processLiveFS(self.log)
=== modified file 'lib/lp/archiveuploader/tests/test_nascentuploadfile.py'
--- lib/lp/archiveuploader/tests/test_nascentuploadfile.py 2018-05-03 15:10:39 +0000
+++ lib/lp/archiveuploader/tests/test_nascentuploadfile.py 2019-05-24 11:18:00 +0000
@@ -1,4 +1,4 @@
-# Copyright 2010-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2010-2019 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test NascentUploadFile functionality."""
@@ -374,7 +374,7 @@
"data.tar.%s" % data_format,
]
for member in members:
- write_file(os.path.join(tempdir, member), "")
+ write_file(os.path.join(tempdir, member), b"")
retcode = subprocess.call(
["ar", "rc", filename] + members, cwd=tempdir)
self.assertEqual(0, retcode)
=== modified file 'lib/lp/archiveuploader/tests/test_snapupload.py'
--- lib/lp/archiveuploader/tests/test_snapupload.py 2018-05-03 15:10:39 +0000
+++ lib/lp/archiveuploader/tests/test_snapupload.py 2019-05-24 11:18:00 +0000
@@ -1,4 +1,4 @@
-# Copyright 2015-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2015-2019 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Test uploads of SnapBuilds."""
@@ -55,8 +55,9 @@
self.assertFalse(self.build.verifySuccessfulUpload())
upload_dir = os.path.join(
self.incoming_folder, "test", str(self.build.id), "ubuntu")
- write_file(os.path.join(upload_dir, "wget_0_all.snap"), "snap")
- write_file(os.path.join(upload_dir, "wget_0_all.manifest"), "manifest")
+ write_file(os.path.join(upload_dir, "wget_0_all.snap"), b"snap")
+ write_file(
+ os.path.join(upload_dir, "wget_0_all.manifest"), b"manifest")
handler = UploadHandler.forProcessor(
self.uploadprocessor, self.incoming_folder, "test", self.build)
result = handler.processSnap(self.log)
@@ -72,7 +73,8 @@
self.assertFalse(self.build.verifySuccessfulUpload())
upload_dir = os.path.join(
self.incoming_folder, "test", str(self.build.id), "ubuntu")
- write_file(os.path.join(upload_dir, "wget_0_all.manifest"), "manifest")
+ write_file(
+ os.path.join(upload_dir, "wget_0_all.manifest"), b"manifest")
handler = UploadHandler.forProcessor(
self.uploadprocessor, self.incoming_folder, "test", self.build)
result = handler.processSnap(self.log)
@@ -98,7 +100,7 @@
self.assertFalse(self.build.verifySuccessfulUpload())
upload_dir = os.path.join(
self.incoming_folder, "test", str(self.build.id), "ubuntu")
- write_file(os.path.join(upload_dir, "wget_0_all.snap"), "snap")
+ write_file(os.path.join(upload_dir, "wget_0_all.snap"), b"snap")
handler = UploadHandler.forProcessor(
self.uploadprocessor, self.incoming_folder, "test", self.build)
result = handler.processSnap(self.log)
=== modified file 'lib/lp/services/apachelogparser/tests/test_apachelogparser.py'
--- lib/lp/services/apachelogparser/tests/test_apachelogparser.py 2018-02-14 11:13:47 +0000
+++ lib/lp/services/apachelogparser/tests/test_apachelogparser.py 2019-05-24 11:18:00 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
from datetime import datetime
@@ -395,7 +395,7 @@
file_paths = [root.join(str(name)) for name in range(3)]
now = time.time()
for i, path in enumerate(file_paths):
- write_file(path, '%s\n' % i)
+ write_file(path, ('%s\n' % i).encode('UTF-8'))
os.utime(path, (now - i, now - i))
contents = []
for fd, _ in get_files_to_parse(file_paths):
=== modified file 'lib/lp/services/osutils.py'
--- lib/lp/services/osutils.py 2018-08-10 09:50:35 +0000
+++ lib/lp/services/osutils.py 2019-05-24 11:18:00 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Utilities for doing the sort of thing the os module does."""
@@ -185,7 +185,7 @@
def write_file(path, content):
- with open_for_writing(path, 'w') as f:
+ with open_for_writing(path, 'wb') as f:
f.write(content)
=== modified file 'lib/lp/services/tests/test_osutils.py'
--- lib/lp/services/tests/test_osutils.py 2018-03-27 17:43:27 +0000
+++ lib/lp/services/tests/test_osutils.py 2019-05-24 11:18:00 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for lp.services.osutils."""
@@ -122,7 +122,7 @@
temp_dir = self.makeTemporaryDirectory()
bin_dir = os.path.join(temp_dir, "bin")
program = os.path.join(bin_dir, "program")
- write_file(program, "")
+ write_file(program, b"")
os.chmod(program, 0o755)
self.useFixture(EnvironmentVariable("PATH", bin_dir))
self.assertTrue(find_on_path("program"))
@@ -130,7 +130,7 @@
def test_present_not_executable(self):
temp_dir = self.makeTemporaryDirectory()
bin_dir = os.path.join(temp_dir, "bin")
- write_file(os.path.join(bin_dir, "program"), "")
+ write_file(os.path.join(bin_dir, "program"), b"")
self.useFixture(EnvironmentVariable("PATH", bin_dir))
self.assertFalse(find_on_path("program"))
=== modified file 'lib/lp/services/tests/test_timeout.py'
--- lib/lp/services/tests/test_timeout.py 2019-03-18 11:58:18 +0000
+++ lib/lp/services/tests/test_timeout.py 2019-05-24 11:18:00 +0000
@@ -425,7 +425,7 @@
def test_urlfetch_does_not_support_file_urls_by_default(self):
"""urlfetch() does not support file urls by default."""
test_path = self.useFixture(TempDir()).join('file')
- write_file(test_path, '')
+ write_file(test_path, b'')
url = 'file://' + test_path
e = self.assertRaises(InvalidSchema, urlfetch, url)
self.assertEqual(
@@ -434,7 +434,7 @@
def test_urlfetch_supports_file_urls_if_allow_file(self):
"""urlfetch() supports file urls if explicitly asked to do so."""
test_path = self.useFixture(TempDir()).join('file')
- write_file(test_path, 'Success.')
+ write_file(test_path, b'Success.')
url = 'file://' + test_path
self.assertThat(urlfetch(url, allow_file=True), MatchesStructure(
status_code=Equals(200),
=== modified file 'lib/lp/soyuz/scripts/tests/test_gina.py'
--- lib/lp/soyuz/scripts/tests/test_gina.py 2019-04-28 16:31:30 +0000
+++ lib/lp/soyuz/scripts/tests/test_gina.py 2019-05-24 11:18:00 +0000
@@ -399,7 +399,7 @@
sp_data.date_uploaded = UTC_NOW
# We don't need a real .dsc here.
write_file(
- os.path.join(archive_root, "pool/main/f/foo/foo_1.0-1.dsc"), "x")
+ os.path.join(archive_root, "pool/main/f/foo/foo_1.0-1.dsc"), b"x")
spr = sphandler.createSourcePackageRelease(sp_data, series)
self.assertIsNotNone(spr)
self.assertEqual(
@@ -490,7 +490,7 @@
# We don't need a real .deb here.
write_file(
os.path.join(archive_root, "pool/main/f/foo/foo_1.0-1_amd64.deb"),
- "x")
+ b"x")
bpr = bphandler.createBinaryPackage(bp_data, spr, das, "amd64")
self.assertIsNotNone(bpr)
self.assertEqual([["Python-Version", "2.7"]], bpr.user_defined_fields)
Follow ups