Merge lp:~ralsina/ubuntuone-windows-installer/put-in-autostart into lp:ubuntuone-windows-installer

Proposed by Roberto Alsina
Status: Merged
Approved by: Roberto Alsina
Approved revision: 66
Merged at revision: 59
Proposed branch: lp:~ralsina/ubuntuone-windows-installer/put-in-autostart
Merge into: lp:ubuntuone-windows-installer
Diff against target: 393 lines (+200/-20)
9 files modified
data/qt/congratulations.ui (+44/-9)
ubuntuone_installer/gui/qt/gui.py (+3/-0)
ubuntuone_installer/gui/qt/setup_account.py (+11/-7)
ubuntuone_installer/gui/qt/tests/test_gui.py (+12/-1)
ubuntuone_installer/gui/qt/tests/test_setup_account.py (+10/-1)
ubuntuone_installer/gui/qt/utils/__init__.py (+2/-0)
ubuntuone_installer/gui/qt/utils/linux.py (+8/-0)
ubuntuone_installer/gui/qt/utils/tests/test_windows.py (+83/-0)
ubuntuone_installer/gui/qt/utils/windows.py (+27/-2)
To merge this branch: bzr merge lp:~ralsina/ubuntuone-windows-installer/put-in-autostart
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Review via email: mp+73670@code.launchpad.net

Commit message

* Adds a missing image to the final page of the wizard
* Adds syncdaemon to autostart

Description of the change

* Adds a missing image to the final page of the wizard
* Adds syncdaemon to autostart

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

ubuntuone_installer/gui/qt/utils/tests/test_windows.py:
    96: [C0301] Line too long (89/79)
    97: [C0301] Line too long (148/79)
    73: [C0103, FakeRegistry.ConnectRegistry] Invalid name "ConnectRegistry" (should match ([a-z_][a-z0-9_]{2,79}$|setUp|tearDown))
    73: [C0111, FakeRegistry.ConnectRegistry] Missing docstring
    77: [C0103, FakeRegistry.OpenKey] Invalid name "OpenKey" (should match ([a-z_][a-z0-9_]{2,79}$|setUp|tearDown))
    77: [C0111, FakeRegistry.OpenKey] Missing docstring
    81: [C0103, FakeRegistry.CloseKey] Invalid name "CloseKey" (should match ([a-z_][a-z0-9_]{2,79}$|setUp|tearDown))
    81: [C0111, FakeRegistry.CloseKey] Missing docstring
    84: [C0103, FakeRegistry.QueryValueEx] Invalid name "QueryValueEx" (should match ([a-z_][a-z0-9_]{2,79}$|setUp|tearDown))
    84: [C0111, FakeRegistry.QueryValueEx] Missing docstring
    85: [W0201, FakeRegistry.QueryValueEx] Attribute 'query_args' defined outside __init__
    78: [W0201, FakeRegistry.OpenKey] Attribute 'openkey_args' defined outside __init__
    82: [W0201, FakeRegistry.CloseKey] Attribute 'closekey_args' defined outside __init__
    74: [W0201, FakeRegistry.ConnectRegistry] Attribute 'connect_args' defined outside __init__
    27: [W0611] Unused import _winreg

ubuntuone_installer/gui/qt/utils/windows.py:
    74: [C0301] Line too long (112/79)
    78: [E0602, add_syncdaemon_to_autostart] Undefined variable 'WindowsError'

review: Needs Fixing
Revision history for this message
Roberto Alsina (ralsina) wrote :

Most of those were a missing push, the last one only appears on Linux, so added a disable for it.

Revision history for this message
Leo Arias (elopio) wrote :

Why did you kept the empty label?

+ <string/>

Revision history for this message
Roberto Alsina (ralsina) wrote :

> Why did you kept the empty label?
>
> + <string/>

There is probably going to be another branch to add an image there after design sees how this looks, and didn't want to make the diff grow more than what's needed.

Revision history for this message
Leo Arias (elopio) wrote :

Good. I still don't understand the whole registry thing, but you have my full confidence and a symbolic +1. :)

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

The branch looks good, but after testing IRL I'm not sure that syncdaemon was added to the startup. Roberto said he will do some more work on this.

review: Needs Fixing
Revision history for this message
Roberto Alsina (ralsina) wrote :

The tests IRL don't work unless ubuntuone-windows-installer is a .exe file. You can test it with tonight's build that includes this branch.

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

Tested IRL with the beta2 bundle and works fine.

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

Oh, I just realized tests are broken:

Traceback (most recent call last):
  File "/home/nessita/canonical/u1/windows-installer/review_put-in-autostart/ubuntuone_installer/gui/qt/tests/test_gui.py", line 153, in setUp
    self.patch(gui.utils, "add_syncdaemon_to_autostart", NO_OP)
exceptions.AttributeError: 'module' object has no attribute 'utils'

review: Needs Fixing
61. By Roberto Alsina

fix tests

62. By Roberto Alsina

pep8

63. By Roberto Alsina

cleaner fix for set_up_button noise.

64. By Roberto Alsina

added missing super call

65. By Roberto Alsina

ARGH

66. By Roberto Alsina

push

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

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/qt/congratulations.ui'
2--- data/qt/congratulations.ui 2011-09-02 12:58:29 +0000
3+++ data/qt/congratulations.ui 2011-09-12 19:52:24 +0000
4@@ -6,8 +6,8 @@
5 <rect>
6 <x>0</x>
7 <y>0</y>
8- <width>521</width>
9- <height>387</height>
10+ <width>622</width>
11+ <height>331</height>
12 </rect>
13 </property>
14 <property name="windowTitle">
15@@ -35,11 +35,44 @@
16 </widget>
17 </item>
18 <item>
19- <widget class="QLabel" name="label_2">
20- <property name="text">
21- <string>Nice picture goes here</string>
22- </property>
23- </widget>
24+ <layout class="QHBoxLayout" name="horizontalLayout_2">
25+ <item>
26+ <spacer name="horizontalSpacer">
27+ <property name="orientation">
28+ <enum>Qt::Horizontal</enum>
29+ </property>
30+ <property name="sizeHint" stdset="0">
31+ <size>
32+ <width>40</width>
33+ <height>20</height>
34+ </size>
35+ </property>
36+ </spacer>
37+ </item>
38+ <item>
39+ <widget class="QLabel" name="label_2">
40+ <property name="text">
41+ <string/>
42+ </property>
43+ <property name="pixmap">
44+ <pixmap resource="images.qrc">:/win_installer_graphic.png</pixmap>
45+ </property>
46+ </widget>
47+ </item>
48+ <item>
49+ <spacer name="horizontalSpacer_2">
50+ <property name="orientation">
51+ <enum>Qt::Horizontal</enum>
52+ </property>
53+ <property name="sizeHint" stdset="0">
54+ <size>
55+ <width>40</width>
56+ <height>20</height>
57+ </size>
58+ </property>
59+ </spacer>
60+ </item>
61+ </layout>
62 </item>
63 <item>
64 <widget class="QLabel" name="label_3">
65@@ -60,7 +93,7 @@
66 <item>
67 <widget class="QLabel" name="label_4">
68 <property name="text">
69- <string>IMAGE GOES HERE?</string>
70+ <string/>
71 </property>
72 </widget>
73 </item>
74@@ -109,6 +142,8 @@
75 </item>
76 </layout>
77 </widget>
78- <resources/>
79+ <resources>
80+ <include location="images.qrc"/>
81+ </resources>
82 <connections/>
83 </ui>
84
85=== modified file 'ubuntuone_installer/gui/qt/gui.py'
86--- ubuntuone_installer/gui/qt/gui.py 2011-09-08 14:18:30 +0000
87+++ ubuntuone_installer/gui/qt/gui.py 2011-09-12 19:52:24 +0000
88@@ -243,6 +243,9 @@
89 self.wizard().button(QtGui.QWizard.FinishButton).style().polish(
90 self.wizard().button(QtGui.QWizard.FinishButton))
91
92+ # Add syncdaemon to autostart
93+ qt.utils.add_syncdaemon_to_autostart()
94+
95
96 class MainWindow(QtGui.QWizard):
97
98
99=== modified file 'ubuntuone_installer/gui/qt/setup_account.py'
100--- ubuntuone_installer/gui/qt/setup_account.py 2011-09-08 13:41:10 +0000
101+++ ubuntuone_installer/gui/qt/setup_account.py 2011-09-12 19:52:24 +0000
102@@ -178,25 +178,29 @@
103 """Set set_up_button as default button when the page is shown."""
104 # This method should stays here because if we move it to initializePage
105 # set_up_button won't take the proper style for hover and press
106- self.set_up_button.setVisible(True)
107- self.set_up_button.setDefault(True)
108- if not self.set_up_button.isEnabled():
109- self.set_up_button.setProperty("DisabledState", True)
110- self.set_up_button.style().unpolish(self.set_up_button)
111- self.set_up_button.style().polish(self.set_up_button)
112+ if self.set_up_button is not None:
113+ self.set_up_button.setVisible(True)
114+ self.set_up_button.setDefault(True)
115+ if not self.set_up_button.isEnabled():
116+ self.set_up_button.setProperty("DisabledState", True)
117+ self.set_up_button.style().unpolish(self.set_up_button)
118+ self.set_up_button.style().polish(self.set_up_button)
119 self.connect(QtGui.QApplication.instance(),
120 QtCore.SIGNAL("focusChanged(QWidget*, QWidget*)"),
121 self.focus_changed)
122+ super(SetupAccountPage, self).showEvent(event)
123
124 def hideEvent(self, event):
125 """Disconnect the focusChanged signal when the page change."""
126- self.set_up_button.setVisible(False)
127+ if self.set_up_button is not None:
128+ self.set_up_button.setVisible(False)
129 try:
130 self.disconnect(QtGui.QApplication.instance(),
131 QtCore.SIGNAL("focusChanged(QWidget*, QWidget*)"),
132 self.focus_changed)
133 except TypeError:
134 pass
135+ super(SetupAccountPage, self).hideEvent(event)
136
137
138 def is_min_required_password(password):
139
140=== modified file 'ubuntuone_installer/gui/qt/tests/test_gui.py'
141--- ubuntuone_installer/gui/qt/tests/test_gui.py 2011-09-12 18:18:54 +0000
142+++ ubuntuone_installer/gui/qt/tests/test_gui.py 2011-09-12 19:52:24 +0000
143@@ -30,7 +30,7 @@
144
145 from ubuntuone_installer.gui import NEXT
146 from ubuntuone_installer.gui.qt import gui, forgotten, utils
147-from ubuntuone_installer.gui.qt.tests import BaseTestCase
148+from ubuntuone_installer.gui.qt.tests import BaseTestCase, NO_OP
149
150
151 class FakeController(object):
152@@ -150,6 +150,7 @@
153 self.patch(gui, "LocalFoldersPage", FakeLocalFoldersPage)
154 self.patch(qt.preferences, "PreferencesPanel", FakePreferencesPanel)
155 self.patch(qt.folders, "FoldersPanel", FakeFoldersPanel)
156+ self.patch(gui.qt.utils, "add_syncdaemon_to_autostart", NO_OP)
157 super(MainWindowTestCase, self).setUp()
158 setup_page = self.ui.page(self.ui.setup_account_page_id)
159 setup_page.initializePage()
160@@ -561,6 +562,16 @@
161 QtCore.QCoreApplication.instance().processEvents()
162 self.assertEqual(self.ui.result(), self.ui.Rejected)
163
164+ def test_congratulations_adds_to_autostart(self):
165+ """Test that syncdaemon is now on autostart."""
166+ self.patch(gui.qt.utils, "add_syncdaemon_to_autostart",
167+ self._set_called)
168+ # Show the Congratulations page
169+ self.ui.setStartId(self.ui.CONGRATULATIONS_PAGE)
170+ self.ui.restart()
171+ # Check if syncdaemon was added to autostart
172+ self.assertEqual(self._called, ((), {}))
173+
174
175 class FakeSignal(object):
176
177
178=== modified file 'ubuntuone_installer/gui/qt/tests/test_setup_account.py'
179--- ubuntuone_installer/gui/qt/tests/test_setup_account.py 2011-09-07 14:15:39 +0000
180+++ ubuntuone_installer/gui/qt/tests/test_setup_account.py 2011-09-12 19:52:24 +0000
181@@ -229,7 +229,6 @@
182 # so we don't rely on any SSO behaviour
183 super(SetupAccountFakeWizardTestCase, self).setUp()
184 self.patch(self.ui, 'wizard', FakeWizard)
185- self.patch(self.ui, "set_up_button", QtGui.QPushButton())
186
187 def test_blank_name(self):
188 """Status when the name field is blank (spaces).
189@@ -322,3 +321,13 @@
190 self.addCleanup(self.ui.hide)
191 self.ui.focus_changed(None, self.ui.ui.password_edit)
192 self.assertTrue(self.ui.ui.password_assistance.isVisible())
193+
194+ def test_hide_event(self):
195+ """Check that hide_event works when set_up_button is none."""
196+ self.assertEqual(self.ui.set_up_button, None)
197+ self.ui.hideEvent(QtGui.QHideEvent())
198+
199+ def test_show_event(self):
200+ """Check that show_event works when set_up_button is none."""
201+ self.assertEqual(self.ui.set_up_button, None)
202+ self.ui.showEvent(QtGui.QShowEvent())
203
204=== modified file 'ubuntuone_installer/gui/qt/utils/__init__.py'
205--- ubuntuone_installer/gui/qt/utils/__init__.py 2011-08-30 14:11:48 +0000
206+++ ubuntuone_installer/gui/qt/utils/__init__.py 2011-09-12 19:52:24 +0000
207@@ -26,9 +26,11 @@
208 from ubuntuone_installer.gui.qt.utils import windows
209 uninstall_application = windows.uninstall_application
210 start_control_panel = windows.start_control_panel
211+ add_syncdaemon_to_autostart = windows.add_syncdaemon_to_autostart
212 default_folders = windows.default_folders
213 else:
214 from ubuntuone_installer.gui.qt.utils import linux
215 uninstall_application = linux.uninstall_application
216 start_control_panel = linux.start_control_panel
217+ add_syncdaemon_to_autostart = linux.add_syncdaemon_to_autostart
218 default_folders = linux.default_folders
219
220=== modified file 'ubuntuone_installer/gui/qt/utils/linux.py'
221--- ubuntuone_installer/gui/qt/utils/linux.py 2011-09-01 11:15:49 +0000
222+++ ubuntuone_installer/gui/qt/utils/linux.py 2011-09-12 19:52:24 +0000
223@@ -32,6 +32,14 @@
224 subprocess.Popen(["ubuntuone-control-panel-qt", ])
225
226
227+def remove_syncdaemon_from_autostart():
228+ """Remove syncdaemon from the session's autostart."""
229+
230+
231+def add_syncdaemon_to_autostart():
232+ """Add syncdaemon to the session's autostart."""
233+
234+
235 def default_folders():
236 """Return a list of the folders to add by default."""
237 # FIXME: this should be taken from ~/.config/user-dirs.dirs
238
239=== modified file 'ubuntuone_installer/gui/qt/utils/tests/test_windows.py'
240--- ubuntuone_installer/gui/qt/utils/tests/test_windows.py 2011-09-01 18:25:44 +0000
241+++ ubuntuone_installer/gui/qt/utils/tests/test_windows.py 2011-09-12 19:52:24 +0000
242@@ -86,6 +86,89 @@
243 self.assertTrue(0 == self._called[0][5])
244
245
246+class FakeRegistry(object):
247+ """A fake registry."""
248+ # pylint: disable=C0103
249+ HKEY_CURRENT_USER = 2
250+ KEY_ALL_ACCESS = 4
251+ REG_SZ = 1
252+
253+ def __init__(self):
254+ self.HKEY_CURRENT_USER = 2
255+ self.KEY_ALL_ACCESS = 4
256+ self.connect_args = None
257+ self.openkey_args = None
258+ self.closekey_args = None
259+ self.query_args = None
260+ self.set_args = []
261+
262+ def ConnectRegistry(self, *args, **kwargs):
263+ """Fake ConnectRegistry."""
264+ self.connect_args = (args, kwargs)
265+ return "REGISTRY"
266+
267+ def OpenKey(self, *args, **kwargs):
268+ """Fake OpenKey."""
269+ self.openkey_args = (args, kwargs)
270+ return "KEY"
271+
272+ def CloseKey(self, *args, **kwargs):
273+ """Fake CloseKey."""
274+ self.closekey_args = (args, kwargs)
275+
276+ def QueryValueEx(self, *args, **kwargs):
277+ """Fake QueryValueEx."""
278+ self.query_args = (args, kwargs)
279+
280+ def SetValueEx(self, *args, **kwargs):
281+ """Fake SetValueEx."""
282+ self.set_args.append((args, kwargs))
283+
284+
285+class AutostartTestCase(BaseTestCase):
286+ """Test add_syncdaemon_to_autostart."""
287+
288+ def setUp(self):
289+ """Initialize this test instance."""
290+ self.registry = FakeRegistry()
291+ self.patch(utils.windows, "_winreg", self.registry)
292+ super(AutostartTestCase, self).setUp()
293+
294+ def test_add_syncdaemon_to_autostart(self):
295+ """Check that the registry is updated correctly."""
296+ # I can't patch sys because frozen is not there by default
297+ sys.frozen = True
298+
299+ def clean_frozen():
300+ """Remove sys.frozen."""
301+ del sys.frozen
302+
303+ self.addCleanup(clean_frozen)
304+ utils.windows.add_syncdaemon_to_autostart()
305+ self.assertEqual(self.registry.connect_args,
306+ ((None, self.registry.HKEY_CURRENT_USER), {}))
307+ self.assertEqual(self.registry.openkey_args,
308+ (('REGISTRY', utils.windows.AUTORUN_KEY, 0,
309+ self.registry.KEY_ALL_ACCESS), {}))
310+ self.assertEqual(self.registry.closekey_args, (('KEY',), {}))
311+ self.assertEqual(self.registry.query_args, None)
312+ self.assertEqual(self.registry.set_args,
313+ [(('KEY', 'Ubuntu One', 0, 1,
314+ 'C:\\Python27\\ubuntuone-syncdaemon.exe'), {}),
315+ (('KEY', 'Ubuntu One Icon', 0, 1,
316+ 'C:\\Python27\\ubuntuone-control-panel-qt.exe --minimized'),
317+ {})])
318+
319+ def test_not_added_if_not_frozen(self):
320+ """Not frozen binaries are not added to the registry."""
321+ utils.windows.add_syncdaemon_to_autostart()
322+ self.assertEqual(self.registry.connect_args, None)
323+ self.assertEqual(self.registry.openkey_args, None)
324+ self.assertEqual(self.registry.closekey_args, None)
325+ self.assertEqual(self.registry.query_args, None)
326+ self.assertEqual(self.registry.set_args, [])
327+
328+
329 class DefaultFoldersTestCase(BaseTestCase):
330
331 """Test the default suggested UDFs."""
332
333=== modified file 'ubuntuone_installer/gui/qt/utils/windows.py'
334--- ubuntuone_installer/gui/qt/utils/windows.py 2011-09-01 10:32:51 +0000
335+++ ubuntuone_installer/gui/qt/utils/windows.py 2011-09-12 19:52:24 +0000
336@@ -19,6 +19,7 @@
337 """Utils Functions Windows specific."""
338
339
340+import ctypes
341 import os
342 import subprocess
343 import sys
344@@ -26,8 +27,10 @@
345 # Avoid pylint error on Linux
346 # pylint: disable=F0401
347 import win32api
348+import _winreg
349 # pylint: enable=F0401
350-import ctypes
351+
352+AUTORUN_KEY = r"Software\Microsoft\Windows\CurrentVersion\Run"
353
354
355 def uninstall_application():
356@@ -48,7 +51,7 @@
357 """Start the control panel."""
358 # If we are in windows and "frozen", assume it's in
359 # the same folder as this .exe
360- if sys.platform == "win32" and hasattr(sys, "frozen"):
361+ if hasattr(sys, "frozen"):
362 cp_path = os.path.join(os.path.dirname(
363 os.path.abspath(sys.executable)),
364 "ubuntuone-control-panel-qt.exe")
365@@ -57,6 +60,28 @@
366 subprocess.Popen([cp_path, ])
367
368
369+def add_syncdaemon_to_autostart():
370+ """Add syncdaemon to the session's autostart."""
371+ if hasattr(sys, "frozen"):
372+ sd_path = os.path.join(os.path.dirname(
373+ os.path.abspath(sys.executable)),
374+ "ubuntuone-syncdaemon.exe")
375+ u1cp_path = os.path.join(os.path.dirname(
376+ os.path.abspath(sys.executable)),
377+ "ubuntuone-control-panel-qt.exe")
378+ else:
379+ return
380+ registry = _winreg.ConnectRegistry(None, _winreg.HKEY_CURRENT_USER)
381+ key = _winreg.OpenKey(registry,
382+ AUTORUN_KEY,
383+ 0, _winreg.KEY_ALL_ACCESS)
384+ # pylint: disable=E0602
385+ _winreg.SetValueEx(key, "Ubuntu One", 0, _winreg.REG_SZ, sd_path)
386+ _winreg.SetValueEx(key, "Ubuntu One Icon", 0, _winreg.REG_SZ,
387+ u1cp_path + " --minimized")
388+ _winreg.CloseKey(key)
389+
390+
391 def default_folders():
392 """Return a list of the folders to add by default."""
393 # XXXX to be replaced by calls to xdg_base_directory's

Subscribers

People subscribed via source and target branches