Merge lp:~mandel/ubuntuone-client/unify-tools into lp:ubuntuone-client

Proposed by Manuel de la Peña on 2012-05-24
Status: Merged
Approved by: Manuel de la Peña on 2012-05-29
Approved revision: 1256
Merged at revision: 1250
Proposed branch: lp:~mandel/ubuntuone-client/unify-tools
Merge into: lp:ubuntuone-client
Diff against target: 447 lines (+222/-84)
8 files modified
tests/platform/tools/__init__.py (+29/-0)
tests/platform/tools/test_darwin.py (+52/-0)
tests/platform/tools/test_tools.py (+4/-14)
tests/platform/tools/test_windows.py (+64/-0)
ubuntuone/platform/tools/__init__.py (+3/-6)
ubuntuone/platform/tools/darwin.py (+0/-47)
ubuntuone/platform/tools/perspective_broker.py (+14/-17)
ubuntuone/platform/tools/windows.py (+56/-0)
To merge this branch: bzr merge lp:~mandel/ubuntuone-client/unify-tools
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve on 2012-05-28
Diego Sarmentero (community) 2012-05-24 Approve on 2012-05-28
Review via email: mp+107226@code.launchpad.net

Commit Message

- Refactored the tools code so that it is shared between windows and darwin (LP: #1002994).

Description of the Change

- Refactored the tools code so that it is shared between windows and darwin (LP: #1002994).

To post a comment you must log in.
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
Roberto Alsina (ralsina) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'tests/platform/tools'
2=== added file 'tests/platform/tools/__init__.py'
3--- tests/platform/tools/__init__.py 1970-01-01 00:00:00 +0000
4+++ tests/platform/tools/__init__.py 2012-05-24 15:14:18 +0000
5@@ -0,0 +1,29 @@
6+# -*- coding: utf-8 -*-
7+#
8+# Copyright 2012 Canonical Ltd.
9+#
10+# This program is free software: you can redistribute it and/or modify it
11+# under the terms of the GNU General Public License version 3, as published
12+# by the Free Software Foundation.
13+#
14+# This program is distributed in the hope that it will be useful, but
15+# WITHOUT ANY WARRANTY; without even the implied warranties of
16+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
17+# PURPOSE. See the GNU General Public License for more details.
18+#
19+# You should have received a copy of the GNU General Public License along
20+# with this program. If not, see <http://www.gnu.org/licenses/>.
21+#
22+# In addition, as a special exception, the copyright holders give
23+# permission to link the code of portions of this program with the
24+# OpenSSL library under certain conditions as described in each
25+# individual source file, and distribute linked combinations
26+# including the two.
27+# You must obey the GNU General Public License in all respects
28+# for all of the code used other than OpenSSL. If you modify
29+# file(s) with this exception, you may extend this exception to your
30+# version of the file(s), but you are not obligated to do so. If you
31+# do not wish to do so, delete this exception statement from your
32+# version. If you delete this exception statement from all source
33+# files in the program, then also delete it here.
34+"""Tests for the tools code."""
35
36=== added file 'tests/platform/tools/test_darwin.py'
37--- tests/platform/tools/test_darwin.py 1970-01-01 00:00:00 +0000
38+++ tests/platform/tools/test_darwin.py 2012-05-24 15:14:18 +0000
39@@ -0,0 +1,52 @@
40+# -*- coding: utf-8 -*-
41+#
42+# Copyright 2012 Canonical Ltd.
43+#
44+# This program is free software: you can redistribute it and/or modify it
45+# under the terms of the GNU General Public License version 3, as published
46+# by the Free Software Foundation.
47+#
48+# This program is distributed in the hope that it will be useful, but
49+# WITHOUT ANY WARRANTY; without even the implied warranties of
50+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
51+# PURPOSE. See the GNU General Public License for more details.
52+#
53+# You should have received a copy of the GNU General Public License along
54+# with this program. If not, see <http://www.gnu.org/licenses/>.
55+#
56+# In addition, as a special exception, the copyright holders give
57+# permission to link the code of portions of this program with the
58+# OpenSSL library under certain conditions as described in each
59+# individual source file, and distribute linked combinations
60+# including the two.
61+# You must obey the GNU General Public License in all respects
62+# for all of the code used other than OpenSSL. If you modify
63+# file(s) with this exception, you may extend this exception to your
64+# version of the file(s), but you are not obligated to do so. If you
65+# do not wish to do so, delete this exception statement from your
66+# version. If you delete this exception statement from all source
67+# files in the program, then also delete it here.
68+"""Tests for the tools windows code."""
69+
70+from twisted.internet import defer
71+from twisted.trial.unittest import TestCase
72+
73+from ubuntuone.platform.tools import perspective_broker, darwin
74+
75+
76+class TestStartSyncdaemon(TestCase):
77+ """Test the process of launching sd."""
78+
79+ @defer.inlineCallbacks
80+ def setUp(self):
81+ yield super(TestStartSyncdaemon, self).setUp()
82+ self.patch(perspective_broker.UbuntuOneClient, "connect",
83+ lambda _: defer.Deferred())
84+ self.sdtool = perspective_broker.SyncDaemonToolProxy()
85+ self.calls = {}
86+
87+ def test_start_missing_exe(self):
88+ """Test starting the service when the exe is missing."""
89+ # file is missing
90+ self.patch(darwin.os.path, 'exists', lambda f: False)
91+ self.assertFailure(self.sdtool.start(), Exception)
92
93=== renamed file 'tests/platform/windows/test_tools.py' => 'tests/platform/tools/test_tools.py'
94--- tests/platform/windows/test_tools.py 2012-04-16 12:21:35 +0000
95+++ tests/platform/tools/test_tools.py 2012-05-24 15:14:18 +0000
96@@ -34,7 +34,7 @@
97 from twisted.internet import defer
98 from twisted.trial.unittest import TestCase
99
100-from ubuntuone.platform.tools import windows
101+from ubuntuone.platform.tools import perspective_broker
102
103
104 # ugly trick to stop pylint for complaining about
105@@ -49,8 +49,9 @@
106 @defer.inlineCallbacks
107 def setUp(self):
108 yield super(TestSyncDaemonTool, self).setUp()
109- self.patch(windows.UbuntuOneClient, "connect", lambda _: defer.Deferred())
110- self.sdtool = windows.SyncDaemonToolProxy()
111+ self.patch(perspective_broker.UbuntuOneClient, "connect",
112+ lambda _: defer.Deferred())
113+ self.sdtool = perspective_broker.SyncDaemonToolProxy()
114 self.calls = {}
115
116 def test_call_after_connection(self):
117@@ -124,14 +125,3 @@
118 attr = getattr(self.sdtool, attr_name)
119 func_name = getattr(attr, "__name__", None)
120 self.assertNotEqual(func_name, "call_after_connection_inner")
121-
122- def test_start_missing_exe(self):
123- """Test starting the service when the exe is missing."""
124- # file is missing
125- self.patch(windows.os.path, 'exists', lambda f: False)
126- key = 'key'
127- path = 'path/to/exe'
128- self.patch(windows, 'OpenKey', lambda k,p: key)
129- self.patch(windows, 'QueryValueEx', lambda k,p: path)
130-
131- self.assertFailure(self.sdtool.start(), WindowsError)
132
133=== added file 'tests/platform/tools/test_windows.py'
134--- tests/platform/tools/test_windows.py 1970-01-01 00:00:00 +0000
135+++ tests/platform/tools/test_windows.py 2012-05-24 15:14:18 +0000
136@@ -0,0 +1,64 @@
137+# -*- coding: utf-8 -*-
138+#
139+# Copyright 2012 Canonical Ltd.
140+#
141+# This program is free software: you can redistribute it and/or modify it
142+# under the terms of the GNU General Public License version 3, as published
143+# by the Free Software Foundation.
144+#
145+# This program is distributed in the hope that it will be useful, but
146+# WITHOUT ANY WARRANTY; without even the implied warranties of
147+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
148+# PURPOSE. See the GNU General Public License for more details.
149+#
150+# You should have received a copy of the GNU General Public License along
151+# with this program. If not, see <http://www.gnu.org/licenses/>.
152+#
153+# In addition, as a special exception, the copyright holders give
154+# permission to link the code of portions of this program with the
155+# OpenSSL library under certain conditions as described in each
156+# individual source file, and distribute linked combinations
157+# including the two.
158+# You must obey the GNU General Public License in all respects
159+# for all of the code used other than OpenSSL. If you modify
160+# file(s) with this exception, you may extend this exception to your
161+# version of the file(s), but you are not obligated to do so. If you
162+# do not wish to do so, delete this exception statement from your
163+# version. If you delete this exception statement from all source
164+# files in the program, then also delete it here.
165+"""Tests for the tools windows code."""
166+
167+import sys
168+
169+from twisted.internet import defer
170+from twisted.trial.unittest import TestCase
171+
172+from ubuntuone.platform.tools import perspective_broker, windows
173+
174+# ugly trick to stop pylint for complaining about
175+# WindowsError on Linux
176+if sys.platform != 'win32':
177+ WindowsError = None
178+
179+
180+class TestStartSyncdaemon(TestCase):
181+ """Test the process of launching sd."""
182+
183+ @defer.inlineCallbacks
184+ def setUp(self):
185+ yield super(TestStartSyncdaemon, self).setUp()
186+ self.patch(perspective_broker.UbuntuOneClient, "connect",
187+ lambda _: defer.Deferred())
188+ self.sdtool = perspective_broker.SyncDaemonToolProxy()
189+ self.calls = {}
190+
191+ def test_start_missing_exe(self):
192+ """Test starting the service when the exe is missing."""
193+ # file is missing
194+ self.patch(windows.os.path, 'exists', lambda f: False)
195+ key = 'key'
196+ path = 'path/to/exe'
197+ self.patch(windows, 'OpenKey', lambda k,p: key)
198+ self.patch(windows, 'QueryValueEx', lambda k,p: path)
199+
200+ self.assertFailure(self.sdtool.start(), WindowsError)
201
202=== modified file 'ubuntuone/platform/tools/__init__.py'
203--- ubuntuone/platform/tools/__init__.py 2012-05-16 16:24:23 +0000
204+++ ubuntuone/platform/tools/__init__.py 2012-05-24 15:14:18 +0000
205@@ -36,12 +36,9 @@
206 from twisted.internet import defer
207 from ubuntuone.logger import log_call
208
209-if sys.platform == 'win32':
210- from ubuntuone.platform.tools import windows
211- source = windows
212-elif sys.platform == 'darwin':
213- from ubuntuone.platform.tools import darwin
214- source = darwin
215+if sys.platform in ('win32', 'darwin'):
216+ from ubuntuone.platform.tools import perspective_broker
217+ source = perspective_broker
218 else:
219 from ubuntuone.platform.tools import linux
220 source = linux
221
222=== added file 'ubuntuone/platform/tools/darwin.py'
223--- ubuntuone/platform/tools/darwin.py 1970-01-01 00:00:00 +0000
224+++ ubuntuone/platform/tools/darwin.py 2012-05-24 15:14:18 +0000
225@@ -0,0 +1,49 @@
226+# -*- coding: utf-8 -*-
227+#
228+# Copyright 2012 Canonical Ltd.
229+#
230+# This program is free software: you can redistribute it and/or modify it
231+# under the terms of the GNU General Public License version 3, as published
232+# by the Free Software Foundation.
233+#
234+# This program is distributed in the hope that it will be useful, but
235+# WITHOUT ANY WARRANTY; without even the implied warranties of
236+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
237+# PURPOSE. See the GNU General Public License for more details.
238+#
239+# You should have received a copy of the GNU General Public License along
240+# with this program. If not, see <http://www.gnu.org/licenses/>.
241+#
242+# In addition, as a special exception, the copyright holders give
243+# permission to link the code of portions of this program with the
244+# OpenSSL library under certain conditions as described in each
245+# individual source file, and distribute linked combinations
246+# including the two.
247+# You must obey the GNU General Public License in all respects
248+# for all of the code used other than OpenSSL. If you modify
249+# file(s) with this exception, you may extend this exception to your
250+# version of the file(s), but you are not obligated to do so. If you
251+# do not wish to do so, delete this exception statement from your
252+# version. If you delete this exception statement from all source
253+# files in the program, then also delete it here.
254+"""SyncDaemon Tools darwin implementation."""
255+
256+import errno
257+import os
258+
259+import ubuntuone
260+
261+
262+def get_sd_install_path():
263+ """Return the path where the sd script was installed."""
264+ # TODO: We need to find a nicer way to find paths on darwin when since this
265+ # method will probably not work once the application has been packaged.
266+ ubuntuone_pkg_dir = os.path.dirname(os.path.dirname(ubuntuone.__file__))
267+ ubuntuone_bin_dir = os.path.join(ubuntuone_pkg_dir, 'bin')
268+ ubuntuone_bin = os.path.join(ubuntuone_bin_dir,
269+ 'ubuntuone-syncdaemon')
270+ if not os.path.exists(ubuntuone_bin):
271+ raise Exception(errno.ENOENT,
272+ 'Could not start syncdaemon: File not found %s' % ubuntuone_bin)
273+ return ubuntuone_bin
274+
275
276=== removed file 'ubuntuone/platform/tools/darwin.py'
277--- ubuntuone/platform/tools/darwin.py 2012-05-17 11:59:26 +0000
278+++ ubuntuone/platform/tools/darwin.py 1970-01-01 00:00:00 +0000
279@@ -1,47 +0,0 @@
280-# -*- coding: utf-8 -*-
281-#
282-# Copyright 2012 Canonical Ltd.
283-#
284-# This program is free software: you can redistribute it and/or modify it
285-# under the terms of the GNU General Public License version 3, as published
286-# by the Free Software Foundation.
287-#
288-# This program is distributed in the hope that it will be useful, but
289-# WITHOUT ANY WARRANTY; without even the implied warranties of
290-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
291-# PURPOSE. See the GNU General Public License for more details.
292-#
293-# You should have received a copy of the GNU General Public License along
294-# with this program. If not, see <http://www.gnu.org/licenses/>.
295-#
296-# In addition, as a special exception, the copyright holders give
297-# permission to link the code of portions of this program with the
298-# OpenSSL library under certain conditions as described in each
299-# individual source file, and distribute linked combinations
300-# including the two.
301-# You must obey the GNU General Public License in all respects
302-# for all of the code used other than OpenSSL. If you modify
303-# file(s) with this exception, you may extend this exception to your
304-# version of the file(s), but you are not obligated to do so. If you
305-# do not wish to do so, delete this exception statement from your
306-# version. If you delete this exception statement from all source
307-# files in the program, then also delete it here.
308-"""SyncDaemon Tools."""
309-
310-
311-def is_already_running(*arg):
312- """Empty implementation for MAC OS"""
313-
314-
315-class IPCError(object):
316- """Empty implementation for MAC OS"""
317-
318- def __init__(self, *args):
319- """Empty implementation for MAC OS"""
320-
321-
322-class SyncDaemonToolProxy(object):
323- """Empty implementation for MAC OS"""
324-
325- def __init__(self, *args):
326- """Empty implementation for MAC OS"""
327
328=== renamed file 'ubuntuone/platform/tools/windows.py' => 'ubuntuone/platform/tools/perspective_broker.py'
329--- ubuntuone/platform/tools/windows.py 2012-05-22 14:13:48 +0000
330+++ ubuntuone/platform/tools/perspective_broker.py 2012-05-24 15:14:18 +0000
331@@ -28,13 +28,10 @@
332 # files in the program, then also delete it here.
333 """SyncDaemon Tools."""
334
335-import errno
336 import subprocess
337 import sys
338-import os
339
340 from twisted.internet import defer
341-from _winreg import OpenKey, HKEY_LOCAL_MACHINE, QueryValueEx
342
343 from ubuntuone.platform.ipc.perspective_broker import is_already_running
344 from ubuntuone.platform.ipc.ipc_client import UbuntuOneClient
345@@ -42,13 +39,17 @@
346
347 # make pyflakes happy since we can't disable the warning
348 is_already_running = is_already_running
349-U1_REG_PATH = r'Software\\Ubuntu One'
350-SD_INSTALL_PATH = 'SyncDaemonInstallPath'
351
352-# ugly trick to stop pylint for complaining about
353-# WindowsError on Linux
354-if sys.platform != 'win32':
355- WindowsError = None
356+if sys.platform == 'win32':
357+ from ubuntuone.platform.tools import windows
358+ get_sd_install_path = windows.get_sd_install_path
359+elif sys.platform == 'darwin':
360+ from ubuntuone.platform.tools import darwin
361+ get_sd_install_path = darwin.get_sd_install_path
362+else:
363+ # add an implementation that will result in os.path.exists always to be
364+ # false
365+ get_sd_install_path = lambda: None
366
367
368 class IPCError(Exception):
369@@ -173,13 +174,9 @@
370
371 def start(self):
372 """Start syncdaemon, should *not* be running."""
373- # look in the reg to find the path of the .exe to be executed
374- # to launch the sd on windows
375- key = OpenKey(HKEY_LOCAL_MACHINE, U1_REG_PATH)
376- path = QueryValueEx(key, SD_INSTALL_PATH)[0]
377- if not os.path.exists(path):
378- # either the .exe was moved of the value is wrong
379- return defer.fail(WindowsError(errno.ENOENT,
380- 'Could not start syncdaemon: File not found %s' % path))
381+ try:
382+ path = get_sd_install_path()
383+ except Exception, e:
384+ defer.fail(e)
385 p = subprocess.Popen([path])
386 return defer.succeed(p)
387
388=== added file 'ubuntuone/platform/tools/windows.py'
389--- ubuntuone/platform/tools/windows.py 1970-01-01 00:00:00 +0000
390+++ ubuntuone/platform/tools/windows.py 2012-05-24 15:14:18 +0000
391@@ -0,0 +1,56 @@
392+# -*- coding: utf-8 -*-
393+#
394+# Copyright 2012 Canonical Ltd.
395+#
396+# This program is free software: you can redistribute it and/or modify it
397+# under the terms of the GNU General Public License version 3, as published
398+# by the Free Software Foundation.
399+#
400+# This program is distributed in the hope that it will be useful, but
401+# WITHOUT ANY WARRANTY; without even the implied warranties of
402+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
403+# PURPOSE. See the GNU General Public License for more details.
404+#
405+# You should have received a copy of the GNU General Public License along
406+# with this program. If not, see <http://www.gnu.org/licenses/>.
407+#
408+# In addition, as a special exception, the copyright holders give
409+# permission to link the code of portions of this program with the
410+# OpenSSL library under certain conditions as described in each
411+# individual source file, and distribute linked combinations
412+# including the two.
413+# You must obey the GNU General Public License in all respects
414+# for all of the code used other than OpenSSL. If you modify
415+# file(s) with this exception, you may extend this exception to your
416+# version of the file(s), but you are not obligated to do so. If you
417+# do not wish to do so, delete this exception statement from your
418+# version. If you delete this exception statement from all source
419+# files in the program, then also delete it here.
420+"""SyncDaemon Tools windows implementation."""
421+
422+import errno
423+import os
424+import sys
425+
426+from _winreg import OpenKey, HKEY_LOCAL_MACHINE, QueryValueEx
427+
428+
429+U1_REG_PATH = r'Software\\Ubuntu One'
430+SD_INSTALL_PATH = 'SyncDaemonInstallPath'
431+
432+# ugly trick to stop pylint for complaining about
433+# WindowsError on Linux
434+if sys.platform != 'win32':
435+ WindowsError = None
436+
437+
438+def get_sd_install_path():
439+ """Return the path where the sd script was installed."""
440+ # look in the reg to find the path of the .exe to be executed
441+ # to launch the sd on windows
442+ key = OpenKey(HKEY_LOCAL_MACHINE, U1_REG_PATH)
443+ path = QueryValueEx(key, SD_INSTALL_PATH)[0]
444+ if not os.path.exists(path):
445+ raise WindowsError(errno.ENOENT,
446+ 'Could not start syncdaemon: File not found %s' % path)
447+ return path

Subscribers

People subscribed via source and target branches