Merge lp:~mandel/ubuntuone-control-panel/auto-update-functions into lp:ubuntuone-control-panel
- auto-update-functions
- Merge into trunk
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 |
Related bugs: |
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-
Description of the change
Moves auto-update code from the u1-windows-
Manuel de la Peña (mandel) wrote : | # |
> utils.os.
>
> 158 + utils.os.
> 159 + utils.os.
Actually that is a fix, you need to move an extra level up since we now have utils as a pacakage :)
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.
logger = set_up_
* 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_
@defer.
def are_updates_
"""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
result = retcode == 0
logger.
defer.
* 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.
- 241. By Manuel de la Peña
-
Fixed branch according to review comments.
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.
>
> logger = set_up_
>
> * 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_
>
> @defer.
> def are_updates_
> """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
> 'unattended'), path=os.
> result = retcode == 0
> logger.
> result: %r',
> update_path, retcode, result)
> defer.returnVal
>
> * 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 :)
Natalia Bidart (nataliabidart) wrote : | # |
I'm having this test failure on windows:
=======
[FAIL]
Traceback (most recent call last):
File "C:\Python27\
ting\txcheck.py", line 355, in run
raise problem
ubuntuone.
controlpanel.
ubuntuone.
- 243. By Manuel de la Peña
-
Call super.setUp()
Natalia Bidart (nataliabidart) wrote : | # |
* addCleanup supports passing arguments next to the function, so instead of
+ self.addCleanup
+ old_exec_path))
you just have to call:
+ self.addCleanup
Same for:
+ self.addCleanup
you just have to call:
+ self.addCleanup
* On ubuntuone/
The rest looks good!
- 244. By Manuel de la Peña
-
Made changes according to reviews.
- 245. By Manuel de la Peña
-
Merged with parent.
Natalia Bidart (nataliabidart) wrote : | # |
Looks good!
Preview Diff
1 | === modified file 'run-tests' |
2 | --- run-tests 2011-10-05 18:17:47 +0000 |
3 | +++ run-tests 2011-11-15 13:13:25 +0000 |
4 | @@ -18,6 +18,7 @@ |
5 | |
6 | QT_TESTS_PATH=ubuntuone/controlpanel/gui/qt/tests |
7 | GTK_TESTS_PATH=ubuntuone/controlpanel/gui/gtk/tests |
8 | +WINDOWS_TESTS=test_windows.py |
9 | |
10 | set -e |
11 | |
12 | @@ -50,9 +51,9 @@ |
13 | ./setup.py build |
14 | echo "Running test suite for ""$MODULE" |
15 | if [ "$USE_QT" -eq 0 ]; then |
16 | - `which xvfb-run` u1trial --ignore-paths $QT_TESTS_PATH "$MODULE" |
17 | + `which xvfb-run` u1trial --ignore-paths "$QT_TESTS_PATH" -i "$WINDOWS_TESTS" "$MODULE" |
18 | else |
19 | - `which xvfb-run` u1trial --ignore-paths $GTK_TESTS_PATH --reactor=qt4 --gui "$MODULE" |
20 | + `which xvfb-run` u1trial --ignore-paths "$GTK_TESTS_PATH" -i "$WINDOWS_TESTS" --reactor=qt4 --gui "$MODULE" |
21 | fi |
22 | style_check |
23 | rm -rf _trial_temp |
24 | |
25 | === modified file 'run-tests.bat' |
26 | --- run-tests.bat 2011-10-06 20:38:39 +0000 |
27 | +++ run-tests.bat 2011-11-15 13:13:25 +0000 |
28 | @@ -20,12 +20,13 @@ |
29 | |
30 | SET MODULE="ubuntuone" |
31 | SET PYTHONEXEPATH="C:\Python27" |
32 | -SET IGNORE_PATHS="ubuntuone\controlpanel\gui\gtk, ubuntuone\controlpanel\dbustests, ubuntuone\controlpanel\web_client\tests\test_libsoup.py" |
33 | +SET IGNORE_PATHS="ubuntuone\controlpanel\gui\gtk, ubuntuone\controlpanel\dbustests" |
34 | +SET IGNORE_MODULES="test_linux.py, test_libsoup.py" |
35 | |
36 | "%PYTHONEXEPATH%\python.exe" setup.py build |
37 | ECHO Running tests |
38 | :: execute the tests with a number of ignored linux only modules |
39 | -"%PYTHONEXEPATH%\python.exe" "%PYTHONEXEPATH%\Scripts\u1trial" --reactor=qt4 --gui -p %IGNORE_PATHS% %MODULE% |
40 | +"%PYTHONEXEPATH%\python.exe" "%PYTHONEXEPATH%\Scripts\u1trial" --reactor=qt4 --gui -p %IGNORE_PATHS% -i %IGNORE_MODULES% %MODULE% |
41 | :: Clean the build from the setupt.py |
42 | ECHO Cleaning the generated code before running the style checks... |
43 | "%PYTHONEXEPATH%\python.exe" setup.py clean |
44 | |
45 | === added directory 'ubuntuone/controlpanel/utils' |
46 | === renamed file 'ubuntuone/controlpanel/utils.py' => 'ubuntuone/controlpanel/utils/__init__.py' |
47 | --- ubuntuone/controlpanel/utils.py 2011-06-29 18:10:16 +0000 |
48 | +++ ubuntuone/controlpanel/utils/__init__.py 2011-11-15 13:13:25 +0000 |
49 | @@ -1,6 +1,5 @@ |
50 | # -*- coding: utf-8 -*- |
51 | |
52 | -# Authors: Natalia B Bidart <natalia.bidart@canonical.com> |
53 | # |
54 | # Copyright 2010 Canonical Ltd. |
55 | # |
56 | @@ -19,6 +18,7 @@ |
57 | """Miscellaneous utilities.""" |
58 | |
59 | import os |
60 | +import sys |
61 | |
62 | from ubuntuone.controlpanel.logger import setup_logging |
63 | |
64 | @@ -30,6 +30,19 @@ |
65 | ERROR_TYPE = 'error_type' |
66 | ERROR_MESSAGE = 'error_msg' |
67 | |
68 | +# ignore issues with the name of the method |
69 | +# pylint: disable=C0103 |
70 | + |
71 | +# import the platform dependent code. |
72 | +if sys.platform == 'win32': |
73 | + from ubuntuone.controlpanel.utils import windows |
74 | + are_updates_present = windows.are_updates_present |
75 | + perform_update = windows.perform_update |
76 | +else: |
77 | + are_updates_present = lambda *args, **kwargs: False |
78 | + perform_update = lambda *args, **kwargs: None |
79 | +# pylint: enable=C0103 |
80 | + |
81 | |
82 | def get_project_dir(): |
83 | """Return the absolute path to this project's data/ dir. |
84 | @@ -38,7 +51,8 @@ |
85 | """ |
86 | module = os.path.dirname(__file__) |
87 | result = os.path.abspath(os.path.join(module, os.path.pardir, |
88 | - os.path.pardir, DATA_SUFFIX)) |
89 | + os.path.pardir, os.path.pardir, |
90 | + DATA_SUFFIX)) |
91 | logger.debug('get_project_dir: trying use data dir at %r (exists? %s)', |
92 | result, os.path.exists(result)) |
93 | if os.path.exists(result): |
94 | |
95 | === added directory 'ubuntuone/controlpanel/utils/tests' |
96 | === added file 'ubuntuone/controlpanel/utils/tests/__init__.py' |
97 | --- ubuntuone/controlpanel/utils/tests/__init__.py 1970-01-01 00:00:00 +0000 |
98 | +++ ubuntuone/controlpanel/utils/tests/__init__.py 2011-11-15 13:13:25 +0000 |
99 | @@ -0,0 +1,18 @@ |
100 | +# -*- coding: utf-8 -*- |
101 | + |
102 | +# |
103 | +# Copyright 2010 Canonical Ltd. |
104 | +# |
105 | +# This program is free software: you can redistribute it and/or modify it |
106 | +# under the terms of the GNU General Public License version 3, as published |
107 | +# by the Free Software Foundation. |
108 | +# |
109 | +# This program is distributed in the hope that it will be useful, but |
110 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
111 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
112 | +# PURPOSE. See the GNU General Public License for more details. |
113 | +# |
114 | +# You should have received a copy of the GNU General Public License along |
115 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
116 | + |
117 | +"""Test utils.""" |
118 | |
119 | === added file 'ubuntuone/controlpanel/utils/tests/test_linux.py' |
120 | --- ubuntuone/controlpanel/utils/tests/test_linux.py 1970-01-01 00:00:00 +0000 |
121 | +++ ubuntuone/controlpanel/utils/tests/test_linux.py 2011-11-15 13:13:25 +0000 |
122 | @@ -0,0 +1,38 @@ |
123 | +# -*- coding: utf-8 -*- |
124 | + |
125 | +# |
126 | +# Copyright 2011 Canonical Ltd. |
127 | +# |
128 | +# This program is free software: you can redistribute it and/or modify it |
129 | +# under the terms of the GNU General Public License version 3, as published |
130 | +# by the Free Software Foundation. |
131 | +# |
132 | +# This program is distributed in the hope that it will be useful, but |
133 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
134 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
135 | +# PURPOSE. See the GNU General Public License for more details. |
136 | +# |
137 | +# You should have received a copy of the GNU General Public License along |
138 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
139 | + |
140 | +"""Test the linux utils functions.""" |
141 | + |
142 | + |
143 | +from twisted.internet import defer |
144 | + |
145 | +from ubuntuone.controlpanel import utils |
146 | +from ubuntuone.controlpanel.tests import TestCase |
147 | + |
148 | + |
149 | +class AutoupdaterTestCase(TestCase): |
150 | + """Test the code that is used for the auto update process.""" |
151 | + |
152 | + @defer.inlineCallbacks |
153 | + def test_are_updates_present(self): |
154 | + """We should never have updates.""" |
155 | + are_present = yield utils.are_updates_present(None) |
156 | + self.assertFalse(are_present) |
157 | + |
158 | + def test_perform_update(self): |
159 | + """Test the method that performs the update.""" |
160 | + self.assertEqual(None, utils.perform_update()) |
161 | |
162 | === renamed file 'ubuntuone/controlpanel/tests/test_utils.py' => 'ubuntuone/controlpanel/utils/tests/test_utils.py' |
163 | --- ubuntuone/controlpanel/tests/test_utils.py 2011-10-24 21:48:27 +0000 |
164 | +++ ubuntuone/controlpanel/utils/tests/test_utils.py 2011-11-15 13:13:25 +0000 |
165 | @@ -73,7 +73,9 @@ |
166 | """The relative path for the data directory is correctly retrieved.""" |
167 | module = utils.os.path.dirname(utils.__file__) |
168 | rel_data = utils.os.path.join(module, utils.os.path.pardir, |
169 | - utils.os.path.pardir, utils.DATA_SUFFIX) |
170 | + utils.os.path.pardir, |
171 | + utils.os.path.pardir, |
172 | + utils.DATA_SUFFIX) |
173 | expected_dir = utils.os.path.abspath(rel_data) |
174 | |
175 | # ensure expected_path exists at os level |
176 | |
177 | === added file 'ubuntuone/controlpanel/utils/tests/test_windows.py' |
178 | --- ubuntuone/controlpanel/utils/tests/test_windows.py 1970-01-01 00:00:00 +0000 |
179 | +++ ubuntuone/controlpanel/utils/tests/test_windows.py 2011-11-15 13:13:25 +0000 |
180 | @@ -0,0 +1,179 @@ |
181 | +# -*- coding: utf-8 -*- |
182 | + |
183 | +# |
184 | +# Copyright 2011 Canonical Ltd. |
185 | +# |
186 | +# This program is free software: you can redistribute it and/or modify it |
187 | +# under the terms of the GNU General Public License version 3, as published |
188 | +# by the Free Software Foundation. |
189 | +# |
190 | +# This program is distributed in the hope that it will be useful, but |
191 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
192 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
193 | +# PURPOSE. See the GNU General Public License for more details. |
194 | +# |
195 | +# You should have received a copy of the GNU General Public License along |
196 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
197 | + |
198 | +"""Test the windows utils functions.""" |
199 | + |
200 | +import os |
201 | + |
202 | +from twisted.internet import defer |
203 | + |
204 | +from ubuntuone.controlpanel import utils |
205 | +from ubuntuone.controlpanel.tests import TestCase |
206 | + |
207 | +# let me use protected methods |
208 | +# pylint: disable=W0212 |
209 | + |
210 | + |
211 | +class AutoupdaterTestCase(TestCase): |
212 | + """Test the code that is used for the auto update process.""" |
213 | + |
214 | + @defer.inlineCallbacks |
215 | + def setUp(self): |
216 | + """Prepare for the diff tests.""" |
217 | + yield super(AutoupdaterTestCase, self).setUp() |
218 | + self.auto_update_path = r'path\to\exe' |
219 | + self.return_from_call = 0 |
220 | + self.command = None |
221 | + self.args = [] |
222 | + |
223 | + def fake_execute_process(command, args=None, path=None): |
224 | + """Fake async process execution.""" |
225 | + self.command = command |
226 | + self.args = args |
227 | + return self.return_from_call |
228 | + |
229 | + self.patch(utils.windows, 'getProcessValue', fake_execute_process) |
230 | + self.patch(utils.windows, '_get_update_path', |
231 | + lambda: self.auto_update_path) |
232 | + |
233 | + @defer.inlineCallbacks |
234 | + def test_are_updates_present_true(self): |
235 | + """Test when updates are present.""" |
236 | + # the idea is simple, set the value to be returned from |
237 | + # the fake call, assert that we get true and also that |
238 | + # we did use the correct parameters. |
239 | + self.return_from_call = 0 |
240 | + are_present = yield utils.are_updates_present() |
241 | + self.assertTrue(are_present, 'Updates should be present.') |
242 | + # lets assert that we did use the correct args |
243 | + expected_args = ('--mode', 'unattended') |
244 | + self.assertEqual(expected_args, self.args) |
245 | + self.assertEqual(self.command, self.auto_update_path) |
246 | + |
247 | + @defer.inlineCallbacks |
248 | + def test_are_updates_present_false(self): |
249 | + """Test when updates are not present.""" |
250 | + # similar to test_are_updates_present_true but with diff retcode |
251 | + self.return_from_call = 40 |
252 | + are_present = yield utils.are_updates_present() |
253 | + self.assertFalse(are_present, 'Updates should NOT be present.') |
254 | + # lets assert that we did use the correct args |
255 | + expected_args = ('--mode', 'unattended') |
256 | + self.assertEqual(expected_args, self.args) |
257 | + self.assertEqual(self.command, self.auto_update_path) |
258 | + |
259 | + def test_perform_update(self): |
260 | + """Test the method that performs the update.""" |
261 | + self.patch(utils.windows.win32api, 'ShellExecute', self._set_called) |
262 | + utils.perform_update() |
263 | + self.assertIn(self.auto_update_path, self._called[0][2]) |
264 | + self.assertEqual('runas', self._called[0][1]) |
265 | + self.assertEqual('--unattendedmodeui none', self._called[0][3]) |
266 | + self.assertEqual('', self._called[0][4]) |
267 | + self.assertEqual(0, self._called[0][5]) |
268 | + |
269 | + |
270 | +class GetPathTestCase(TestCase): |
271 | + """Test the code that is used for the auto update process.""" |
272 | + |
273 | + @defer.inlineCallbacks |
274 | + def setUp(self): |
275 | + """Set the different tests.""" |
276 | + yield super(GetPathTestCase, self).setUp() |
277 | + self.called = [] |
278 | + self.exec_path = 'path/to/current/exe' |
279 | + self.exists = True |
280 | + |
281 | + def fake_abspath(path): |
282 | + """Fake os.path.abspath.""" |
283 | + self.called.append('os.path.abspath') |
284 | + return path |
285 | + |
286 | + def fake_dirname(path): |
287 | + """Fake os.path.dirname.""" |
288 | + self.called.append('os.path.dirname') |
289 | + return path |
290 | + |
291 | + def fake_exists(path): |
292 | + """Fake os.path.exists.""" |
293 | + self.called.append('os.path.exists') |
294 | + return self.exists |
295 | + |
296 | + # patch the os.path functions used |
297 | + self.patch(utils.windows.os.path, 'abspath', fake_abspath) |
298 | + self.patch(utils.windows.os.path, 'dirname', fake_dirname) |
299 | + self.patch(utils.windows.os.path, 'exists', fake_exists) |
300 | + |
301 | + def _delete_frozen_state(self): |
302 | + """Delete the frozen state.""" |
303 | + del utils.windows.sys.frozen |
304 | + del utils.windows.sys.executable |
305 | + |
306 | + def test_get_auto_update_path_frozen(self): |
307 | + """Test the method used to get the autoupdate.""" |
308 | + # patch the diff parts of sys so that we get fake paths |
309 | + is_frozen = hasattr(utils.windows.sys, 'frozen') |
310 | + if not is_frozen: |
311 | + utils.windows.sys.frozen = True |
312 | + utils.windows.sys.executable = self.exec_path |
313 | + self.addCleanup(self._delete_frozen_state) |
314 | + |
315 | + # called method and assert that we have the correct result |
316 | + path = utils.windows._get_update_path() |
317 | + self.assertEqual(os.path.join(self.exec_path, |
318 | + utils.windows.AUTOUPDATE_EXE_NAME), path) |
319 | + self.assertTrue('os.path.abspath' in self.called) |
320 | + self.assertTrue('os.path.dirname' in self.called) |
321 | + self.assertTrue('os.path.exists' in self.called) |
322 | + |
323 | + def _reset_frozen_state(self, old_frozen, old_exec_path): |
324 | + """Reset the frozen state.""" |
325 | + utils.windows.sys.frozen = old_frozen |
326 | + utils.windows.sys.executable = old_exec_path |
327 | + |
328 | + def _reset__file__(self, path): |
329 | + """Reset the value of __file__.""" |
330 | + utils.windows.__file__ = path |
331 | + |
332 | + def test_get_auto_update_path_not_frozen(self): |
333 | + """Test the method used to get the autoupdate.""" |
334 | + is_frozen = hasattr(utils.windows.sys, 'frozen') |
335 | + if is_frozen: |
336 | + old_frozen = utils.windows.sys.frozen |
337 | + old_exec_path = utils.windows.sys.executable |
338 | + del utils.windows.sys.frozen |
339 | + del utils.windows.sys.executable |
340 | + self.addCleanup(self._reset_frozen_state, old_frozen, |
341 | + old_exec_path) |
342 | + # set a fake __file__ for the module |
343 | + old_file = utils.windows.__file__ |
344 | + utils.windows.__file__ = self.exec_path |
345 | + self.addCleanup(self._reset__file__, old_file) |
346 | + |
347 | + path = utils.windows._get_update_path() |
348 | + self.assertEqual(os.path.join(self.exec_path, |
349 | + utils.windows.AUTOUPDATE_EXE_NAME), path) |
350 | + self.assertEqual(2, self.called.count('os.path.dirname')) |
351 | + self.assertTrue('os.path.exists' in self.called) |
352 | + |
353 | + def test_get_auto_update_path_not_present(self): |
354 | + """Test the method used to get the autoupdate.""" |
355 | + self.exists = False |
356 | + |
357 | + # called method and assert that we have the correct result |
358 | + path = utils.windows._get_update_path() |
359 | + self.assertEqual(None, path) |
360 | |
361 | === added file 'ubuntuone/controlpanel/utils/windows.py' |
362 | --- ubuntuone/controlpanel/utils/windows.py 1970-01-01 00:00:00 +0000 |
363 | +++ ubuntuone/controlpanel/utils/windows.py 2011-11-15 13:13:25 +0000 |
364 | @@ -0,0 +1,73 @@ |
365 | +# -*- coding: utf-8 -*- |
366 | + |
367 | +# |
368 | +# Copyright 2011 Canonical Ltd. |
369 | +# |
370 | +# This program is free software: you can redistribute it and/or modify it |
371 | +# under the terms of the GNU General Public License version 3, as published |
372 | +# by the Free Software Foundation. |
373 | +# |
374 | +# This program is distributed in the hope that it will be useful, but |
375 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
376 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
377 | +# PURPOSE. See the GNU General Public License for more details. |
378 | +# |
379 | +# You should have received a copy of the GNU General Public License along |
380 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
381 | + |
382 | +"""Autoupdate functions for windows.""" |
383 | + |
384 | +import os |
385 | +import sys |
386 | + |
387 | +# Avoid pylint error on Linux |
388 | +# pylint: disable=F0401 |
389 | +import win32api |
390 | +# pylint: enable=F0401 |
391 | + |
392 | +from twisted.internet import defer |
393 | +from twisted.internet.utils import getProcessValue |
394 | + |
395 | +from ubuntuone.controlpanel.logger import setup_logging |
396 | + |
397 | +logger = setup_logging('utils') |
398 | +AUTOUPDATE_EXE_NAME = 'autoupdate-windows.exe' |
399 | + |
400 | + |
401 | +def _get_update_path(): |
402 | + """Return the path in which the autoupdate command is found.""" |
403 | + if hasattr(sys, 'frozen'): |
404 | + exec_path = os.path.abspath(sys.executable) |
405 | + else: |
406 | + exec_path = os.path.dirname(__file__) |
407 | + folder = os.path.dirname(exec_path) |
408 | + update_path = os.path.join(folder, AUTOUPDATE_EXE_NAME) |
409 | + if os.path.exists(update_path): |
410 | + return update_path |
411 | + return None |
412 | + |
413 | + |
414 | +@defer.inlineCallbacks |
415 | +def are_updates_present(): |
416 | + """Return if there are updates for Ubuntu One.""" |
417 | + result = False |
418 | + retcode = None |
419 | + update_path = _get_update_path() |
420 | + if update_path is not None: |
421 | + # If there is an update present we will get 0, non-zero otherwise |
422 | + retcode = yield getProcessValue(update_path, args=('--mode', |
423 | + 'unattended'), path=os.path.dirname(update_path)) |
424 | + result = retcode == 0 |
425 | + logger.debug('are_updates_present: update path: %r, return code: %r,' |
426 | + ' result: %r', update_path, retcode, result) |
427 | + defer.returnValue(result) |
428 | + |
429 | + |
430 | +def perform_update(): |
431 | + """Spawn the autoupdate process and call the stop function.""" |
432 | + update_path = _get_update_path() |
433 | + if update_path is not None: |
434 | + # lets call the updater with the commands that are required, |
435 | + win32api.ShellExecute(None, 'runas', |
436 | + update_path, |
437 | + '--unattendedmodeui none', '', 0) |
utils.os. path.pardir, esta repetido:
158 + utils.os. path.pardir, path.pardir,
159 + utils.os.