Merge lp:~mandel/ubuntuone-control-panel/auto-update-functions into lp:ubuntuone-control-panel

Proposed by Manuel de la Peña
Status: Merged
Approved by: Natalia Bidart
Approved revision: 245
Merged at revision: 243
Proposed branch: lp:~mandel/ubuntuone-control-panel/auto-update-functions
Merge into: lp:ubuntuone-control-panel
Diff against target: 437 lines (+333/-7)
8 files modified
run-tests (+3/-2)
run-tests.bat (+3/-2)
ubuntuone/controlpanel/utils/__init__.py (+16/-2)
ubuntuone/controlpanel/utils/tests/__init__.py (+18/-0)
ubuntuone/controlpanel/utils/tests/test_linux.py (+38/-0)
ubuntuone/controlpanel/utils/tests/test_utils.py (+3/-1)
ubuntuone/controlpanel/utils/tests/test_windows.py (+179/-0)
ubuntuone/controlpanel/utils/windows.py (+73/-0)
To merge this branch: bzr merge lp:~mandel/ubuntuone-control-panel/auto-update-functions
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+80237@code.launchpad.net

Commit message

Moves auto-update code from the u1-windows-installer to the control panel.

Description of the change

Moves auto-update code from the u1-windows-installer to the control panel.

To post a comment you must log in.
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

utils.os.path.pardir, esta repetido:

158 + utils.os.path.pardir,
159 + utils.os.path.pardir,

review: Needs Fixing
Revision history for this message
Manuel de la Peña (mandel) wrote :

> utils.os.path.pardir, esta repetido:
>
> 158 + utils.os.path.pardir,
> 159 + utils.os.path.pardir,

Actually that is a fix, you need to move an extra level up since we now have utils as a pacakage :)

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

+1

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

A few minor tweaks:

* instead of duplicating the -i "test_windows.py" in run-tests, please define a new bash variable and use that

* we're trying to get rid of the authors section of the source headers, so instead of adding yourself, please remove all the authors in the files you modify :-)

* remember to always use %r for logging stuff

* why are we receiving the logger by parameter? that makes the api of the methods weird... let's grab the logger just like in the rest of the app (and then we can remove the fake logger altogether):

from ubuntuone.controlpanel import set_up_logger

logger = set_up_logger('utils')

* the logging itself could use some improvement, so when seen in a log file our of the code context, we can understand what information is giving us. So below I propose a new version of are_updates_present:

@defer.inlineCallbacks
def are_updates_present():
    """Return if there are updates for Ubuntu One."""
     result = False
     retcode = None
    update_path = _get_update_path()
    if update_path is not None:
        # If there is an update present we will get 0, non-zero otherwise
        retcode = yield getProcessValue(update_path, args=('--mode',
            'unattended'), path=os.path.dirname(update_path))
        result = retcode == 0
    logger.debug('are_updates_present: update path: %r, return code: %r, result: %r',
                 update_path, retcode, result)
    defer.returnValue(result)

* Remember to have cleanup code to be run ALWAYS, even if the test fails. In your tests, the cleanup code is only run if none of the asserts failed. So, please use self.addCleanup calls as soon as you modify the env for the test.

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

Fixed branch according to review comments.

Revision history for this message
Manuel de la Peña (mandel) wrote :

> A few minor tweaks:
>
> * instead of duplicating the -i "test_windows.py" in run-tests, please define
> a new bash variable and use that
>
> * we're trying to get rid of the authors section of the source headers, so
> instead of adding yourself, please remove all the authors in the files you
> modify :-)
>
> * remember to always use %r for logging stuff
>
> * why are we receiving the logger by parameter? that makes the api of the
> methods weird... let's grab the logger just like in the rest of the app (and
> then we can remove the fake logger altogether):
>
> from ubuntuone.controlpanel import set_up_logger
>
> logger = set_up_logger('utils')
>
> * the logging itself could use some improvement, so when seen in a log file
> our of the code context, we can understand what information is giving us. So
> below I propose a new version of are_updates_present:
>
> @defer.inlineCallbacks
> def are_updates_present():
> """Return if there are updates for Ubuntu One."""
> result = False
> retcode = None
> update_path = _get_update_path()
> if update_path is not None:
> # If there is an update present we will get 0, non-zero otherwise
> retcode = yield getProcessValue(update_path, args=('--mode',
> 'unattended'), path=os.path.dirname(update_path))
> result = retcode == 0
> logger.debug('are_updates_present: update path: %r, return code: %r,
> result: %r',
> update_path, retcode, result)
> defer.returnValue(result)
>
> * Remember to have cleanup code to be run ALWAYS, even if the test fails. In
> your tests, the cleanup code is only run if none of the asserts failed. So,
> please use self.addCleanup calls as soon as you modify the env for the test.

Fixed all of them :)

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

I'm having this test failure on windows:

===============================================================================
[FAIL]
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\ubuntuone-dev-tools\ubuntuone\devtools\tes
ting\txcheck.py", line 355, in run
    raise problem
ubuntuone.devtools.testing.txcheck.SuperNotCalled: SuperNotCalled for ubuntuone.
controlpanel.utils.tests.test_windows.GetPathTestCase.setUp

ubuntuone.devtools.testing.txcheck.TXCheckTest.runTest

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

Call super.setUp()

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

* addCleanup supports passing arguments next to the function, so instead of

+ self.addCleanup(lambda: self._reset_frozen_state(old_frozen,
+ old_exec_path))

you just have to call:

+ self.addCleanup(self._reset_frozen_state, old_frozen, old_exec_path)

Same for:

+ self.addCleanup(lambda: self._reset__file__(old_file))

you just have to call:

+ self.addCleanup(self._reset__file__, old_file)

* On ubuntuone/controlpanel/utils/windows.py, define logger globally so is accessible to the whole module, and to also maintain consistency with the rest of the project.

The rest looks good!

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

Made changes according to reviews.

245. By Manuel de la Peña

Merged with parent.

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
=== modified file 'run-tests'
--- run-tests 2011-10-05 18:17:47 +0000
+++ run-tests 2011-11-15 13:13:25 +0000
@@ -18,6 +18,7 @@
1818
19QT_TESTS_PATH=ubuntuone/controlpanel/gui/qt/tests19QT_TESTS_PATH=ubuntuone/controlpanel/gui/qt/tests
20GTK_TESTS_PATH=ubuntuone/controlpanel/gui/gtk/tests20GTK_TESTS_PATH=ubuntuone/controlpanel/gui/gtk/tests
21WINDOWS_TESTS=test_windows.py
2122
22set -e23set -e
2324
@@ -50,9 +51,9 @@
50./setup.py build51./setup.py build
51echo "Running test suite for ""$MODULE"52echo "Running test suite for ""$MODULE"
52if [ "$USE_QT" -eq 0 ]; then53if [ "$USE_QT" -eq 0 ]; then
53 `which xvfb-run` u1trial --ignore-paths $QT_TESTS_PATH "$MODULE"54 `which xvfb-run` u1trial --ignore-paths "$QT_TESTS_PATH" -i "$WINDOWS_TESTS" "$MODULE"
54else55else
55 `which xvfb-run` u1trial --ignore-paths $GTK_TESTS_PATH --reactor=qt4 --gui "$MODULE"56 `which xvfb-run` u1trial --ignore-paths "$GTK_TESTS_PATH" -i "$WINDOWS_TESTS" --reactor=qt4 --gui "$MODULE"
56fi57fi
57style_check58style_check
58rm -rf _trial_temp59rm -rf _trial_temp
5960
=== modified file 'run-tests.bat'
--- run-tests.bat 2011-10-06 20:38:39 +0000
+++ run-tests.bat 2011-11-15 13:13:25 +0000
@@ -20,12 +20,13 @@
2020
21SET MODULE="ubuntuone"21SET MODULE="ubuntuone"
22SET PYTHONEXEPATH="C:\Python27"22SET PYTHONEXEPATH="C:\Python27"
23SET IGNORE_PATHS="ubuntuone\controlpanel\gui\gtk, ubuntuone\controlpanel\dbustests, ubuntuone\controlpanel\web_client\tests\test_libsoup.py"23SET IGNORE_PATHS="ubuntuone\controlpanel\gui\gtk, ubuntuone\controlpanel\dbustests"
24SET IGNORE_MODULES="test_linux.py, test_libsoup.py"
2425
25"%PYTHONEXEPATH%\python.exe" setup.py build26"%PYTHONEXEPATH%\python.exe" setup.py build
26ECHO Running tests27ECHO Running tests
27:: execute the tests with a number of ignored linux only modules28:: execute the tests with a number of ignored linux only modules
28"%PYTHONEXEPATH%\python.exe" "%PYTHONEXEPATH%\Scripts\u1trial" --reactor=qt4 --gui -p %IGNORE_PATHS% %MODULE%29"%PYTHONEXEPATH%\python.exe" "%PYTHONEXEPATH%\Scripts\u1trial" --reactor=qt4 --gui -p %IGNORE_PATHS% -i %IGNORE_MODULES% %MODULE%
29:: Clean the build from the setupt.py30:: Clean the build from the setupt.py
30ECHO Cleaning the generated code before running the style checks...31ECHO Cleaning the generated code before running the style checks...
31"%PYTHONEXEPATH%\python.exe" setup.py clean32"%PYTHONEXEPATH%\python.exe" setup.py clean
3233
=== added directory 'ubuntuone/controlpanel/utils'
=== renamed file 'ubuntuone/controlpanel/utils.py' => 'ubuntuone/controlpanel/utils/__init__.py'
--- ubuntuone/controlpanel/utils.py 2011-06-29 18:10:16 +0000
+++ ubuntuone/controlpanel/utils/__init__.py 2011-11-15 13:13:25 +0000
@@ -1,6 +1,5 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
22
3# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
4#3#
5# Copyright 2010 Canonical Ltd.4# Copyright 2010 Canonical Ltd.
6#5#
@@ -19,6 +18,7 @@
19"""Miscellaneous utilities."""18"""Miscellaneous utilities."""
2019
21import os20import os
21import sys
2222
23from ubuntuone.controlpanel.logger import setup_logging23from ubuntuone.controlpanel.logger import setup_logging
2424
@@ -30,6 +30,19 @@
30ERROR_TYPE = 'error_type'30ERROR_TYPE = 'error_type'
31ERROR_MESSAGE = 'error_msg'31ERROR_MESSAGE = 'error_msg'
3232
33# ignore issues with the name of the method
34# pylint: disable=C0103
35
36# import the platform dependent code.
37if sys.platform == 'win32':
38 from ubuntuone.controlpanel.utils import windows
39 are_updates_present = windows.are_updates_present
40 perform_update = windows.perform_update
41else:
42 are_updates_present = lambda *args, **kwargs: False
43 perform_update = lambda *args, **kwargs: None
44# pylint: enable=C0103
45
3346
34def get_project_dir():47def get_project_dir():
35 """Return the absolute path to this project's data/ dir.48 """Return the absolute path to this project's data/ dir.
@@ -38,7 +51,8 @@
38 """51 """
39 module = os.path.dirname(__file__)52 module = os.path.dirname(__file__)
40 result = os.path.abspath(os.path.join(module, os.path.pardir,53 result = os.path.abspath(os.path.join(module, os.path.pardir,
41 os.path.pardir, DATA_SUFFIX))54 os.path.pardir, os.path.pardir,
55 DATA_SUFFIX))
42 logger.debug('get_project_dir: trying use data dir at %r (exists? %s)',56 logger.debug('get_project_dir: trying use data dir at %r (exists? %s)',
43 result, os.path.exists(result))57 result, os.path.exists(result))
44 if os.path.exists(result):58 if os.path.exists(result):
4559
=== added directory 'ubuntuone/controlpanel/utils/tests'
=== added file 'ubuntuone/controlpanel/utils/tests/__init__.py'
--- ubuntuone/controlpanel/utils/tests/__init__.py 1970-01-01 00:00:00 +0000
+++ ubuntuone/controlpanel/utils/tests/__init__.py 2011-11-15 13:13:25 +0000
@@ -0,0 +1,18 @@
1# -*- coding: utf-8 -*-
2
3#
4# Copyright 2010 Canonical Ltd.
5#
6# This program is free software: you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 3, as published
8# by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranties of
12# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13# PURPOSE. See the GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program. If not, see <http://www.gnu.org/licenses/>.
17
18"""Test utils."""
019
=== added file 'ubuntuone/controlpanel/utils/tests/test_linux.py'
--- ubuntuone/controlpanel/utils/tests/test_linux.py 1970-01-01 00:00:00 +0000
+++ ubuntuone/controlpanel/utils/tests/test_linux.py 2011-11-15 13:13:25 +0000
@@ -0,0 +1,38 @@
1# -*- coding: utf-8 -*-
2
3#
4# Copyright 2011 Canonical Ltd.
5#
6# This program is free software: you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 3, as published
8# by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranties of
12# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13# PURPOSE. See the GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program. If not, see <http://www.gnu.org/licenses/>.
17
18"""Test the linux utils functions."""
19
20
21from twisted.internet import defer
22
23from ubuntuone.controlpanel import utils
24from ubuntuone.controlpanel.tests import TestCase
25
26
27class AutoupdaterTestCase(TestCase):
28 """Test the code that is used for the auto update process."""
29
30 @defer.inlineCallbacks
31 def test_are_updates_present(self):
32 """We should never have updates."""
33 are_present = yield utils.are_updates_present(None)
34 self.assertFalse(are_present)
35
36 def test_perform_update(self):
37 """Test the method that performs the update."""
38 self.assertEqual(None, utils.perform_update())
039
=== renamed file 'ubuntuone/controlpanel/tests/test_utils.py' => 'ubuntuone/controlpanel/utils/tests/test_utils.py'
--- ubuntuone/controlpanel/tests/test_utils.py 2011-10-24 21:48:27 +0000
+++ ubuntuone/controlpanel/utils/tests/test_utils.py 2011-11-15 13:13:25 +0000
@@ -73,7 +73,9 @@
73 """The relative path for the data directory is correctly retrieved."""73 """The relative path for the data directory is correctly retrieved."""
74 module = utils.os.path.dirname(utils.__file__)74 module = utils.os.path.dirname(utils.__file__)
75 rel_data = utils.os.path.join(module, utils.os.path.pardir,75 rel_data = utils.os.path.join(module, utils.os.path.pardir,
76 utils.os.path.pardir, utils.DATA_SUFFIX)76 utils.os.path.pardir,
77 utils.os.path.pardir,
78 utils.DATA_SUFFIX)
77 expected_dir = utils.os.path.abspath(rel_data)79 expected_dir = utils.os.path.abspath(rel_data)
7880
79 # ensure expected_path exists at os level81 # ensure expected_path exists at os level
8082
=== added file 'ubuntuone/controlpanel/utils/tests/test_windows.py'
--- ubuntuone/controlpanel/utils/tests/test_windows.py 1970-01-01 00:00:00 +0000
+++ ubuntuone/controlpanel/utils/tests/test_windows.py 2011-11-15 13:13:25 +0000
@@ -0,0 +1,179 @@
1# -*- coding: utf-8 -*-
2
3#
4# Copyright 2011 Canonical Ltd.
5#
6# This program is free software: you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 3, as published
8# by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranties of
12# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13# PURPOSE. See the GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program. If not, see <http://www.gnu.org/licenses/>.
17
18"""Test the windows utils functions."""
19
20import os
21
22from twisted.internet import defer
23
24from ubuntuone.controlpanel import utils
25from ubuntuone.controlpanel.tests import TestCase
26
27# let me use protected methods
28# pylint: disable=W0212
29
30
31class AutoupdaterTestCase(TestCase):
32 """Test the code that is used for the auto update process."""
33
34 @defer.inlineCallbacks
35 def setUp(self):
36 """Prepare for the diff tests."""
37 yield super(AutoupdaterTestCase, self).setUp()
38 self.auto_update_path = r'path\to\exe'
39 self.return_from_call = 0
40 self.command = None
41 self.args = []
42
43 def fake_execute_process(command, args=None, path=None):
44 """Fake async process execution."""
45 self.command = command
46 self.args = args
47 return self.return_from_call
48
49 self.patch(utils.windows, 'getProcessValue', fake_execute_process)
50 self.patch(utils.windows, '_get_update_path',
51 lambda: self.auto_update_path)
52
53 @defer.inlineCallbacks
54 def test_are_updates_present_true(self):
55 """Test when updates are present."""
56 # the idea is simple, set the value to be returned from
57 # the fake call, assert that we get true and also that
58 # we did use the correct parameters.
59 self.return_from_call = 0
60 are_present = yield utils.are_updates_present()
61 self.assertTrue(are_present, 'Updates should be present.')
62 # lets assert that we did use the correct args
63 expected_args = ('--mode', 'unattended')
64 self.assertEqual(expected_args, self.args)
65 self.assertEqual(self.command, self.auto_update_path)
66
67 @defer.inlineCallbacks
68 def test_are_updates_present_false(self):
69 """Test when updates are not present."""
70 # similar to test_are_updates_present_true but with diff retcode
71 self.return_from_call = 40
72 are_present = yield utils.are_updates_present()
73 self.assertFalse(are_present, 'Updates should NOT be present.')
74 # lets assert that we did use the correct args
75 expected_args = ('--mode', 'unattended')
76 self.assertEqual(expected_args, self.args)
77 self.assertEqual(self.command, self.auto_update_path)
78
79 def test_perform_update(self):
80 """Test the method that performs the update."""
81 self.patch(utils.windows.win32api, 'ShellExecute', self._set_called)
82 utils.perform_update()
83 self.assertIn(self.auto_update_path, self._called[0][2])
84 self.assertEqual('runas', self._called[0][1])
85 self.assertEqual('--unattendedmodeui none', self._called[0][3])
86 self.assertEqual('', self._called[0][4])
87 self.assertEqual(0, self._called[0][5])
88
89
90class GetPathTestCase(TestCase):
91 """Test the code that is used for the auto update process."""
92
93 @defer.inlineCallbacks
94 def setUp(self):
95 """Set the different tests."""
96 yield super(GetPathTestCase, self).setUp()
97 self.called = []
98 self.exec_path = 'path/to/current/exe'
99 self.exists = True
100
101 def fake_abspath(path):
102 """Fake os.path.abspath."""
103 self.called.append('os.path.abspath')
104 return path
105
106 def fake_dirname(path):
107 """Fake os.path.dirname."""
108 self.called.append('os.path.dirname')
109 return path
110
111 def fake_exists(path):
112 """Fake os.path.exists."""
113 self.called.append('os.path.exists')
114 return self.exists
115
116 # patch the os.path functions used
117 self.patch(utils.windows.os.path, 'abspath', fake_abspath)
118 self.patch(utils.windows.os.path, 'dirname', fake_dirname)
119 self.patch(utils.windows.os.path, 'exists', fake_exists)
120
121 def _delete_frozen_state(self):
122 """Delete the frozen state."""
123 del utils.windows.sys.frozen
124 del utils.windows.sys.executable
125
126 def test_get_auto_update_path_frozen(self):
127 """Test the method used to get the autoupdate."""
128 # patch the diff parts of sys so that we get fake paths
129 is_frozen = hasattr(utils.windows.sys, 'frozen')
130 if not is_frozen:
131 utils.windows.sys.frozen = True
132 utils.windows.sys.executable = self.exec_path
133 self.addCleanup(self._delete_frozen_state)
134
135 # called method and assert that we have the correct result
136 path = utils.windows._get_update_path()
137 self.assertEqual(os.path.join(self.exec_path,
138 utils.windows.AUTOUPDATE_EXE_NAME), path)
139 self.assertTrue('os.path.abspath' in self.called)
140 self.assertTrue('os.path.dirname' in self.called)
141 self.assertTrue('os.path.exists' in self.called)
142
143 def _reset_frozen_state(self, old_frozen, old_exec_path):
144 """Reset the frozen state."""
145 utils.windows.sys.frozen = old_frozen
146 utils.windows.sys.executable = old_exec_path
147
148 def _reset__file__(self, path):
149 """Reset the value of __file__."""
150 utils.windows.__file__ = path
151
152 def test_get_auto_update_path_not_frozen(self):
153 """Test the method used to get the autoupdate."""
154 is_frozen = hasattr(utils.windows.sys, 'frozen')
155 if is_frozen:
156 old_frozen = utils.windows.sys.frozen
157 old_exec_path = utils.windows.sys.executable
158 del utils.windows.sys.frozen
159 del utils.windows.sys.executable
160 self.addCleanup(self._reset_frozen_state, old_frozen,
161 old_exec_path)
162 # set a fake __file__ for the module
163 old_file = utils.windows.__file__
164 utils.windows.__file__ = self.exec_path
165 self.addCleanup(self._reset__file__, old_file)
166
167 path = utils.windows._get_update_path()
168 self.assertEqual(os.path.join(self.exec_path,
169 utils.windows.AUTOUPDATE_EXE_NAME), path)
170 self.assertEqual(2, self.called.count('os.path.dirname'))
171 self.assertTrue('os.path.exists' in self.called)
172
173 def test_get_auto_update_path_not_present(self):
174 """Test the method used to get the autoupdate."""
175 self.exists = False
176
177 # called method and assert that we have the correct result
178 path = utils.windows._get_update_path()
179 self.assertEqual(None, path)
0180
=== added file 'ubuntuone/controlpanel/utils/windows.py'
--- ubuntuone/controlpanel/utils/windows.py 1970-01-01 00:00:00 +0000
+++ ubuntuone/controlpanel/utils/windows.py 2011-11-15 13:13:25 +0000
@@ -0,0 +1,73 @@
1# -*- coding: utf-8 -*-
2
3#
4# Copyright 2011 Canonical Ltd.
5#
6# This program is free software: you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 3, as published
8# by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranties of
12# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13# PURPOSE. See the GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program. If not, see <http://www.gnu.org/licenses/>.
17
18"""Autoupdate functions for windows."""
19
20import os
21import sys
22
23# Avoid pylint error on Linux
24# pylint: disable=F0401
25import win32api
26# pylint: enable=F0401
27
28from twisted.internet import defer
29from twisted.internet.utils import getProcessValue
30
31from ubuntuone.controlpanel.logger import setup_logging
32
33logger = setup_logging('utils')
34AUTOUPDATE_EXE_NAME = 'autoupdate-windows.exe'
35
36
37def _get_update_path():
38 """Return the path in which the autoupdate command is found."""
39 if hasattr(sys, 'frozen'):
40 exec_path = os.path.abspath(sys.executable)
41 else:
42 exec_path = os.path.dirname(__file__)
43 folder = os.path.dirname(exec_path)
44 update_path = os.path.join(folder, AUTOUPDATE_EXE_NAME)
45 if os.path.exists(update_path):
46 return update_path
47 return None
48
49
50@defer.inlineCallbacks
51def are_updates_present():
52 """Return if there are updates for Ubuntu One."""
53 result = False
54 retcode = None
55 update_path = _get_update_path()
56 if update_path is not None:
57 # If there is an update present we will get 0, non-zero otherwise
58 retcode = yield getProcessValue(update_path, args=('--mode',
59 'unattended'), path=os.path.dirname(update_path))
60 result = retcode == 0
61 logger.debug('are_updates_present: update path: %r, return code: %r,'
62 ' result: %r', update_path, retcode, result)
63 defer.returnValue(result)
64
65
66def perform_update():
67 """Spawn the autoupdate process and call the stop function."""
68 update_path = _get_update_path()
69 if update_path is not None:
70 # lets call the updater with the commands that are required,
71 win32api.ShellExecute(None, 'runas',
72 update_path,
73 '--unattendedmodeui none', '', 0)

Subscribers

People subscribed via source and target branches

to all changes: