@@ -1,11 +1,29 @@
1−import subprocess
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3+# Unity Autopilot Utilities
4+# Copyright (C) 2013 Canonical
6+# This program is free software: you can redistribute it and/or modify
7+# it under the terms of the GNU General Public License as published by
8+# the Free Software Foundation, either version 3 of the License, or
9+# (at your option) any later version.
11+# This program is distributed in the hope that it will be useful,
12+# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+# GNU General Public License for more details.
16+# You should have received a copy of the GNU General Public License
17+# along with this program. If not, see <http://www.gnu.org/licenses/>.
3from autopilot.introspection import (
20from autopilot.introspection import (
4 get_proxy_object_for_existing_process,
21 get_proxy_object_for_existing_process,
5 ProcessSearchError,
22 ProcessSearchError,
7−from unity8.shell.emulators.main_window import MainWindow
24+import subprocess
8from unity8.shell.emulators import UnityEmulatorBase
25from unity8.shell.emulators import UnityEmulatorBase
26+from unity8.shell.emulators.main_window import MainWindow
11class CannotAccessUnity(Exception):
29class CannotAccessUnity(Exception):
@@ -40,15 +58,24 @@ def unlock_unity():
40 except ProcessSearchError as e:
58 except ProcessSearchError as e:
41 raise CannotAccessUnity(
59 raise CannotAccessUnity(
42 "Cannot introspect unity, make sure that it has been started "
60 "Cannot introspect unity, make sure that it has been started "
43− "with 'testability' (%s)" % e.message
61+ "with testability. Perhaps use the function "
62+ "'restart_unity_with_testability' this module provides."
47def restart_unity_with_testability():
68def restart_unity_with_testability():
69+ """Restarts (or just starts) unity8 with the testability driver loaded
71+ :raises: subprocess.CalledProcessError if unable to stop or start the
48 status = _get_unity_status()
75 status = _get_unity_status()
49 if "start/" in status:
76 if "start/" in status:
51− print "Stopping unity."
78+ print("Stopping unity.")
52 subprocess.check_call([
79 subprocess.check_call([
53 'initctl',
80 'initctl',
@@ -59,7 +86,7 @@ def restart_unity_with_testability():
62− print "Stopping unity with testability."
89+ print("Starting unity with testability.")
63 subprocess.check_call([
90 subprocess.check_call([
64 'initctl',
91 'initctl',
@@ -79,7 +106,7 @@ def _get_unity_status():
81 except subprocess.CalledProcessError as e:
108 except subprocess.CalledProcessError as e:
82− raise CannotAccessUnity("Unable to get unity's status: %s" % e.message)
109+ raise CannotAccessUnity("Unable to get unity's status: %s" % str(e))
85def _get_unity_pid():
112def _get_unity_pid():