Merge lp:~mterry/auto-upgrade-testing/str-buffer into lp:~auto-upgrade-testing-dev/auto-upgrade-testing/trunk

Proposed by Michael Terry
Status: Merged
Merged at revision: 32
Proposed branch: lp:~mterry/auto-upgrade-testing/str-buffer
Merge into: lp:~auto-upgrade-testing-dev/auto-upgrade-testing/trunk
Diff against target: 37 lines (+4/-4)
1 file modified
AutoUpgradeTester/UpgradeTestBackendQemu.py (+4/-4)
To merge this branch: bzr merge lp:~mterry/auto-upgrade-testing/str-buffer
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+113780@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

On Fri, Jul 06, 2012 at 05:36:26PM -0000, Michael Terry wrote:
> interfaces = tempfile.NamedTemporaryFile()
> - interfaces.write("""
> + interfaces.write(bytes("""

You can use b"""...""" rather than bytes(). But this is really text
data, so I recommend instead simply opening the file in text mode:

  interfaces = tempfile.NamedTemporaryFile(mode="w+")

... and similarly for the other occurrences. (You can add
encoding="UTF-8" if you need it, but it looks like you shouldn't.)

32. By Michael Terry

fix mode of tempfiles to accept strings

Revision history for this message
Michael Terry (mterry) wrote :

Updated to use the mode="w+" method, which is certainly cleaner. Thanks, Colin!

This branch is ready to be re-reviewed.

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'AutoUpgradeTester/UpgradeTestBackendQemu.py'
2--- AutoUpgradeTester/UpgradeTestBackendQemu.py 2012-06-15 09:53:41 +0000
3+++ AutoUpgradeTester/UpgradeTestBackendQemu.py 2012-07-09 21:04:24 +0000
4@@ -247,7 +247,7 @@
5 # going into the VM with ssh)
6 nm = self.config.getWithDefault("NonInteractive","WorkaroundNetworkManager","")
7 if nm:
8- interfaces = tempfile.NamedTemporaryFile()
9+ interfaces = tempfile.NamedTemporaryFile(mode="w+")
10 interfaces.write("""
11 auto lo
12 iface lo inet loopback
13@@ -264,7 +264,7 @@
14 # generate hosts file, the default hosts file contains
15 # "127.0.0.1 ubuntu. ubuntu" for some reason and the missing
16 # domain part after the "." makes e.g. postfix rather unhappy
17- etc_hosts = tempfile.NamedTemporaryFile()
18+ etc_hosts = tempfile.NamedTemporaryFile(mode="w+")
19 etc_hosts.write('127.0.0.1 localhost\n')
20 etc_hosts.write('127.0.0.1 upgrade-test-vm\n')
21 etc_hosts.flush()
22@@ -273,13 +273,13 @@
23 # generate apt.conf
24 proxy = self.config.getWithDefault("NonInteractive","Proxy","")
25 if proxy:
26- aptconf = tempfile.NamedTemporaryFile()
27+ aptconf = tempfile.NamedTemporaryFile(mode="w+")
28 aptconf.write('Acquire::http::proxy "%s";' % proxy)
29 aptconf.flush()
30 self._copyToImage(aptconf.name, "/etc/apt/apt.conf")
31
32 # tzdata is unhappy without that file
33- tzone = tempfile.NamedTemporaryFile()
34+ tzone = tempfile.NamedTemporaryFile(mode="w+")
35 tzone.write("Europe/Berlin")
36 tzone.flush()
37 self._copyToImage(tzone.name, "/etc/timezone")

Subscribers

People subscribed via source and target branches