Merge lp:~mandel/ubuntuone-windows-installer/auto-update-python-only into lp:ubuntuone-windows-installer

Proposed by Manuel de la Peña
Status: Merged
Approved by: Roberto Alsina
Approved revision: 77
Merged at revision: 73
Proposed branch: lp:~mandel/ubuntuone-windows-installer/auto-update-python-only
Merge into: lp:ubuntuone-windows-installer
Diff against target: 415 lines (+241/-7)
7 files modified
ubuntuone_installer/gui/qt/gui.py (+11/-0)
ubuntuone_installer/gui/qt/main/tests/test_windows.py (+19/-2)
ubuntuone_installer/gui/qt/main/windows.py (+29/-5)
ubuntuone_installer/gui/qt/tests/test_gui.py (+49/-0)
ubuntuone_installer/gui/qt/utils/__init__.py (+4/-0)
ubuntuone_installer/gui/qt/utils/tests/test_windows.py (+85/-0)
ubuntuone_installer/gui/qt/utils/windows.py (+44/-0)
To merge this branch: bzr merge lp:~mandel/ubuntuone-windows-installer/auto-update-python-only
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+76047@code.launchpad.net

Commit message

Partial fix for lp: 845662

Provides the code that perform a call to the auto-update process that will check for updates and will perform them if the user agrees to do so.

Description of the change

Provides the code that perform a call to the auto-update process that will check for updates and will perform them if the user agrees to do so.

To post a comment you must log in.
72. By Manuel de la Peña

Remove named parameter comming from a smart-ass diff.

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :
Download full text (6.4 KiB)

...
ubuntuone_installer.gui.qt.main.tests.test_windows
  CredsFailureMainTestCase
    test_failure ... [OK]
    test_no_creds ... Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 1020, in
_inlineCallbacks
    result = g.send(result)
  File "X:\ubuntuone-windows-installer-mandel\ubuntuone_installer\gui\qt\main\wi
ndows.py", line 85, in check_credentials
    success_cb(creds, gui, installer, logger)
  File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 1141, in
unwindGenerator
    return _inlineCallbacks(None, f(*args, **kwargs), Deferred())
  File "X:\ubuntuone-windows-installer-mandel\ubuntuone_installer\gui\qt\main\wi
ndows.py", line 50, in success_cb
    logger.debug('Got back from sso.')
exceptions.AttributeError: 'FakeLogger' object has no attribute 'debug'
[ERROR]
    test_with_creds ... Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 1020, in
_inlineCallbacks
    result = g.send(result)
  File "X:\ubuntuone-windows-installer-mandel\ubuntuone_installer\gui\qt\main\wi
ndows.py", line 85, in check_credentials
    success_cb(creds, gui, installer, logger)
  File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 1141, in
unwindGenerator
    return _inlineCallbacks(None, f(*args, **kwargs), Deferred())
  File "X:\ubuntuone-windows-installer-mandel\ubuntuone_installer\gui\qt\main\wi
ndows.py", line 50, in success_cb
    logger.debug('Got back from sso.')
exceptions.AttributeError: 'FakeLogger' object has no attribute 'debug'
[ERROR]
    test_with_installed_flag ... Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 1020, in
_inlineCallbacks
    result = g.send(result)
  File "X:\ubuntuone-windows-installer-mandel\ubuntuone_installer\gui\qt\main\te
sts\test_windows.py", line 150, in test_with_installed_flag
    gui, True), {}))
twisted.trial.unittest.FailTest: not equal:
a = (('Something not false',
  <module 'ubuntuone_installer.gui.qt.gui' from 'X:\ubuntuone-windows-installer-
mandel\ubuntuone_installer\gui\qt\gui.pyc'>,
  True,
  <ubuntuone_installer.gui.qt.main.tests.test_windows.FakeLogger object at 0x086
9D3B0>),
 {})
b = (('Something not false',
  <module 'ubuntuone_installer.gui.qt.gui' from 'X:\ubuntuone-windows-installer-
mandel\ubuntuone_installer\gui\qt\gui.pyc'>,
  True),
 {})

[FAIL]
    test_without_installed_flag ... Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 1020, in
_inlineCallbacks
    result = g.send(result)
  File "X:\ubuntuone-windows-installer-mandel\ubuntuone_installer\gui\qt\main\te
sts\test_windows.py", line 139, in test_without_installed_flag
    gui, False), {}))
twisted.trial.unittest.FailTest: not equal:
a = (('Something not false',
  <module 'ubuntuone_installer.gui.qt.gui' from 'X:\ubuntuone-windows-installer-
mandel\ubuntuone_installer\gui\qt\gui.pyc'>,
  False,
  <ubuntuone_installer.gui.qt.main.tests.test_windows.FakeLogger object at 0x086
9D9B0>),
 {})
b = (('Something not false',
  <module 'ubunt...

Read more...

review: Needs Fixing
73. By Manuel de la Peña

Fixed the tests so that they take into account the new update method.

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

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

C:\Users\ROBERTO\canonical\fix_809873\scripts>"c:\Program Files (x86)\ubuntuone\dist\ubuntuone-installer-qt.exe"
Traceback (most recent call last):
  File "ubuntuone-installer-qt", line 51, in <module>
  File "ubuntuone_installer\gui\qt\main\windows.pyc", line 118, in main
  File "twisted\internet\defer.pyc", line 1141, in unwindGenerator
TypeError: check_credentials() takes at most 4 arguments (5 given)

review: Needs Fixing
74. By Manuel de la Peña

Pass the correct number of parameters.

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

2011-09-20 09:51:56,575 - ubuntuone.installer.qt.gui - INFO - Updates are present.
Unhandled error in Deferred:
Traceback (most recent call last):
  File "twisted\internet\defer.pyc", line 388, in errback

  File "twisted\internet\defer.pyc", line 455, in _startRunCallbacks

  File "twisted\internet\defer.pyc", line 542, in _runCallbacks

  File "twisted\internet\defer.pyc", line 1076, in gotResult

--- <exception caught here> ---
  File "twisted\internet\defer.pyc", line 1018, in _inlineCallbacks

  File "twisted\python\failure.pyc", line 349, in throwExceptionIntoGenerator

  File "ubuntuone_installer\gui\qt\main\windows.pyc", line 85, in check_credentials

  File "twisted\internet\defer.pyc", line 1018, in _inlineCallbacks

  File "twisted\python\failure.pyc", line 349, in throwExceptionIntoGenerator

  File "ubuntuone_installer\gui\qt\main\windows.pyc", line 56, in success_cb

  File "twisted\internet\defer.pyc", line 1020, in _inlineCallbacks

  File "ubuntuone_installer\gui\qt\main\windows.pyc", line 97, in check_updates

  File "ubuntuone_installer\gui\qt\gui.pyc", line 96, in user_wants_to_update

exceptions.NameError: global name 'UPDATE_TITLE' is not defined

75. By Manuel de la Peña

Added missing var.

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

Unhandled error in Deferred:
Traceback (most recent call last):
  File "twisted\internet\defer.pyc", line 388, in errback

  File "twisted\internet\defer.pyc", line 455, in _startRunCallbacks

  File "twisted\internet\defer.pyc", line 542, in _runCallbacks

  File "twisted\internet\defer.pyc", line 1076, in gotResult

--- <exception caught here> ---
  File "twisted\internet\defer.pyc", line 1018, in _inlineCallbacks

  File "twisted\python\failure.pyc", line 349, in throwExceptionIntoGenerator

  File "ubuntuone_installer\gui\qt\main\windows.pyc", line 85, in check_credentials

  File "twisted\internet\defer.pyc", line 1020, in _inlineCallbacks

  File "ubuntuone_installer\gui\qt\main\windows.pyc", line 58, in success_cb

  File "ubuntuone_installer\gui\qt\main\windows.pyc", line 38, in stop

  File "twisted\internet\base.pyc", line 570, in stop

twisted.internet.error.ReactorNotRunning: Can't stop reactor that isn't running.

76. By Manuel de la Peña

Merged with trunk.

77. By Manuel de la Peña

Removed the stop_fn since there is not need because the installer takes care of the situation in which the files are used.

Revision history for this message
Roberto Alsina (ralsina) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ubuntuone_installer/gui/qt/gui.py'
--- ubuntuone_installer/gui/qt/gui.py 2011-09-19 15:41:40 +0000
+++ ubuntuone_installer/gui/qt/gui.py 2011-09-22 19:45:30 +0000
@@ -84,12 +84,23 @@
84CREDENTIALS_ERROR = _('Application will close.\n\n%r')84CREDENTIALS_ERROR = _('Application will close.\n\n%r')
85SKIP_TOUR = _("Skip tour, go to Dashboard")85SKIP_TOUR = _("Skip tour, go to Dashboard")
86START_SETUP = _("Start setup")86START_SETUP = _("Start setup")
87UPDATE_TITLE = _("Updates are available")
88UPDATE_SOFTWARE = _("There is a new version available. Do you want perform an upgrade?")
87# Invalid name logger89# Invalid name logger
88# pylint: disable=C010390# pylint: disable=C0103
89logger = setup_logging('qt.gui')91logger = setup_logging('qt.gui')
90# pylint: enable=C010392# pylint: enable=C0103
9193
9294
95def user_wants_to_update():
96 """Ask the user if he really wants to update the software."""
97 result = QtGui.QMessageBox.question(None, UPDATE_TITLE, UPDATE_SOFTWARE,
98 QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
99 if result == QtGui.QMessageBox.Yes:
100 return True
101 return False
102
103
93class LicensePage(SSOWizardPage):104class LicensePage(SSOWizardPage):
94 """Wizard Page that displays the license info and links to the GPL."""105 """Wizard Page that displays the license info and links to the GPL."""
95106
96107
=== modified file 'ubuntuone_installer/gui/qt/main/tests/test_windows.py'
--- ubuntuone_installer/gui/qt/main/tests/test_windows.py 2011-09-19 23:00:32 +0000
+++ ubuntuone_installer/gui/qt/main/tests/test_windows.py 2011-09-22 19:45:30 +0000
@@ -59,22 +59,37 @@
59 """Fake Logger."""59 """Fake Logger."""
6060
61 error_args = None61 error_args = None
62 debug_args = None
63 info_args = None
6264
63 def error(self, *args, **kwargs):65 def error(self, *args, **kwargs):
64 """Save the error."""66 """Save the error."""
65 self.error_args = (args, kwargs)67 self.error_args = (args, kwargs)
6668
69 def debug(self, *args, **kwargs):
70 """Save the debug."""
71 self.debug_args = (args, kwargs)
72
73 def info(self, *args, **kwargs):
74 """Save the info."""
75 self.info_args = (args, kwargs)
76
6777
68class CredsFailureMainTestCase(TestCase):78class CredsFailureMainTestCase(TestCase):
6979
70 """Test the qt main window."""80 """Test the qt main window."""
7181
72 stopped = False82 stopped = False
83 updates_checked = False
7384
74 def stop(self):85 def stop(self):
75 """A fake stop."""86 """A fake stop."""
76 self.stopped = True87 self.stopped = True
7788
89 def check_updates(self, gui, logger):
90 """A fake check updates."""
91 self.updates_checked = True
92
78 @defer.inlineCallbacks93 @defer.inlineCallbacks
79 def test_failure(self):94 def test_failure(self):
80 """Credential errors should display a critical message."""95 """Credential errors should display a critical message."""
@@ -116,6 +131,7 @@
116 logger = FakeLogger()131 logger = FakeLogger()
117 self.patch(utils, 'start_control_panel', self._set_called)132 self.patch(utils, 'start_control_panel', self._set_called)
118 self.patch(windows, 'stop', self.stop)133 self.patch(windows, 'stop', self.stop)
134 self.patch(windows, 'check_updates', self.check_updates)
119 self.stopped = False135 self.stopped = False
120 yield windows.check_credentials(136 yield windows.check_credentials(
121 FakeCredentialsManagementTool,137 FakeCredentialsManagementTool,
@@ -126,6 +142,7 @@
126 self.assertEqual(self._called, ((), {'with_icon': False}))142 self.assertEqual(self._called, ((), {'with_icon': False}))
127 # Should stop the app143 # Should stop the app
128 self.assertTrue(self.stopped)144 self.assertTrue(self.stopped)
145 self.assertTrue(self.updates_checked)
129146
130 @defer.inlineCallbacks147 @defer.inlineCallbacks
131 def test_without_installed_flag(self):148 def test_without_installed_flag(self):
@@ -136,7 +153,7 @@
136 FakeCredentialsManagementTool,153 FakeCredentialsManagementTool,
137 gui, logger)154 gui, logger)
138 self.assertEqual(self._called, (('Something not false',155 self.assertEqual(self._called, (('Something not false',
139 gui, False), {}))156 gui, False, logger), {}))
140157
141 @defer.inlineCallbacks158 @defer.inlineCallbacks
142 def test_with_installed_flag(self):159 def test_with_installed_flag(self):
@@ -147,4 +164,4 @@
147 FakeCredentialsManagementTool,164 FakeCredentialsManagementTool,
148 gui, logger, installer=True)165 gui, logger, installer=True)
149 self.assertEqual(self._called, (('Something not false',166 self.assertEqual(self._called, (('Something not false',
150 gui, True), {}))167 gui, True, logger), {}))
151168
=== modified file 'ubuntuone_installer/gui/qt/main/windows.py'
--- ubuntuone_installer/gui/qt/main/windows.py 2011-09-19 23:00:32 +0000
+++ ubuntuone_installer/gui/qt/main/windows.py 2011-09-22 19:45:30 +0000
@@ -29,6 +29,7 @@
29# pylint: disable=W061129# pylint: disable=W0611
30from ubuntuone_installer.gui.qt.ui import images_rc30from ubuntuone_installer.gui.qt.ui import images_rc
31# pylint: enable=W061131# pylint: enable=W0611
32from ubuntuone_installer.gui.qt import utils
3233
3334
34def stop(*args):35def stop(*args):
@@ -43,14 +44,20 @@
43 'Error while getting the credentials: %r', exc)44 'Error while getting the credentials: %r', exc)
44 stop()45 stop()
4546
4647@defer.inlineCallbacks
47def success_cb(creds, gui, installing):48def success_cb(creds, gui, installing, logger):
48 """Handle credentials success."""49 """Handle credentials success."""
50 logger.debug('Got back from sso.')
49 if creds: # Have credentials already51 if creds: # Have credentials already
50 from ubuntuone_installer.gui.qt import utils52 logger.debug('Already got credentials.')
53 logger.info('Starting control panel.')
51 utils.start_control_panel(with_icon=False)54 utils.start_control_panel(with_icon=False)
55 logger.info('Checking updates.')
56 yield check_updates(gui, logger)
57 logger.info('Stopping.')
52 stop()58 stop()
53 else: # No credentials59 else: # No credentials
60 logger.debug('Did got connections.')
54 window = gui.MainWindow(close_callback=stop, installing=installing)61 window = gui.MainWindow(close_callback=stop, installing=installing)
55 # Set Application Style Sheet62 # Set Application Style Sheet
56 app = QtGui.QApplication.instance()63 app = QtGui.QApplication.instance()
@@ -65,7 +72,8 @@
6572
6673
67@defer.inlineCallbacks74@defer.inlineCallbacks
68def check_credentials(credentials_tool, gui, logger, installer=False):75def check_credentials(credentials_tool, gui, logger,
76 installer=False):
69 """Check credentials and either start u1cp or show the wizard."""77 """Check credentials and either start u1cp or show the wizard."""
70 credtool = credentials_tool()78 credtool = credentials_tool()
71 # pylint: disable=W070379 # pylint: disable=W0703
@@ -74,7 +82,23 @@
74 except Exception, exc:82 except Exception, exc:
75 error_cb(exc, logger)83 error_cb(exc, logger)
76 else:84 else:
77 success_cb(creds, gui, installer)85 yield success_cb(creds, gui, installer, logger)
86
87@defer.inlineCallbacks
88def check_updates(gui, logger):
89 """Check for updates."""
90 logger.info('Checking for updates.')
91 # the idea is simple, check if there are updates, ask user if we perform
92 # the update and continue.
93 are_updates_present = yield utils.are_updates_present(logger)
94 logger.debug('Updates present: %r', are_updates_present)
95 if are_updates_present:
96 logger.info('Updates are present.')
97 if gui.user_wants_to_update():
98 logger.info('Performing auto-update in diff process.')
99 utils.perform_update()
100 else:
101 logger.info('No updates are present.')
78102
79103
80def main(installing=False):104def main(installing=False):
81105
=== modified file 'ubuntuone_installer/gui/qt/tests/test_gui.py'
--- ubuntuone_installer/gui/qt/tests/test_gui.py 2011-09-21 18:24:39 +0000
+++ ubuntuone_installer/gui/qt/tests/test_gui.py 2011-09-22 19:45:30 +0000
@@ -22,6 +22,7 @@
22from PyQt4 import QtGui, QtCore22from PyQt4 import QtGui, QtCore
23from ubuntuone.controlpanel.gui import qt23from ubuntuone.controlpanel.gui import qt
24from ubuntuone.platform.credentials import APP_NAME24from ubuntuone.platform.credentials import APP_NAME
25from twisted.internet import defer
2526
26from ubuntuone_installer.gui import NEXT27from ubuntuone_installer.gui import NEXT
27from ubuntuone_installer.gui.qt import gui, forgotten, utils28from ubuntuone_installer.gui.qt import gui, forgotten, utils
@@ -662,3 +663,51 @@
662 [QtGui.QWizard.Stretch,663 [QtGui.QWizard.Stretch,
663 QtGui.QWizard.FinishButton,664 QtGui.QWizard.FinishButton,
664 QtGui.QWizard.NextButton])665 QtGui.QWizard.NextButton])
666
667class UpgradeQuestion(BaseTestCase):
668 """Test the dialog that ask the user if he wants to upgrade."""
669
670 @defer.inlineCallbacks
671 def setUp(self):
672 """Set the tests."""
673 yield super(UpgradeQuestion, self).setUp()
674 self.answer = 0
675 self.parent = None
676 self.title = None
677 self.text = None
678 self.yes_button = None
679 self.no_button = None
680
681 def fake_question(parent, title, text, yes_button,
682 no_button):
683 """Fake asking a question."""
684 self.parent = parent
685 self.title = title
686 self.text = text
687 self.yes_button = yes_button
688 self.no_button = no_button
689 return self.answer
690
691 self.patch(gui.QtGui.QMessageBox, 'question', fake_question)
692
693 def user_wants_to_update_true(self):
694 """Test the question."""
695 self.answer = gui.QtGui.QMessageBox.Yes
696 self.assertTrue(gui.user_wants_to_update(), 'User wants to update.')
697 # lets assert the parameters
698 self.assertTrue(None, self.parent)
699 self.assertTrue(self.title, gui.UPDATE_TITLE)
700 self.assertTrue(self.text, gui.UPDATE_SOFTWARE)
701 self.assertTrue(self.yes_button, gui.QtGui.QMessageBox.Yes)
702 self.assertTrue(self.no_button, gui.QtGui.QMessageBox.No)
703
704 def user_wants_to_update_false(self):
705 """Test the question."""
706 self.answer = gui.QtGui.QMessageBox.No
707 self.assertFalse(gui.user_wants_to_update(), 'User DOES NOT want to update.')
708 # lets assert the parameters
709 self.assertTrue(None, self.parent)
710 self.assertTrue(self.title, gui.UPDATE_TITLE)
711 self.assertTrue(self.text, gui.UPDATE_SOFTWARE)
712 self.assertTrue(self.yes_button, gui.QtGui.QMessageBox.Yes)
713 self.assertTrue(self.no_button, gui.QtGui.QMessageBox.No)
665714
=== modified file 'ubuntuone_installer/gui/qt/utils/__init__.py'
--- ubuntuone_installer/gui/qt/utils/__init__.py 2011-09-01 13:52:35 +0000
+++ ubuntuone_installer/gui/qt/utils/__init__.py 2011-09-22 19:45:30 +0000
@@ -28,9 +28,13 @@
28 start_control_panel = windows.start_control_panel28 start_control_panel = windows.start_control_panel
29 add_syncdaemon_to_autostart = windows.add_syncdaemon_to_autostart29 add_syncdaemon_to_autostart = windows.add_syncdaemon_to_autostart
30 default_folders = windows.default_folders30 default_folders = windows.default_folders
31 are_updates_present = windows.are_updates_present
32 perform_update = windows.perform_update
31else:33else:
32 from ubuntuone_installer.gui.qt.utils import linux34 from ubuntuone_installer.gui.qt.utils import linux
33 uninstall_application = linux.uninstall_application35 uninstall_application = linux.uninstall_application
34 start_control_panel = linux.start_control_panel36 start_control_panel = linux.start_control_panel
35 add_syncdaemon_to_autostart = linux.add_syncdaemon_to_autostart37 add_syncdaemon_to_autostart = linux.add_syncdaemon_to_autostart
36 default_folders = linux.default_folders38 default_folders = linux.default_folders
39 are_updates_present = lambda *args, **kwargs: False
40 perform_update = lambda *args, **kwargs: None
3741
=== modified file 'ubuntuone_installer/gui/qt/utils/tests/test_windows.py'
--- ubuntuone_installer/gui/qt/utils/tests/test_windows.py 2011-09-19 23:01:24 +0000
+++ ubuntuone_installer/gui/qt/utils/tests/test_windows.py 2011-09-22 19:45:30 +0000
@@ -27,6 +27,8 @@
27import win32api27import win32api
28# pylint: enable=F040128# pylint: enable=F0401
2929
30from twisted.internet import defer
31
30from ubuntuone_installer.gui.qt import utils32from ubuntuone_installer.gui.qt import utils
31from ubuntuone_installer.gui.qt.tests import BaseTestCase33from ubuntuone_installer.gui.qt.tests import BaseTestCase
3234
@@ -229,3 +231,86 @@
229 pictures = buf.value231 pictures = buf.value
230 expected = [docs, music, pictures]232 expected = [docs, music, pictures]
231 self.assertEqual(sorted(folders), sorted(expected))233 self.assertEqual(sorted(folders), sorted(expected))
234
235
236class FakeLogger(object):
237 """A Fake logging object."""
238
239 def __init__(self):
240 """Create a new instance."""
241 self.called_methods = []
242
243 def info(self, message, *args, **kwargs):
244 """Set an info log message."""
245 self.called_methods.append(('info', message, args, kwargs))
246
247 def debug(self, message, *args, **kwargs):
248 """Set a debug log message."""
249 self.called_methods.append(('debug', message, args, kwargs))
250
251
252class AutoupdaterTestCase(BaseTestCase):
253 """Test the code that is used for the auto update process."""
254
255 @defer.inlineCallbacks
256 def setUp(self):
257 """Prepare for the diff tests."""
258 yield super(AutoupdaterTestCase, self).setUp()
259 self.auto_update_path = r'path\to\exe'
260 self.return_from_call = 0
261 self.command = None
262 self.args = []
263
264 def fake_execute_process(command, args=None, path=None):
265 """Fake async process execution."""
266 self.command = command
267 self.args = args
268 return self.return_from_call
269
270 self.fake_logger = FakeLogger()
271 self.patch(utils.windows, 'getProcessValue', fake_execute_process)
272 self.patch(utils.windows, '_get_update_path',
273 lambda:self.auto_update_path)
274
275
276 @defer.inlineCallbacks
277 def test_are_updates_present_true(self):
278 """Test when updates are present."""
279 # the idea is simple, set the value to be returned from
280 # the fake call, assert that we get true and also that
281 # we did use the correct parameters.
282 self.return_from_call = 0
283 are_present = yield utils.are_updates_present(self.fake_logger)
284 self.assertTrue(are_present, 'Updates should be present.')
285 # lets assert that we did use the correct args
286 expected_args = ('--mode', 'unattended')
287 self.assertEqual(expected_args, self.args)
288 self.assertEqual(self.command, self.auto_update_path)
289
290
291 @defer.inlineCallbacks
292 def test_are_updates_present_false(self):
293 """Test when updates are not present."""
294 # similar to test_are_updates_present_true but with diff retcode
295 self.return_from_call = 40
296 are_present = yield utils.are_updates_present(self.fake_logger)
297 self.assertFalse(are_present, 'Updates should NOT be present.')
298 # lets assert that we did use the correct args
299 expected_args = ('--mode', 'unattended')
300 self.assertEqual(expected_args, self.args)
301 self.assertEqual(self.command, self.auto_update_path)
302
303 def test_perform_update(self):
304 """Test the method that perfroms the update."""
305 self.patch(utils.windows.win32api, 'ShellExecute', self._set_called)
306 utils.perform_update()
307 self.assertIn(self.auto_update_path, self._called[0][2])
308 self.assertEqual('runas', self._called[0][1])
309 self.assertEqual('--unattendedmodeui none', self._called[0][3])
310 self.assertEqual('', self._called[0][4])
311 self.assertEqual(0, self._called[0][5])
312
313 def test_get_auto_update_path(self):
314 """Test the method used to get the autoupdate."""
315
316
232317
=== modified file 'ubuntuone_installer/gui/qt/utils/windows.py'
--- ubuntuone_installer/gui/qt/utils/windows.py 2011-09-19 23:00:32 +0000
+++ ubuntuone_installer/gui/qt/utils/windows.py 2011-09-22 19:45:30 +0000
@@ -30,6 +30,9 @@
30import _winreg30import _winreg
31# pylint: enable=F040131# pylint: enable=F0401
3232
33from twisted.internet import defer
34from twisted.internet.utils import getProcessValue
35
33AUTORUN_KEY = r"Software\Microsoft\Windows\CurrentVersion\Run"36AUTORUN_KEY = r"Software\Microsoft\Windows\CurrentVersion\Run"
3437
3538
@@ -47,6 +50,47 @@
47 '--mode win32', '', 0)50 '--mode win32', '', 0)
4851
4952
53def _get_update_path():
54 """Return the path in which the autoupdate command is found."""
55 if hasattr(sys, "frozen"):
56 exec_path = os.path.abspath(sys.executable)
57 else:
58 exec_path = os.path.dirname(__file__)
59 folder = os.path.dirname(exec_path)
60 update_path = os.path.join(folder, "autoupdate-windows.exe")
61 if os.path.exists(update_path):
62 return update_path
63 return None
64
65
66@defer.inlineCallbacks
67def are_updates_present(logger):
68 """Return if there are updates for Ubuntu One."""
69 update_path = _get_update_path()
70 logger.debug('Update path %s', update_path)
71 if update_path is not None:
72 # If there is an update present we will get 0 and other number
73 # otherwise
74 retcode = yield getProcessValue(update_path, args=('--mode',
75 'unattended'), path=os.path.dirname(update_path))
76 logger.debug('Return code %s', retcode)
77 if retcode == 0:
78 logger.debug('Returning True')
79 defer.returnValue(True)
80 logger.debug('Returning False')
81 defer.returnValue(False)
82
83
84def perform_update():
85 """Spawn the autoupdate process and call the stop funtion."""
86 update_path = _get_update_path()
87 if update_path is not None:
88 # lets call the updater with the commands that are required,
89 win32api.ShellExecute(None, 'runas',
90 update_path,
91 '--unattendedmodeui none', '', 0)
92
93
50def start_control_panel(with_icon=True):94def start_control_panel(with_icon=True):
51 """Start the control panel."""95 """Start the control panel."""
52 # If we are in windows and "frozen", assume it's in96 # If we are in windows and "frozen", assume it's in

Subscribers

People subscribed via source and target branches