Merge lp:~mikemc/ubuntu-sso-client/use-dirspec-get-program-path into lp:ubuntu-sso-client

Proposed by Mike McCracken
Status: Merged
Approved by: Mike McCracken
Approved revision: 994
Merged at revision: 986
Proposed branch: lp:~mikemc/ubuntu-sso-client/use-dirspec-get-program-path
Merge into: lp:ubuntu-sso-client
Diff against target: 509 lines (+80/-138)
10 files modified
ubuntu_sso/__init__.py (+3/-6)
ubuntu_sso/credentials.py (+9/-13)
ubuntu_sso/main/__init__.py (+0/-2)
ubuntu_sso/main/darwin.py (+3/-17)
ubuntu_sso/main/tests/test_windows.py (+0/-18)
ubuntu_sso/main/windows.py (+3/-14)
ubuntu_sso/tests/test_credentials.py (+18/-37)
ubuntu_sso/utils/__init__.py (+29/-7)
ubuntu_sso/utils/tests/test_common.py (+1/-10)
ubuntu_sso/utils/webclient/common.py (+14/-14)
To merge this branch: bzr merge lp:~mikemc/ubuntu-sso-client/use-dirspec-get-program-path
Reviewer Review Type Date Requested Status
dobey (community) Approve
Brian Curtin (community) Approve
Review via email: mp+114690@code.launchpad.net

Commit message

- Use dirspec get_program_path for cross-platform executable path finding.

Description of the change

- Use dirspec get_program_path for cross-platform executable path finding.

Adds support for darwin packaged paths, and changes packaged windows to always use sys.executable-relative paths, instead of sometimes using paths from the registry and sometimes using executable.

NOTE: to test, needs current trunk of dirspec. On mac and windows, I just moved the dirspec in the buildout eggs/ directory and hacked the PYTHONPATH.

To post a comment you must log in.
Revision history for this message
Brian Curtin (brian.curtin) wrote :

Looks fine. The change on line 18 of the diff to wrap the imports in parentheses isn't necessary but isn't hurting anything either.

review: Approve
Revision history for this message
dobey (dobey) wrote :

198 + return get_bin_cmd('ubuntu-sso-login')

There are a few uses of this, so perhaps we want to define a constant for this string as well?

review: Needs Information
Revision history for this message
Mike McCracken (mikemc) wrote :

rev 993 removes the code in ubuntu_sso/__init__ that added .exe to two of the four program names that sso can launch.

I confirmed that leaving this in does break launching e.g. ubuntu-sso-login-qt.exe from ubuntuone-control-panel.exe in a packaged windows app.

The two executables that weren't being added are the proxy & SSL cert ones launched using utils/runner/qt.py's spawn_program(), which has code intended to make the paths work on windows in development mode (unfrozen) - it checks to see if the program name ends in 'exe', and if it doesn't, it runs it with 'python.exe program_name'. This happens to also work in frozen mode if you pass the wrong program name, but I'm not sure it's really OK. At any rate, this change avoids that code path and passes in the right program name to launch for those two.

Revision history for this message
Mike McCracken (mikemc) wrote :

Looking at this further: I had the exe's mixed up - the proxy UI was getting .exe added in ubuntu_sso/__init__ -- the two that weren't were the 'ubuntu-sso-login' backend, which had been found using the registry, and the ubuntu-sso-ssl-certificate-qt UI, which would have the problem I outlined above.

As far as I can tell from a few minutes reading through the code, that UI won't be called correctly.

Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (111.5 KiB)

The attempt to merge lp:~mikemc/ubuntu-sso-client/use-dirspec-get-program-path into lp:ubuntu-sso-client failed. Below is the output from the failed tests.

*** Running QT test suite for ubuntu_sso ***
running build
Compiled data/qt/proxy_credentials_dialog.ui into ubuntu_sso/qt/ui/proxy_credentials_dialog_ui.py
compiled data/qt/resources.qrc into ubuntu_sso/qt/ui/resources_rc.py
Compiled data/qt/setup_account.ui into ubuntu_sso/qt/ui/setup_account_ui.py
Compiled data/qt/reset_password.ui into ubuntu_sso/qt/ui/reset_password_ui.py
Compiled data/qt/network_detection.ui into ubuntu_sso/qt/ui/network_detection_ui.py
Compiled data/qt/forgotten_password.ui into ubuntu_sso/qt/ui/forgotten_password_ui.py
Compiled data/qt/ssl_dialog.ui into ubuntu_sso/qt/ui/ssl_dialog_ui.py
Compiled data/qt/success_message.ui into ubuntu_sso/qt/ui/success_message_ui.py
Compiled data/qt/loadingoverlay.ui into ubuntu_sso/qt/ui/loadingoverlay_ui.py
Compiled data/qt/current_user_sign_in.ui into ubuntu_sso/qt/ui/current_user_sign_in_ui.py
Compiled data/qt/error_message.ui into ubuntu_sso/qt/ui/error_message_ui.py
Compiled data/qt/email_verification.ui into ubuntu_sso/qt/ui/email_verification_ui.py
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/account.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/credentials.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/logger.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
creating build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/test_credentials.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/test_account.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
creating build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
copying ubuntu_sso/keyring/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
copying ubuntu_sso/keyring/linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
copying ubuntu_sso/keyring/pykeyring.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
creating build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/test_common.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/test_linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/test_pykeyring.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
creating build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/glib.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/darwin.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/windows.py -> build/lib.linu...

Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (111.4 KiB)

The attempt to merge lp:~mikemc/ubuntu-sso-client/use-dirspec-get-program-path into lp:ubuntu-sso-client failed. Below is the output from the failed tests.

*** Running QT test suite for ubuntu_sso ***
running build
Compiled data/qt/proxy_credentials_dialog.ui into ubuntu_sso/qt/ui/proxy_credentials_dialog_ui.py
compiled data/qt/resources.qrc into ubuntu_sso/qt/ui/resources_rc.py
Compiled data/qt/setup_account.ui into ubuntu_sso/qt/ui/setup_account_ui.py
Compiled data/qt/reset_password.ui into ubuntu_sso/qt/ui/reset_password_ui.py
Compiled data/qt/network_detection.ui into ubuntu_sso/qt/ui/network_detection_ui.py
Compiled data/qt/forgotten_password.ui into ubuntu_sso/qt/ui/forgotten_password_ui.py
Compiled data/qt/ssl_dialog.ui into ubuntu_sso/qt/ui/ssl_dialog_ui.py
Compiled data/qt/success_message.ui into ubuntu_sso/qt/ui/success_message_ui.py
Compiled data/qt/loadingoverlay.ui into ubuntu_sso/qt/ui/loadingoverlay_ui.py
Compiled data/qt/current_user_sign_in.ui into ubuntu_sso/qt/ui/current_user_sign_in_ui.py
Compiled data/qt/error_message.ui into ubuntu_sso/qt/ui/error_message_ui.py
Compiled data/qt/email_verification.ui into ubuntu_sso/qt/ui/email_verification_ui.py
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/account.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/credentials.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/logger.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
creating build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/test_credentials.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/test_account.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
creating build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
copying ubuntu_sso/keyring/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
copying ubuntu_sso/keyring/linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
copying ubuntu_sso/keyring/pykeyring.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
creating build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/test_common.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/test_linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/test_pykeyring.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
creating build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/glib.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/darwin.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/windows.py -> build/lib.linu...

Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (83.1 KiB)

The attempt to merge lp:~mikemc/ubuntu-sso-client/use-dirspec-get-program-path into lp:ubuntu-sso-client failed. Below is the output from the failed tests.

*** Running QT test suite for ubuntu_sso ***
running build
Compiled data/qt/proxy_credentials_dialog.ui into ubuntu_sso/qt/ui/proxy_credentials_dialog_ui.py
compiled data/qt/resources.qrc into ubuntu_sso/qt/ui/resources_rc.py
Compiled data/qt/setup_account.ui into ubuntu_sso/qt/ui/setup_account_ui.py
Compiled data/qt/reset_password.ui into ubuntu_sso/qt/ui/reset_password_ui.py
Compiled data/qt/network_detection.ui into ubuntu_sso/qt/ui/network_detection_ui.py
Compiled data/qt/forgotten_password.ui into ubuntu_sso/qt/ui/forgotten_password_ui.py
Compiled data/qt/ssl_dialog.ui into ubuntu_sso/qt/ui/ssl_dialog_ui.py
Compiled data/qt/success_message.ui into ubuntu_sso/qt/ui/success_message_ui.py
Compiled data/qt/loadingoverlay.ui into ubuntu_sso/qt/ui/loadingoverlay_ui.py
Compiled data/qt/current_user_sign_in.ui into ubuntu_sso/qt/ui/current_user_sign_in_ui.py
Compiled data/qt/error_message.ui into ubuntu_sso/qt/ui/error_message_ui.py
Compiled data/qt/email_verification.ui into ubuntu_sso/qt/ui/email_verification_ui.py
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/account.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/credentials.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/logger.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
creating build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/test_credentials.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/test_account.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
creating build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
copying ubuntu_sso/keyring/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
copying ubuntu_sso/keyring/linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
copying ubuntu_sso/keyring/pykeyring.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
creating build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/test_common.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/test_linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/test_pykeyring.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
creating build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/glib.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/darwin.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/windows.py -> build/lib.linu...

994. By Mike McCracken

re-add pylint disable messages around win32 imports

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/__init__.py'
2--- ubuntu_sso/__init__.py 2012-06-27 19:03:44 +0000
3+++ ubuntu_sso/__init__.py 2012-07-17 21:15:24 +0000
4@@ -28,8 +28,6 @@
5 # files in the program, then also delete it here.
6 """Ubuntu Single Sign On client code."""
7
8-import sys
9-
10 # DBus constants
11 DBUS_BUS_NAME = "com.ubuntu.sso"
12
13@@ -46,10 +44,9 @@
14 USER_CANCELLATION = 10
15 EXCEPTION_RAISED = 11
16
17+BACKEND_EXECUTABLE = 'ubuntu-sso-login'
18+
19 # available UIs
20+UI_SSL_DIALOG = 'ubuntu-sso-ssl-certificate-qt'
21 UI_EXECUTABLE_QT = 'ubuntu-sso-login-qt'
22 UI_PROXY_CREDS_DIALOG = 'ubuntu-sso-proxy-creds-qt'
23-
24-if getattr(sys, "frozen", None) is not None and sys.platform == "win32":
25- UI_EXECUTABLE_QT += ".exe"
26- UI_PROXY_CREDS_DIALOG += ".exe"
27
28=== modified file 'ubuntu_sso/credentials.py'
29--- ubuntu_sso/credentials.py 2012-06-27 19:03:44 +0000
30+++ ubuntu_sso/credentials.py 2012-07-17 21:15:24 +0000
31@@ -43,8 +43,6 @@
32
33 """
34
35-import os
36-
37 from functools import wraps
38
39 from twisted.internet import defer
40@@ -56,7 +54,7 @@
41 )
42 from ubuntu_sso.keyring import Keyring
43 from ubuntu_sso.logger import setup_logging
44-from ubuntu_sso.utils import get_bin_dir, runner
45+from ubuntu_sso.utils import get_bin_cmd, runner
46
47
48 logger = setup_logging('ubuntu_sso.credentials')
49@@ -173,21 +171,19 @@
50
51 """
52 guis = (self.ui_executable, UI_EXECUTABLE_QT)
53- for gui_exe_path in guis:
54- ui_exe_path = os.path.join(get_bin_dir(), gui_exe_path)
55- ui_exe_exists = os.path.exists(ui_exe_path)
56- logger.debug('Attempting to use the following executable as GUI: '
57- '%r (exists? %r).', ui_exe_path, ui_exe_exists)
58- if not ui_exe_exists:
59- logger.error('The given UI path %r does not exist.',
60- ui_exe_path)
61+ for gui_exe_name in guis:
62+ try:
63+ args = get_bin_cmd(gui_exe_name)
64+ except OSError:
65+ logger.error('The given UI %r does not exist.',
66+ gui_exe_name)
67 else:
68 break
69 else:
70 raise GUINotAvailableError('Can not find a GUI to present to the '
71- 'user (tried with %r). Aborting.' % repr(guis))
72+ 'user (tried with %r). Aborting.' %
73+ repr(guis))
74
75- args = [ui_exe_path]
76 for arg in ('app_name', 'help_text', 'ping_url', 'policy_url',
77 'tc_url', 'window_id'):
78 value = getattr(self, arg)
79
80=== modified file 'ubuntu_sso/main/__init__.py'
81--- ubuntu_sso/main/__init__.py 2012-06-22 16:51:06 +0000
82+++ ubuntu_sso/main/__init__.py 2012-07-17 21:15:24 +0000
83@@ -94,12 +94,10 @@
84 else:
85 from ubuntu_sso.main import linux as source
86
87- source.get_activation_cmdline = lambda *args: None
88
89 UbuntuSSOClient = source.UbuntuSSOClient
90 UbuntuSSOProxy = source.UbuntuSSOProxy
91 get_sso_client = source.get_sso_client
92-get_activation_cmdline = source.get_activation_cmdline
93
94
95 def except_to_errdict(e):
96
97=== modified file 'ubuntu_sso/main/darwin.py'
98--- ubuntu_sso/main/darwin.py 2012-05-21 14:38:23 +0000
99+++ ubuntu_sso/main/darwin.py 2012-07-17 21:15:24 +0000
100@@ -31,8 +31,9 @@
101 from dirspec import basedir
102 from twisted.internet import defer
103
104-import ubuntu_sso
105+from ubuntu_sso import BACKEND_EXECUTABLE
106 from ubuntu_sso.logger import setup_logging
107+from ubuntu_sso.utils import get_bin_cmd
108 from ubuntu_sso.utils.ipc import BaseClient
109 from ubuntu_sso.main.perspective_broker import (
110 SSO_SERVICE_NAME,
111@@ -55,21 +56,6 @@
112 return path
113
114
115-def get_activation_cmdline(name):
116- """Find the path to the executable callback."""
117- # TODO: We have to either use launchd to launch the different services
118- # on demand or us LaunchServices to handle running the app via an URL.
119- ubuntu_sso_pkg_dir = os.path.dirname(os.path.dirname(ubuntu_sso.__file__))
120- ubuntu_sso_bin_dir = os.path.join(ubuntu_sso_pkg_dir, 'bin')
121- ubuntu_sso_bin = os.path.join(ubuntu_sso_bin_dir, 'ubuntu-sso-login')
122- ubuntuone_client_bin_dir = os.path.join(ubuntu_sso_pkg_dir,
123- '../ubuntuone-client/bin')
124- ubuntuone_client_bin = os.path.join(ubuntuone_client_bin_dir, name)
125- if os.path.exists(ubuntuone_client_bin):
126- return ubuntuone_client_bin
127- return ubuntu_sso_bin
128-
129-
130 class DescriptionFactory(object):
131 """Factory that provides the server and client descriptions."""
132
133@@ -96,7 +82,7 @@
134 @property
135 def cmdline(self):
136 """Get the command line to activate an executable."""
137- return get_activation_cmdline(self.name)
138+ return get_bin_cmd(BACKEND_EXECUTABLE)
139
140
141 class UbuntuSSOClient(BaseClient):
142
143=== modified file 'ubuntu_sso/main/tests/test_windows.py'
144--- ubuntu_sso/main/tests/test_windows.py 2012-06-27 20:16:56 +0000
145+++ ubuntu_sso/main/tests/test_windows.py 2012-07-17 21:15:24 +0000
146@@ -28,16 +28,9 @@
147 # files in the program, then also delete it here.
148 """Windows specific tests for the main module."""
149
150-# pylint: disable=F0401
151-try:
152- import winreg
153-except ImportError:
154- import _winreg as winreg
155-
156 from twisted.internet import defer
157
158 from ubuntu_sso.main import windows
159-from ubuntu_sso.main import perspective_broker
160 from ubuntu_sso.tests import TestCase
161
162 # because we are using twisted we have java like names C0103
163@@ -111,17 +104,6 @@
164 uid_modulo * windows.SSO_PORT_ALLOCATION_STEP)
165 self._test_port_assignation(uid, expected_port)
166
167- def test_get_activation_cmdline(self):
168- """Test the get_activation_cmdline method."""
169- sample_value = "test 123"
170- self.patch(windows.winreg, "OpenKey",
171- lambda key, subkey: sample_value)
172- self.patch(windows.winreg, "QueryValueEx",
173- lambda key, v: (key, winreg.REG_SZ))
174- cmdline = windows.get_activation_cmdline(
175- perspective_broker.SSO_SERVICE_NAME)
176- self.assertEqual(sample_value, cmdline)
177-
178
179 class DescriptionFactoryTestcase(TestCase):
180 """Test the factory."""
181
182=== modified file 'ubuntu_sso/main/windows.py'
183--- ubuntu_sso/main/windows.py 2012-06-27 20:16:56 +0000
184+++ ubuntu_sso/main/windows.py 2012-07-17 21:15:24 +0000
185@@ -37,19 +37,16 @@
186 duplication between the different platform implementations.
187
188 """
189-
190 # pylint: disable=F0401
191 import win32process
192 import win32security
193-try:
194- import winreg
195-except ImportError:
196- import _winreg as winreg
197 # pylint: enable=F0401
198
199 from twisted.internet import defer
200
201+from ubuntu_sso import BACKEND_EXECUTABLE
202 from ubuntu_sso.logger import setup_logging
203+from ubuntu_sso.utils import get_bin_cmd
204 from ubuntu_sso.utils.ipc import BaseClient
205 from ubuntu_sso.main.perspective_broker import (
206 SSO_SERVICE_NAME,
207@@ -84,14 +81,6 @@
208 return SSO_BASE_PB_PORT + uid_modulo * SSO_PORT_ALLOCATION_STEP
209
210
211-def get_activation_cmdline(name):
212- """Find the path to the executable callback."""
213- key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, U1_REG_PATH)
214- # pylint: disable=W0612
215- value, registry_type = winreg.QueryValueEx(key, "path-" + name)
216- return value
217-
218-
219 class DescriptionFactory(object):
220 """Factory that provides the server and client descriptions."""
221
222@@ -118,7 +107,7 @@
223 @property
224 def cmdline(self):
225 """Get the command line to activate an executable."""
226- return get_activation_cmdline(self.name)
227+ return get_bin_cmd(BACKEND_EXECUTABLE)
228
229
230 class UbuntuSSOClient(BaseClient):
231
232=== modified file 'ubuntu_sso/tests/test_credentials.py'
233--- ubuntu_sso/tests/test_credentials.py 2012-06-27 19:03:44 +0000
234+++ ubuntu_sso/tests/test_credentials.py 2012-07-17 21:15:24 +0000
235@@ -123,7 +123,9 @@
236 credentials.logger.addHandler(self.memento)
237 self.addCleanup(credentials.logger.removeHandler, self.memento)
238
239- self.patch(credentials, 'get_bin_dir', lambda: self.bin_dir)
240+ self.patch(credentials, 'get_bin_cmd',
241+ lambda x: [os.path.join(self.bin_dir,
242+ KWARGS[UI_EXECUTABLE_KEY])])
243
244 def _set_called(self, *args, **kwargs):
245 """Set _called to True."""
246@@ -351,10 +353,6 @@
247 lambda kr, app: defer.succeed(None))
248 self._next_inner_result = credentials.USER_SUCCESS
249
250- # patch os.path.exists so it returns True for the faked exe_path
251- self.patch(credentials.os.path, 'exists',
252- lambda path: path == self.exe_path)
253-
254 result = yield self.method_call(**self.kwargs)
255 self.assertEqual(result, TOKEN)
256
257@@ -369,28 +367,15 @@
258 lambda kr, app: defer.succeed(None))
259 self._next_inner_result = credentials.USER_SUCCESS
260
261- assert not os.path.exists(self.exe_path)
262- self.patch(credentials.os.path, 'exists',
263- lambda path: path.endswith(credentials.UI_EXECUTABLE_QT))
264-
265- result = yield self.method_call(**self.kwargs)
266- self.assertEqual(result, TOKEN)
267-
268- # the ui was opened and proper params were passed
269- args = yield self.deferred
270- self.inner_args[0] = os.path.join(self.bin_dir,
271- credentials.UI_EXECUTABLE_QT)
272- self.assertEqual(self.inner_args, args)
273-
274- @defer.inlineCallbacks
275- def test_ui_executable_uses_qt_ui_if_none_available(self):
276- """The executable loads the QT UI if the requested does not exist."""
277- self.patch(credentials.Keyring, 'get_credentials',
278- lambda kr, app: defer.succeed(None))
279- self._next_inner_result = credentials.USER_SUCCESS
280-
281- self.patch(credentials.os.path, 'exists',
282- lambda path: path.endswith(credentials.UI_EXECUTABLE_QT))
283+ def get_bin_cmd_raises_if_not_qt(path):
284+ """Simulates nonexistence of exes that aren't qt."""
285+ if not path.endswith(credentials.UI_EXECUTABLE_QT):
286+ raise OSError()
287+ return [os.path.join(self.bin_dir,
288+ credentials.UI_EXECUTABLE_QT)]
289+
290+ self.patch(credentials, 'get_bin_cmd',
291+ get_bin_cmd_raises_if_not_qt)
292
293 result = yield self.method_call(**self.kwargs)
294 self.assertEqual(result, TOKEN)
295@@ -406,7 +391,12 @@
296 """If no GUI is available, raise GUINotAvailableError."""
297 self.patch(credentials.Keyring, 'get_credentials',
298 lambda kr, app: defer.succeed(None))
299- self.patch(credentials.os.path, 'exists', lambda path: False)
300+
301+ def get_bin_cmd_just_raises(*args, **kwargs):
302+ """Workaround for lambda: raise."""
303+ raise OSError()
304+
305+ self.patch(credentials, 'get_bin_cmd', get_bin_cmd_just_raises)
306
307 f = self.method_call(**self.kwargs)
308 yield self.assertFailure(f, credentials.GUINotAvailableError)
309@@ -418,9 +408,6 @@
310 lambda kr, app: defer.succeed(None))
311 self._next_inner_result = credentials.USER_CANCELLATION
312
313- self.patch(credentials.os.path, 'exists',
314- lambda path: path == self.exe_path)
315-
316 if exc is None:
317 exc = credentials.UserCancellationError
318 yield self.assertFailure(self.method_call(**self.kwargs), exc)
319@@ -432,9 +419,6 @@
320 lambda kr, app: defer.succeed(None))
321 self._next_inner_result = credentials.USER_CANCELLATION * 2 # other
322
323- self.patch(credentials.os.path, 'exists',
324- lambda path: path == self.exe_path)
325-
326 exc = yield self.assertFailure(self.method_call(**self.kwargs),
327 credentials.CredentialsError)
328 if result is None:
329@@ -461,9 +445,6 @@
330 lambda kr, app: defer.succeed(None))
331 self.patch_inner(self.fail_inner)
332
333- self.patch(credentials.os.path, 'exists',
334- lambda path: path == self.exe_path)
335-
336 yield self.assertFailure(self.method_call(**self.kwargs),
337 SampleMiscException)
338
339
340=== modified file 'ubuntu_sso/utils/__init__.py'
341--- ubuntu_sso/utils/__init__.py 2012-06-29 20:57:01 +0000
342+++ ubuntu_sso/utils/__init__.py 2012-07-17 21:15:24 +0000
343@@ -33,6 +33,7 @@
344 import sys
345 import time
346
347+from dirspec.utils import get_program_path
348 from oauth import oauth
349
350 try:
351@@ -46,6 +47,10 @@
352
353 from twisted.internet import defer
354
355+from ubuntu_sso import (BACKEND_EXECUTABLE,
356+ UI_EXECUTABLE_QT,
357+ UI_PROXY_CREDS_DIALOG,
358+ UI_SSL_DIALOG)
359 from ubuntu_sso.logger import setup_logging
360 from ubuntu_sso.utils import webclient
361
362@@ -62,6 +67,12 @@
363 # platform as a key in the dictionary
364 PLATFORM_QSS = QSS_MAP.get(sys.platform, ":/linux.qss")
365
366+DARWIN_APP_NAMES = {BACKEND_EXECUTABLE: 'Ubuntu SSO Helper.app',
367+ UI_EXECUTABLE_QT: 'Ubuntu Single Sign-On.app',
368+ UI_SSL_DIALOG: 'Ubuntu SSO SSL Certificate.app',
369+ UI_PROXY_CREDS_DIALOG: 'Ubuntu SSO Proxy Credentials.app'
370+ }
371+
372
373 def _get_dir(dir_name, dir_constant):
374 """Return the absolute path to this project's 'dir_name' dir.
375@@ -116,18 +127,29 @@
376 found, return the value of the BIN_DIR.
377
378 """
379- # If sys is frozen, this is an .exe, and all binaries are in
380- # the same place
381- if getattr(sys, "frozen", None) is not None:
382- exec_path = os.path.abspath(sys.executable)
383- result = os.path.dirname(exec_path)
384- else:
385- result = _get_dir(dir_name=BIN_SUFFIX, dir_constant='BIN_DIR')
386+ result = _get_dir(dir_name=BIN_SUFFIX, dir_constant='BIN_DIR')
387 assert result is not None, '%r dir can not be None.' % BIN_SUFFIX
388 logger.info('get_bin_dir: returning dir located at %r.', result)
389 return result
390
391
392+def get_bin_cmd(program_name):
393+ """Return a list of arguments to launch the given executable."""
394+ path = get_program_path(program_name,
395+ fallback_dirs=[get_bin_dir()],
396+ app_names=DARWIN_APP_NAMES)
397+ cmd_args = [path]
398+
399+ # adjust cmd for platforms using buildout-generated python
400+ # wrappers
401+ if getattr(sys, 'frozen', None) is None \
402+ and sys.platform in ('win32', 'darwin'):
403+ cmd_args.insert(0, 'python')
404+
405+ logger.debug('get_bin_cmd: returning %r', cmd_args)
406+ return cmd_args
407+
408+
409 class RequestHead(Request):
410 """A request with the method set to HEAD."""
411
412
413=== modified file 'ubuntu_sso/utils/tests/test_common.py'
414--- ubuntu_sso/utils/tests/test_common.py 2012-06-25 16:36:29 +0000
415+++ ubuntu_sso/utils/tests/test_common.py 2012-07-17 21:15:24 +0000
416@@ -29,7 +29,6 @@
417 """Tests for the oauth_headers helper function."""
418
419 import logging
420-import os
421 import sys
422 import time
423
424@@ -167,17 +166,9 @@
425 DIR_CONSTANT = 'BIN_DIR'
426 DIR_GETTER = 'get_bin_dir'
427
428- def test_frozen_binary(self):
429- """Test that frozen binaries return a valid path."""
430- sys.frozen = True
431- self.addCleanup(delattr, sys, "frozen")
432- expected = os.path.dirname(os.path.abspath(sys.executable))
433- result = self.get_dir()
434- self.assertEqual(expected, result)
435-
436
437 class GetBinDirWithConstantsTestCase(GetProjectDirWithConstantsTestCase):
438- """Test case for get_bin_dir when constants module is not defined."""
439+ """Test case for get_bin_dir when constants module is defined."""
440
441 DIR_NAME = utils.BIN_SUFFIX
442 DIR_CONSTANT = 'BIN_DIR'
443
444=== modified file 'ubuntu_sso/utils/webclient/common.py'
445--- ubuntu_sso/utils/webclient/common.py 2012-06-29 20:57:01 +0000
446+++ ubuntu_sso/utils/webclient/common.py 2012-07-17 21:15:24 +0000
447@@ -30,7 +30,6 @@
448
449 import cgi
450 import collections
451-import os
452
453 from httplib2 import iri2uri
454 from oauth import oauth
455@@ -43,13 +42,14 @@
456 except ImportError:
457 from urlparse import urlparse
458
459-from ubuntu_sso import USER_SUCCESS, UI_PROXY_CREDS_DIALOG
460+from ubuntu_sso import (USER_SUCCESS,
461+ UI_PROXY_CREDS_DIALOG,
462+ UI_SSL_DIALOG)
463 from ubuntu_sso.logger import setup_logging
464 from ubuntu_sso.utils.runner import spawn_program
465 from ubuntu_sso.utils.ui import SSL_DETAILS_TEMPLATE
466 from ubuntu_sso.utils.webclient.timestamp import TimestampChecker
467
468-SSL_DIALOG = 'ubuntu-sso-ssl-certificate-qt'
469
470 logger = setup_logging("ubuntu_sso.utils.webclient.common")
471
472@@ -230,13 +230,12 @@
473
474 def _launch_proxy_creds_dialog(self, domain, retry):
475 """Launch the dialog used to get the creds."""
476- from ubuntu_sso.utils import get_bin_dir
477+ from ubuntu_sso.utils import get_bin_cmd
478+ args = get_bin_cmd(UI_PROXY_CREDS_DIALOG)
479
480- bin_dir = get_bin_dir()
481- args = (os.path.join(bin_dir, UI_PROXY_CREDS_DIALOG), '--domain',
482- domain)
483+ args += ['--domain', domain]
484 if retry:
485- args += ('--retry',)
486+ args += ['--retry']
487 return spawn_program(args)
488
489 @defer.inlineCallbacks
490@@ -273,12 +272,13 @@
491
492 def _launch_ssl_dialog(self, domain, details):
493 """Launch a dialog used to approve the ssl cert."""
494- from ubuntu_sso.utils import get_bin_dir
495-
496- bin_dir = get_bin_dir()
497- args = (os.path.join(bin_dir, SSL_DIALOG), '--domain', domain,
498- '--details', details,
499- '--appname', self.appname)
500+ from ubuntu_sso.utils import get_bin_cmd
501+
502+ args = get_bin_cmd(UI_SSL_DIALOG)
503+ args += ['--domain', domain,
504+ '--details', details,
505+ '--appname', self.appname]
506+
507 return spawn_program(args)
508
509 def _was_ssl_accepted(self, cert_details):

Subscribers

People subscribed via source and target branches