Merge lp:~mikemc/ubuntuone-control-panel/fix-1024623-install-confs into lp:ubuntuone-control-panel

Proposed by Mike McCracken on 2012-08-06
Status: Merged
Approved by: Alejandro J. Cura on 2012-08-07
Approved revision: 343
Merged at revision: 340
Proposed branch: lp:~mikemc/ubuntuone-control-panel/fix-1024623-install-confs
Merge into: lp:ubuntuone-control-panel
Diff against target: 283 lines (+203/-1)
7 files modified
run-tests.bat (+1/-1)
ubuntuone/controlpanel/gui/qt/main/__init__.py (+4/-0)
ubuntuone/controlpanel/gui/qt/main/tests/test_main.py (+8/-0)
ubuntuone/controlpanel/utils/__init__.py (+10/-0)
ubuntuone/controlpanel/utils/darwin.py (+91/-0)
ubuntuone/controlpanel/utils/tests/test_darwin.py (+78/-0)
ubuntuone/controlpanel/utils/tests/test_utils.py (+11/-0)
To merge this branch: bzr merge lp:~mikemc/ubuntuone-control-panel/fix-1024623-install-confs
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve on 2012-08-07
Roberto Alsina (community) 2012-08-06 Approve on 2012-08-06
Review via email: mp+118404@code.launchpad.net

Commit Message

- Add darwin-only function to perform first-run "install" steps (LP: #1024623)

Description of the Change

- Add darwin-only function to perform first-run "install" steps (LP: #1024623)

Function is set to no_op in utils.__init__ for linux and windows.

This function does first-run install stuff, but it just copies the default conf files to the right place if they're not there, which is better than using the presence or absence of just one file/directory to signal "first-run".

Also, excludes "test_darwin.py" on windows. This is the first branch to add a test_darwin.py.

Tested on all three platforms.

To post a comment you must log in.
Roberto Alsina (ralsina) :
review: Approve
Alejandro J. Cura (alecu) wrote :

The code looks good. I was unable to run the tests though, because something on my dev environment is broken.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'run-tests.bat'
2--- run-tests.bat 2012-04-20 14:45:56 +0000
3+++ run-tests.bat 2012-08-06 17:51:56 +0000
4@@ -19,7 +19,7 @@
5 SET MODULE="ubuntuone"
6 SET PYTHONEXEPATH=""
7 SET IGNORE_PATHS="ubuntuone\controlpanel\dbustests"
8-SET IGNORE_MODULES="test_linux.py, test_libsoup.py"
9+SET IGNORE_MODULES="test_linux.py, test_libsoup.py, test_darwin.py"
10 SET PYTHONPATH=%PYTHONPATH%;..\ubuntu-sso-client;..\ubuntuone-client;.
11
12 ECHO Checking for Python on the path
13
14=== modified file 'ubuntuone/controlpanel/gui/qt/main/__init__.py'
15--- ubuntuone/controlpanel/gui/qt/main/__init__.py 2012-08-01 19:14:35 +0000
16+++ ubuntuone/controlpanel/gui/qt/main/__init__.py 2012-08-06 17:51:56 +0000
17@@ -38,6 +38,8 @@
18 source = dbus_main
19 # pylint: enable=C0103
20
21+from ubuntuone.controlpanel.utils import install_config_and_daemons
22+
23
24 def parser_options():
25 """Parse command line parameters."""
26@@ -119,6 +121,8 @@
27 data.append(unicode(qss.data()))
28 app.setStyleSheet('\n'.join(data))
29
30+ install_config_and_daemons()
31+
32 # Unused variable 'window', 'icon', pylint: disable=W0612
33 icon, window = start(lambda: source.main_quit(app),
34 minimized=minimized, with_icon=with_icon,
35
36=== modified file 'ubuntuone/controlpanel/gui/qt/main/tests/test_main.py'
37--- ubuntuone/controlpanel/gui/qt/main/tests/test_main.py 2012-08-01 20:18:52 +0000
38+++ ubuntuone/controlpanel/gui/qt/main/tests/test_main.py 2012-08-06 17:51:56 +0000
39@@ -260,3 +260,11 @@
40 self.patch(sys, 'platform', 'not-darwin')
41 main.main([sys.argv[0]], install_reactor_darwin=False)
42 self.assertEqual(self.qt4reactor_installed, False)
43+
44+ def test_install_config(self):
45+ """Test that install_config_and_daemons is called."""
46+ self.patch(main, 'install_config_and_daemons',
47+ self._set_called)
48+
49+ main.main([sys.argv[0]], install_reactor_darwin=False)
50+ self.assertEqual(self._called, ((), {}))
51
52=== modified file 'ubuntuone/controlpanel/utils/__init__.py'
53--- ubuntuone/controlpanel/utils/__init__.py 2012-04-05 14:52:55 +0000
54+++ ubuntuone/controlpanel/utils/__init__.py 2012-08-06 17:51:56 +0000
55@@ -40,13 +40,23 @@
56 add_to_autostart = windows.add_to_autostart
57 are_updates_present = windows.are_updates_present
58 default_folders = windows.default_folders
59+ install_config_and_daemons = no_op
60 perform_update = windows.perform_update
61 uninstall_application = windows.uninstall_application
62+elif sys.platform == 'darwin':
63+ from ubuntuone.controlpanel.utils import darwin
64+ add_to_autostart = no_op
65+ are_updates_present = no_op
66+ default_folders = darwin.default_folders
67+ install_config_and_daemons = darwin.install_config_and_daemons
68+ perform_update = no_op
69+ uninstall_application = no_op
70 else:
71 from ubuntuone.controlpanel.utils import linux
72 add_to_autostart = no_op
73 are_updates_present = no_op
74 default_folders = linux.default_folders
75+ install_config_and_daemons = no_op
76 perform_update = no_op
77 uninstall_application = no_op
78
79
80=== added file 'ubuntuone/controlpanel/utils/darwin.py'
81--- ubuntuone/controlpanel/utils/darwin.py 1970-01-01 00:00:00 +0000
82+++ ubuntuone/controlpanel/utils/darwin.py 2012-08-06 17:51:56 +0000
83@@ -0,0 +1,91 @@
84+# -*- coding: utf-8 -*-
85+#
86+# Copyright 2012 Canonical Ltd.
87+#
88+# This program is free software: you can redistribute it and/or modify it
89+# under the terms of the GNU General Public License version 3, as published
90+# by the Free Software Foundation.
91+#
92+# This program is distributed in the hope that it will be useful, but
93+# WITHOUT ANY WARRANTY; without even the implied warranties of
94+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
95+# PURPOSE. See the GNU General Public License for more details.
96+#
97+# You should have received a copy of the GNU General Public License along
98+# with this program. If not, see <http://www.gnu.org/licenses/>.
99+
100+"""Miscelaneous functions and constants for darwin."""
101+
102+import os
103+import shutil
104+import sys
105+
106+from twisted.internet import defer
107+
108+from dirspec.basedir import save_config_path
109+from ubuntuone.controlpanel.logger import setup_logging
110+
111+logger = setup_logging('utils.darwin')
112+AUTOUPDATE_BIN_NAME = 'autoupdate-darwin'
113+UNINSTALL_BIN_NAME = 'uninstall-darwin'
114+
115+
116+def add_to_autostart():
117+ """Add syncdaemon to the session's autostart."""
118+ # TODO
119+
120+
121+@defer.inlineCallbacks
122+def are_updates_present():
123+ """Return if there are updates for Ubuntu One."""
124+ result = False
125+ # TODO
126+ defer.returnValue(result)
127+
128+
129+def default_folders(user_home=None):
130+ """Return a list of the folders to add by default."""
131+ folders = []
132+ # TODO
133+ return folders
134+
135+
136+def install_config_and_daemons():
137+ """Install required data files and fsevents daemon.
138+
139+ This function is a replacement for an installer. As such it is
140+ required on first-run, but it's also called every time we start
141+ up, in case anything has moved or been deleted.
142+ """
143+
144+ # Do nothing if we are running from source:
145+ if getattr(sys, 'frozen', None) is None:
146+ return
147+
148+ main_app_dir = ''.join(__file__.partition('.app')[:-1])
149+ main_app_resources_dir = os.path.join(main_app_dir,
150+ 'Contents',
151+ 'Resources')
152+
153+ config_path = save_config_path('ubuntuone')
154+
155+ conf_filenames = ['syncdaemon.conf',
156+ 'logging.conf']
157+ for conf_filename in conf_filenames:
158+ src_path = os.path.join(main_app_resources_dir,
159+ conf_filename)
160+ dest_path = os.path.join(config_path,
161+ conf_filename)
162+
163+ if not os.path.exists(dest_path):
164+ shutil.copyfile(src_path, dest_path)
165+
166+
167+def perform_update():
168+ """Spawn the autoupdate process and call the stop function."""
169+ # TODO
170+
171+
172+def uninstall_application():
173+ """Uninstall Ubuntu One."""
174+ # TODO
175
176=== added file 'ubuntuone/controlpanel/utils/tests/test_darwin.py'
177--- ubuntuone/controlpanel/utils/tests/test_darwin.py 1970-01-01 00:00:00 +0000
178+++ ubuntuone/controlpanel/utils/tests/test_darwin.py 2012-08-06 17:51:56 +0000
179@@ -0,0 +1,78 @@
180+# -*- coding: utf-8 -*-
181+#
182+# Copyright 2012 Canonical Ltd.
183+#
184+# This program is free software: you can redistribute it and/or modify it
185+# under the terms of the GNU General Public License version 3, as published
186+# by the Free Software Foundation.
187+#
188+# This program is distributed in the hope that it will be useful, but
189+# WITHOUT ANY WARRANTY; without even the implied warranties of
190+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
191+# PURPOSE. See the GNU General Public License for more details.
192+#
193+# You should have received a copy of the GNU General Public License along
194+# with this program. If not, see <http://www.gnu.org/licenses/>.
195+
196+"""Test the darwin utils functions."""
197+
198+import os
199+import sys
200+
201+from twisted.internet import defer
202+
203+from ubuntuone.controlpanel import utils
204+from ubuntuone.devtools.testcases import TestCase
205+
206+# let me use protected methods
207+# pylint: disable=W0212
208+
209+
210+class InstallConfigTestCase(TestCase):
211+ """Test install_config_and_daemons."""
212+
213+ @defer.inlineCallbacks
214+ def setUp(self):
215+ """Set up multi-call checker."""
216+ yield super(InstallConfigTestCase, self).setUp()
217+ self._called = []
218+
219+ def _set_called(self, *args, **kwargs):
220+ """Store 'args' and 'kwargs for test assertions."""
221+ self._called.append((args, kwargs))
222+
223+ def test_do_nothing_unfrozen(self):
224+ """Test that install_config_and_daemons does nothing when unfrozen."""
225+
226+ self.patch(utils.darwin, 'save_config_path',
227+ self._set_called)
228+ utils.install_config_and_daemons()
229+ self.assertEqual(self._called, [])
230+
231+ def _test_copying_conf_files(self, exists):
232+ """Call install_config_and_daemons, parameterize os.path.exists."""
233+ sys.frozen = 'macosx_app'
234+ self.addCleanup(delattr, sys, 'frozen')
235+ self.patch(utils.darwin, 'save_config_path', lambda x: "TARGET_PATH")
236+ self.patch(utils.darwin, '__file__', "/path/to/Main.app/ignore")
237+ self.patch(os.path, "exists", lambda x: exists)
238+ self.patch(utils.darwin.shutil, 'copyfile',
239+ self._set_called)
240+ utils.install_config_and_daemons()
241+
242+ def test_copies_conf_files(self):
243+ """When frozen, we copy the conf files if they don't exist."""
244+ self._test_copying_conf_files(False)
245+ self.assertEqual(self._called,
246+ [(('/path/to/Main.app/Contents/'
247+ 'Resources/syncdaemon.conf',
248+ 'TARGET_PATH/syncdaemon.conf'), {}),
249+ (('/path/to/Main.app/Contents/'
250+ 'Resources/logging.conf',
251+ 'TARGET_PATH/logging.conf'),
252+ {})])
253+
254+ def test_does_not_copy_conf_files(self):
255+ """When frozen, we do not copy the conf files if they do exist."""
256+ self._test_copying_conf_files(True)
257+ self.assertEqual(self._called, [])
258
259=== modified file 'ubuntuone/controlpanel/utils/tests/test_utils.py'
260--- ubuntuone/controlpanel/utils/tests/test_utils.py 2011-11-14 11:33:31 +0000
261+++ ubuntuone/controlpanel/utils/tests/test_utils.py 2012-08-06 17:51:56 +0000
262@@ -24,6 +24,7 @@
263 from twisted.internet import defer
264
265 from ubuntuone.devtools.handlers import MementoHandler
266+from ubuntuone.devtools.testcases import skipIfOS
267
268 from ubuntuone.controlpanel import utils
269 from ubuntuone.controlpanel.tests import TestCase
270@@ -149,3 +150,13 @@
271 utils.ERROR_MESSAGE: unicode(exc)}
272
273 self.assertEqual(expected, result)
274+
275+
276+class FirstRunInstallTestCase(TestCase):
277+ """Test cases for darwin-only first-run installations."""
278+
279+ @skipIfOS("darwin", "Darwin-only code is tested in test_darwin.")
280+ def test_no_op_on_win_or_linux(self):
281+ """Test that install_config_and_daemons does nothing on win/linux."""
282+ self.assertEqual(utils.install_config_and_daemons,
283+ utils.no_op)

Subscribers

People subscribed via source and target branches