Merge lp:~brian.curtin/ubuntuone-dev-tools/py3-dbus-str into lp:ubuntuone-dev-tools

Proposed by Brian Curtin on 2012-08-28
Status: Merged
Approved by: Brian Curtin on 2012-08-31
Approved revision: 100
Merged at revision: 95
Proposed branch: lp:~brian.curtin/ubuntuone-dev-tools/py3-dbus-str
Merge into: lp:ubuntuone-dev-tools
Prerequisite: lp:~brian.curtin/ubuntuone-dev-tools/py3-bytes-formatting
Diff against target: 47 lines (+12/-5)
2 files modified
ubuntuone/devtools/services/dbus.py (+6/-3)
ubuntuone/devtools/testcases/dbus.py (+6/-2)
To merge this branch: bzr merge lp:~brian.curtin/ubuntuone-dev-tools/py3-dbus-str
Reviewer Review Type Date Requested Status
dobey (community) Approve on 2012-08-31
Manuel de la Peña (community) 2012-08-28 Approve on 2012-08-30
Review via email: mp+121712@code.launchpad.net

Commit Message

- Sort out dbus related bytes/string differences surrounding subprocess pipes, environment variables, and a dbus API expecting a str argument regardless of version.

Description of the Change

subprocess pipes return byte strings, so implicit strings were converted to explicitly be bytes in order to join on them with data from the pipe. Additionally, os.environ expects Unicode, so we decode the byte string that we joined from the pipe.

dbus.bus.BusConnection expects the first argument to be str regardless of version, so we explicitly give it an str. I added a comment there so we avoid trying to use any compatibility layer there, e.g., ubuntuone.devtools.compat which solves some str/bytes differences.

To post a comment you must log in.
review: Approve
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/devtools/services/dbus.py'
2--- ubuntuone/devtools/services/dbus.py 2012-08-20 22:10:29 +0000
3+++ ubuntuone/devtools/services/dbus.py 2012-08-28 21:59:18 +0000
4@@ -29,6 +29,8 @@
5 # files in the program, then also delete it here.
6 """Utilities for finding and running a dbus session bus for testing."""
7
8+from __future__ import unicode_literals
9+
10 import os
11 import signal
12 import subprocess
13@@ -96,11 +98,12 @@
14 # Call wait here as under the qt4 reactor we get an error about
15 # interrupted system call if we don't.
16 sp.wait()
17- self.dbus_address = "".join(sp.stdout.readlines()).strip()
18- self.dbus_pid = int("".join(sp.stderr.readlines()).strip())
19+ self.dbus_address = b"".join(sp.stdout.readlines()).strip()
20+ self.dbus_pid = int(b"".join(sp.stderr.readlines()).strip())
21
22 if self.dbus_address != "":
23- os.environ["DBUS_SESSION_BUS_ADDRESS"] = self.dbus_address
24+ os.environ["DBUS_SESSION_BUS_ADDRESS"] = \
25+ self.dbus_address.decode("utf8")
26 else:
27 os.kill(self.dbus_pid, signal.SIGKILL)
28 raise DBusLaunchError("There was a problem launching dbus-daemon.")
29
30=== modified file 'ubuntuone/devtools/testcases/dbus.py'
31--- ubuntuone/devtools/testcases/dbus.py 2012-08-21 18:51:05 +0000
32+++ ubuntuone/devtools/testcases/dbus.py 2012-08-28 21:59:18 +0000
33@@ -107,8 +107,12 @@
34
35 # Set up the main loop and bus connection
36 self.loop = DBusGMainLoop(set_as_default=True)
37- self.bus = dbus.bus.BusConnection(address_or_type=bus_address,
38- mainloop=self.loop)
39+
40+ # NOTE: The address_or_type value must remain explicitly as
41+ # str instead of anything from ubuntuone.devtools.compat. dbus
42+ # expects this to be str regardless of version.
43+ self.bus = dbus.bus.BusConnection(address_or_type=str(bus_address),
44+ mainloop=self.loop)
45
46 # Monkeypatch the dbus.SessionBus/SystemBus methods, to ensure we
47 # always point at our own private bus instance.

Subscribers

People subscribed via source and target branches

to all changes: