Merge lp:~brian.curtin/ubuntuone-control-panel/windows-autostart into lp:ubuntuone-control-panel

Proposed by Brian Curtin
Status: Rejected
Rejected by: Natalia Bidart
Proposed branch: lp:~brian.curtin/ubuntuone-control-panel/windows-autostart
Merge into: lp:ubuntuone-control-panel
Prerequisite: lp:~ralsina/ubuntuone-control-panel/installer-option
Diff against target: 291 lines (+155/-4)
7 files modified
ubuntuone/controlpanel/gui/qt/gui.py (+1/-0)
ubuntuone/controlpanel/gui/qt/tests/test_folders.py (+24/-4)
ubuntuone/controlpanel/gui/qt/tests/test_gui.py (+13/-0)
ubuntuone/controlpanel/gui/qt/wizard.py (+10/-0)
ubuntuone/controlpanel/utils/__init__.py (+2/-0)
ubuntuone/controlpanel/utils/tests/test_windows.py (+83/-0)
ubuntuone/controlpanel/utils/windows.py (+22/-0)
To merge this branch: bzr merge lp:~brian.curtin/ubuntuone-control-panel/windows-autostart
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Disapprove
Roberto Alsina Pending
Review via email: mp+98741@code.launchpad.net

Commit message

- Implemented add_to_autostart to put Ubuntu One into the Windows autostart registry key. This was originally in ubuntuone-windows-installer in a slightly different form.

Description of the change

Implement add_to_autostart to put SD into the Windows autostart registry key. This was originally in ubuntuone-windows-installer in a slightly different form.

This proposal also depends on the following branches:
lp:~brian.curtin/ubuntuone-control-panel/no-symlinks-on-windows
lp:~brian.curtin/ubuntuone-control-panel/nessitas-crash-fix

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Roberto's proposal changed, so this diff is shwoing stuff that it shouldn't.

Would you please update your branch pulling the latest changes from all your dependency branches? Thanks!!!

298. By Brian Curtin

Move the symlink part of build_test_dir out to its own test class
so we can skip it on Windows.

299. By Brian Curtin

merge trunk

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Now I'm getting all these errors:

[ERROR]
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1039, in _inlineCallbacks
    result = g.send(result)
  File "/home/nessita/canonical/controlpanel/review_no-symlinks-on-windows/ubuntuone/controlpanel/gui/qt/tests/test_gui.py", line 126, in setUp
    self.patch(gui, "add_to_autostart", self._set_called)
  File "/usr/lib/python2.7/dist-packages/twisted/trial/unittest.py", line 1073, in patch
    monkeyPatch.patch()
  File "/usr/lib/python2.7/dist-packages/twisted/python/monkey.py", line 51, in patch
    self._originals.append((obj, name, getattr(obj, name)))
exceptions.AttributeError: 'module' object has no attribute 'add_to_autostart'

ubuntuone.controlpanel.gui.qt.tests.test_gui.AutoStartTestCase.test_add_to_autostart
ubuntuone.controlpanel.gui.qt.tests.test_gui.AutoStartTestCase.test_backend_is_correct
ubuntuone.controlpanel.gui.qt.tests.test_gui.AutoStartTestCase.test_close_callback_can_be_none
ubuntuone.controlpanel.gui.qt.tests.test_gui.AutoStartTestCase.test_close_event_calls_custom_close_callback
ubuntuone.controlpanel.gui.qt.tests.test_gui.AutoStartTestCase.test_focus_in
ubuntuone.controlpanel.gui.qt.tests.test_gui.AutoStartTestCase.test_init_loads_ui
ubuntuone.controlpanel.gui.qt.tests.test_gui.AutoStartTestCase.test_on_signin_canceled
ubuntuone.controlpanel.gui.qt.tests.test_gui.AutoStartTestCase.test_quit_action
ubuntuone.controlpanel.gui.qt.tests.test_gui.AutoStartTestCase.test_set_urgent
ubuntuone.controlpanel.gui.qt.tests.test_gui.AutoStartTestCase.test_switch_to

review: Needs Fixing
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

The code here was already covered by other 2 proposals, so rejecting this branch.

review: Disapprove

Unmerged revisions

299. By Brian Curtin

merge trunk

298. By Brian Curtin

Move the symlink part of build_test_dir out to its own test class
so we can skip it on Windows.

297. By Brian Curtin

Undo a previous incorrect change to a version of run-tests.bat

296. By Brian Curtin

merge lp:~brian.curtin/ubuntuone-control-panel/no-symlinks-on-windows

295. By Brian Curtin

merge lp:~brian.curtin/ubuntuone-control-panel/nessitas-crash-fix

294. By Brian Curtin

merge lp:~brian.curtin/ubuntuone-control-panel/windows-autostart

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/controlpanel/gui/qt/gui.py'
2--- ubuntuone/controlpanel/gui/qt/gui.py 2012-03-21 19:17:21 +0000
3+++ ubuntuone/controlpanel/gui/qt/gui.py 2012-03-22 14:10:24 +0000
4@@ -18,6 +18,7 @@
5
6 from PyQt4 import QtGui, QtCore
7
8+from ubuntuone.controlpanel.utils import add_to_autostart
9 from ubuntuone.controlpanel.gui.qt.systray import TrayIcon
10 from ubuntuone.controlpanel.gui.qt.ui import mainwindow_ui
11
12
13=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_folders.py'
14--- ubuntuone/controlpanel/gui/qt/tests/test_folders.py 2012-03-19 20:51:26 +0000
15+++ ubuntuone/controlpanel/gui/qt/tests/test_folders.py 2012-03-22 14:10:24 +0000
16@@ -22,10 +22,12 @@
17 import os
18 import Queue
19 import shutil
20+import sys
21
22 from PyQt4 import QtGui
23 from twisted.internet import defer
24 from ubuntuone.devtools.handlers import MementoHandler
25+from ubuntuone.devtools.testcases import skipIfOS
26
27 from ubuntuone.controlpanel.tests import helper_fail
28 from ubuntuone.controlpanel.gui.tests import (
29@@ -694,10 +696,6 @@
30 empty_dir = os.path.join(dir_path, 'empty')
31 os.mkdir(empty_dir)
32
33- # add a symlink to confirm those are avoided
34- a_link = os.path.join(dir_path, 'some_link')
35- os.symlink(a_file, a_link)
36-
37 return total_size
38
39
40@@ -733,6 +731,28 @@
41 self.assertRaises(Queue.Empty, self.queue.get, block=True, timeout=0.5)
42
43
44+@skipIfOS("win32", "Windows does not easily support symlinks")
45+class CalculateSizeWithSymlinksTestCase(BaseLocalFoldersTestCase):
46+ """Test suite for the CalculateSize thread implementation."""
47+
48+ def build_test_dir(self, dir_path):
49+ """Build a testing directory hierarchy."""
50+ total_size = super(CalculateSizeWithSymlinksTestCase,
51+ self).build_test_dir(dir_path)
52+
53+ a_file = os.path.join(dir_path, 'to_be_symlinked')
54+ with open(a_file, 'wb') as f:
55+ f.write('y' * 5000)
56+
57+ total_size += os.path.getsize(a_file)
58+
59+ # add a symlink to confirm those are avoided
60+ a_link = os.path.join(dir_path, 'some_link')
61+ os.symlink(a_file, a_link)
62+
63+ return total_size
64+
65+
66 class FakedCalculateSize(object):
67 """A faked CalculateSize thread."""
68
69
70=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_gui.py'
71--- ubuntuone/controlpanel/gui/qt/tests/test_gui.py 2012-03-09 01:05:49 +0000
72+++ ubuntuone/controlpanel/gui/qt/tests/test_gui.py 2012-03-22 14:10:24 +0000
73@@ -18,6 +18,8 @@
74
75 """Tests for the Qt UI."""
76
77+from twisted.internet import defer
78+
79 from ubuntuone.controlpanel.gui.qt import gui
80 from ubuntuone.controlpanel.gui.qt.tests import BaseTestCase
81
82@@ -115,3 +117,14 @@
83 self.patch(self.ui, "entry", entry)
84 self.ui.set_urgent("foo")
85 self.assertEqual(entry.called, (('urgent', "foo"), {}))
86+
87+
88+class AutoStartTestCase(MainWindowTestCase):
89+
90+ @defer.inlineCallbacks
91+ def setUp(self):
92+ self.patch(gui, "add_to_autostart", self._set_called)
93+ yield super(AutoStartTestCase, self).setUp()
94+
95+ def test_add_to_autostart(self):
96+ self.assertTrue(self._called)
97
98=== modified file 'ubuntuone/controlpanel/gui/qt/wizard.py'
99--- ubuntuone/controlpanel/gui/qt/wizard.py 2012-03-22 12:43:53 +0000
100+++ ubuntuone/controlpanel/gui/qt/wizard.py 2012-03-22 14:10:24 +0000
101@@ -24,6 +24,7 @@
102 from ubuntu_sso.utils.ui import CLOSE_AND_SETUP_LATER
103
104 from ubuntuone.controlpanel import cache
105+from ubuntuone.controlpanel.utils import add_to_autostart
106 from ubuntuone.controlpanel.logger import log_call, setup_logging
107 from ubuntuone.controlpanel.gui import (
108 APP_NAME,
109@@ -281,6 +282,13 @@
110 self.side_widget.stage = stage
111
112 @log_call(logger.info)
113+ def start_from_license(self):
114+ """Use the license page as first page."""
115+ # license
116+ self.setStartId(self.pages[self.license_page])
117+ self.restart()
118+
119+ @log_call(logger.info)
120 def cleanupPage(self, page_id):
121 """Called clean up 'page_id' just before the user leaves it."""
122 page = self.page(page_id)
123@@ -345,3 +353,5 @@
124 self.rejected.emit()
125 else:
126 super(UbuntuOneWizard, self).done(result)
127+
128+ add_to_autostart()
129
130=== modified file 'ubuntuone/controlpanel/utils/__init__.py'
131--- ubuntuone/controlpanel/utils/__init__.py 2012-03-16 16:40:27 +0000
132+++ ubuntuone/controlpanel/utils/__init__.py 2012-03-22 14:10:24 +0000
133@@ -38,11 +38,13 @@
134 are_updates_present = windows.are_updates_present
135 default_folders = windows.default_folders
136 perform_update = windows.perform_update
137+ add_to_autostart = windows.add_to_autostart
138 else:
139 from ubuntuone.controlpanel.utils import linux
140 are_updates_present = lambda *args, **kwargs: False
141 default_folders = linux.default_folders
142 perform_update = lambda *args, **kwargs: None
143+ add_to_autostart = lambda *args, **kwargs: None
144
145 # pylint: enable=C0103
146
147
148=== modified file 'ubuntuone/controlpanel/utils/tests/test_windows.py'
149--- ubuntuone/controlpanel/utils/tests/test_windows.py 2012-03-16 19:55:22 +0000
150+++ ubuntuone/controlpanel/utils/tests/test_windows.py 2012-03-22 14:10:24 +0000
151@@ -18,6 +18,7 @@
152 """Test the windows utils functions."""
153
154 import os
155+import sys
156
157 from twisted.internet import defer
158
159@@ -87,6 +88,88 @@
160 self.assertEqual(0, self._called[0][5])
161
162
163+class FakeOpenKey(object):
164+
165+ def __init__(self):
166+ self.openkey_args = None
167+ super(FakeOpenKey, self).__init__()
168+
169+ def __call__(self, *args, **kwargs):
170+ self.openkey_args = (args, kwargs)
171+ return self
172+
173+ def __enter__(self, *args, **kwargs):
174+ #self.openkey_args = (args, kwargs)
175+ return self
176+
177+ def __exit__(self, *args):
178+ pass
179+
180+
181+class FakeRegistry(object):
182+
183+ """A fake registry."""
184+
185+ # pylint: disable=C0103
186+ HKEY_CURRENT_USER = 2
187+ KEY_ALL_ACCESS = 4
188+ REG_SZ = 1
189+
190+ def __init__(self):
191+ self.HKEY_CURRENT_USER = 2
192+ self.KEY_ALL_ACCESS = 4
193+ self.openkey_args = None
194+ self.query_args = None
195+ self.set_args = []
196+
197+ self.OpenKey = FakeOpenKey()
198+
199+ def QueryValueEx(self, *args, **kwargs):
200+ """Fake QueryValueEx."""
201+ self.query_args = (args, kwargs)
202+
203+ def SetValueEx(self, *args, **kwargs):
204+ """Fake SetValueEx."""
205+ self.set_args.append((args, kwargs))
206+
207+
208+class AutostartTestCase(TestCase):
209+
210+ """Test add_syncdaemon_to_autostart."""
211+
212+ @defer.inlineCallbacks
213+ def setUp(self):
214+ """Initialize this test instance."""
215+ self.registry = FakeRegistry()
216+ self.patch(utils.windows, "_winreg", self.registry)
217+ yield super(AutostartTestCase, self).setUp()
218+
219+ def test_add_syncdaemon_to_autostart(self):
220+ """Check that the registry is updated correctly."""
221+ # I can't patch sys because frozen is not there by default
222+ sys.frozen = True
223+ self.addCleanup(delattr, sys, 'frozen')
224+ utils.windows.add_to_autostart()
225+ self.assertEqual(self.registry.OpenKey.openkey_args,
226+ ((self.registry.HKEY_CURRENT_USER, utils.windows.AUTORUN_KEY, 0,
227+ self.registry.KEY_ALL_ACCESS), {}))
228+ self.assertEqual(self.registry.query_args, None)
229+ dir = os.path.dirname(os.path.abspath(sys.executable))
230+ self.assertEqual(self.registry.set_args,
231+ [((self.registry.OpenKey, 'Ubuntu One', 0, 1,
232+ '"%s\\ubuntuone-syncdaemon.exe"' % dir), {}),
233+ ((self.registry.OpenKey, 'Ubuntu One Icon', 0, 1,
234+ '"%s\\ubuntuone-control-panel-qt.exe" --minimized' % dir),
235+ {})])
236+
237+ def test_not_added_if_not_frozen(self):
238+ """Not frozen binaries are not added to the registry."""
239+ utils.windows.add_to_autostart()
240+ self.assertEqual(self.registry.openkey_args, None)
241+ self.assertEqual(self.registry.query_args, None)
242+ self.assertEqual(self.registry.set_args, [])
243+
244+
245 class DefaultFoldersTestCase(TestCase):
246 """Test the default_folders method."""
247
248
249=== modified file 'ubuntuone/controlpanel/utils/windows.py'
250--- ubuntuone/controlpanel/utils/windows.py 2012-03-16 19:55:22 +0000
251+++ ubuntuone/controlpanel/utils/windows.py 2012-03-22 14:10:24 +0000
252@@ -19,6 +19,7 @@
253
254 import os
255 import sys
256+import _winreg
257
258 # Avoid pylint error on Linux
259 # pylint: disable=F0401
260@@ -33,6 +34,7 @@
261
262 logger = setup_logging('utils.windows')
263 AUTOUPDATE_EXE_NAME = 'autoupdate-windows.exe'
264+AUTORUN_KEY = r"Software\Microsoft\Windows\CurrentVersion\Run"
265
266
267 def _get_update_path():
268@@ -96,3 +98,23 @@
269 win32api.ShellExecute(None, 'runas',
270 update_path,
271 '--unattendedmodeui none', '', 0)
272+
273+
274+def add_to_autostart():
275+ """Add syncdaemon to the session's autostart."""
276+ if getattr(sys, "frozen", False):
277+ sd_path = '"%s"' % os.path.join(os.path.dirname(
278+ os.path.abspath(sys.executable)),
279+ "ubuntuone-syncdaemon.exe")
280+ u1cp_path = '"%s"' % os.path.join(os.path.dirname(
281+ os.path.abspath(sys.executable)),
282+ "ubuntuone-control-panel-qt.exe")
283+ else:
284+ return
285+
286+ with _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, AUTORUN_KEY,
287+ 0, _winreg.KEY_ALL_ACCESS) as key:
288+ # pylint: disable=E0602
289+ _winreg.SetValueEx(key, "Ubuntu One", 0, _winreg.REG_SZ, sd_path)
290+ _winreg.SetValueEx(key, "Ubuntu One Icon", 0, _winreg.REG_SZ,
291+ u1cp_path + " --minimized")

Subscribers

People subscribed via source and target branches