Merge lp:~dobey/ubuntu-sso-client/use-dirspec into lp:ubuntu-sso-client

Proposed by dobey on 2012-06-21
Status: Merged
Approved by: dobey on 2012-06-22
Approved revision: 974
Merged at revision: 973
Proposed branch: lp:~dobey/ubuntu-sso-client/use-dirspec
Merge into: lp:ubuntu-sso-client
Diff against target: 723 lines (+19/-515)
17 files modified
setup.py (+2/-4)
ubuntu_sso/account.py (+2/-2)
ubuntu_sso/gtk/gui.py (+3/-3)
ubuntu_sso/keyring/tests/test_linux.py (+1/-1)
ubuntu_sso/logger.py (+2/-2)
ubuntu_sso/main/tests/test_linux.py (+1/-1)
ubuntu_sso/networkstate/darwin.py (+1/-1)
ubuntu_sso/networkstate/linux.py (+1/-1)
ubuntu_sso/qt/setup_account_page.py (+2/-2)
ubuntu_sso/qt/sso_wizard_page.py (+1/-1)
ubuntu_sso/qt/tests/test_common.py (+2/-2)
ubuntu_sso/tests/test_account.py (+1/-1)
ubuntu_sso/xdg_base_directory/__init__.py (+0/-104)
ubuntu_sso/xdg_base_directory/tests/__init__.py (+0/-29)
ubuntu_sso/xdg_base_directory/tests/test_common.py (+0/-91)
ubuntu_sso/xdg_base_directory/tests/test_windows.py (+0/-157)
ubuntu_sso/xdg_base_directory/windows.py (+0/-113)
To merge this branch: bzr merge lp:~dobey/ubuntu-sso-client/use-dirspec
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve on 2012-06-22
Natalia Bidart 2012-06-21 Approve on 2012-06-22
Review via email: mp+111484@code.launchpad.net

Commit Message

Remove the xdg_base_directory module as it duplicates dirspec now

Description of the Change

To post a comment you must log in.
Natalia Bidart (nataliabidart) wrote :

Looks good!

review: Approve
review: Approve
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (171.6 KiB)

The attempt to merge lp:~dobey/ubuntu-sso-client/use-dirspec into lp:ubuntu-sso-client failed. Below is the output from the failed tests.

*** Running GTK test suite for ubuntu_sso ***
Starting squid version...
Waiting for squid to start....
ubuntu_sso.main.tests.test_common
  BaseTestCase
    runTest ... [OK]
  CredentialsManagementClearTestCase
    test_backend_called ... [OK]
    test_does_not_block ... [OK]
    test_handles_error ... [OK]
  CredentialsManagementFindTestCase
    test_backend_called ... [OK]
    test_does_not_block ... [OK]
    test_find_credentials_with_error_cb ... [OK]
    test_find_credentials_with_success_cb ... [OK]
    test_handles_error ... [OK]
  CredentialsManagementNotFindTestCase
    test_backend_called ... [OK]
    test_does_not_block ... [OK]
    test_find_credentials_with_error_cb ... [OK]
    test_find_credentials_with_success_cb ... [OK]
    test_handles_error ... [OK]
  CredentialsManagementOpsTestCase
    test_login ... [OK]
    test_login_email_password ... [OK]
    test_register ... [OK]
  CredentialsManagementParamsTestCase
    test_login ... [OK]
    test_login_email_password ... [OK]
    test_register ... [OK]
  CredentialsManagementRefCountingTestCase
    test_authorization_denied ... [OK]
    test_autorization_denied_when_ref_count_is_not_positive ... [OK]
    test_clear_credentials ... [OK]
    test_credentials_cleared ... [OK]
    test_credentials_cleared_when_ref_count_is_not_positive ... [OK]
    test_credentials_error ... [OK]
    test_credentials_error_when_ref_count_is_not_positive ... [OK]
    test_credentials_found ... [OK]
    test_credentials_found_when_ref_count_is_not_positive ... [OK]
    test_credentials_not_found ... [OK]
    test_credentials_not_found_when_ref_count_is_not_positive ... [OK]
    test_credentials_stored ... [OK]
    test_credentials_stored_when_ref_count_is_not_positive ... [OK]
    test_find_credentials ... ...

974. By dobey on 2012-06-22

Fix pep8 warnings

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'setup.py'
2--- setup.py 2012-05-29 17:27:26 +0000
3+++ setup.py 2012-06-22 17:06:18 +0000
4@@ -301,8 +301,8 @@
5 author='Natalia Bidart',
6 author_email='natalia.bidart@canonical.com',
7 description='Ubuntu Single Sign-On client',
8- long_description='Desktop service to allow applications to sign in' \
9- 'to Ubuntu services via SSO',
10+ long_description=('Desktop service to allow applications to sign in'
11+ 'to Ubuntu services via SSO'),
12 url='https://launchpad.net/ubuntu-sso-client',
13 extra_path='ubuntu-sso-client',
14 data_files=data_files,
15@@ -325,8 +325,6 @@
16 'ubuntu_sso.utils.runner.tests',
17 'ubuntu_sso.utils.webclient',
18 'ubuntu_sso.utils.webclient.tests',
19- 'ubuntu_sso.xdg_base_directory',
20- 'ubuntu_sso.xdg_base_directory.tests',
21 ],
22 cmdclass=cmdclass,
23 **extra)
24
25=== modified file 'ubuntu_sso/account.py'
26--- ubuntu_sso/account.py 2012-05-29 16:56:45 +0000
27+++ ubuntu_sso/account.py 2012-06-22 17:06:18 +0000
28@@ -197,7 +197,7 @@
29 finally:
30 restful_client.shutdown()
31
32- logger.debug('login: authentication successful! consumer_key: %r, ' \
33+ logger.debug('login: authentication successful! consumer_key: %r, '
34 'token_name: %r', credentials['consumer_key'], token_name)
35 defer.returnValue(credentials)
36
37@@ -212,7 +212,7 @@
38 finally:
39 restful_client.shutdown()
40 key = 'preferred_email'
41- result = key in me_info and me_info[key] != None
42+ result = key in me_info and me_info[key] is not None
43
44 logger.info('is_validated: consumer_key: %r, result: %r.',
45 token['consumer_key'], result)
46
47=== modified file 'ubuntu_sso/gtk/gui.py'
48--- ubuntu_sso/gtk/gui.py 2012-06-13 20:15:33 +0000
49+++ ubuntu_sso/gtk/gui.py 2012-06-22 17:06:18 +0000
50@@ -362,7 +362,7 @@
51 if app_name == self.app_name:
52 result = f(app_name, *args, **kwargs)
53 else:
54- logger.info('%s: ignoring call since received app_name '\
55+ logger.info('%s: ignoring call since received app_name '
56 '%r (expected %r)',
57 f.__name__, app_name, self.app_name)
58 return result
59@@ -796,7 +796,7 @@
60 self.user_email = email1
61 self.user_password = password1
62
63- logger.info('Calling register_user with email %r, password <hidden>,' \
64+ logger.info('Calling register_user with email %r, password <hidden>,'
65 ' name %r, captcha_id %r and captcha_solution %r.', email1,
66 name, self._captcha_id, captcha_solution)
67
68@@ -949,7 +949,7 @@
69 return
70
71 email = self.reset_email_entry.get_text()
72- logger.info('Calling set_new_password with email %r, token %r and ' \
73+ logger.info('Calling set_new_password with email %r, token %r and '
74 'new password: <hidden>.', email, token)
75 f = self.backend.set_new_password
76 error_handler = partial(self._handle_error, f,
77
78=== modified file 'ubuntu_sso/keyring/tests/test_linux.py'
79--- ubuntu_sso/keyring/tests/test_linux.py 2012-04-09 17:38:24 +0000
80+++ ubuntu_sso/keyring/tests/test_linux.py 2012-06-22 17:06:18 +0000
81@@ -137,7 +137,7 @@
82
83 def get_mock_service(self):
84 """Create only one instance of the mock service per test."""
85- if self.mock_service == None:
86+ if self.mock_service is None:
87 self.mock_service = MockSecretService()
88 return self.mock_service
89
90
91=== modified file 'ubuntu_sso/logger.py'
92--- ubuntu_sso/logger.py 2012-04-09 17:38:24 +0000
93+++ ubuntu_sso/logger.py 2012-06-22 17:06:18 +0000
94@@ -37,11 +37,11 @@
95 import os
96 import sys
97
98+from dirspec.basedir import xdg_cache_home
99+from dirspec.utils import unicode_path
100 from functools import wraps
101 from logging.handlers import RotatingFileHandler
102
103-from ubuntu_sso.xdg_base_directory import unicode_path, xdg_cache_home
104-
105 LOGFOLDER = os.path.join(xdg_cache_home, 'sso')
106 # create log folder if it doesn't exists
107 if not os.path.exists(unicode_path(LOGFOLDER)):
108
109=== modified file 'ubuntu_sso/main/tests/test_linux.py'
110--- ubuntu_sso/main/tests/test_linux.py 2012-06-13 16:49:54 +0000
111+++ ubuntu_sso/main/tests/test_linux.py 2012-06-22 17:06:18 +0000
112@@ -42,7 +42,7 @@
113 from ubuntuone.devtools.testcases import BaseTestCase, skipIf
114
115
116-@skipIf(do_tests != True, 'Tests only work with DBus and linux imports.')
117+@skipIf(not do_tests, 'Tests only work with DBus and linux imports.')
118 class LinuxProxyTestCase(BaseTestCase):
119 """Test some Linux specific cases."""
120
121
122=== modified file 'ubuntu_sso/networkstate/darwin.py'
123--- ubuntu_sso/networkstate/darwin.py 2012-05-21 14:48:25 +0000
124+++ ubuntu_sso/networkstate/darwin.py 2012-06-22 17:06:18 +0000
125@@ -126,7 +126,7 @@
126 CFRelease(target)
127
128 if not ok:
129- logger.error("Error getting reachability status of '%s'" % \
130+ logger.error("Error getting reachability status of '%s'" %
131 HOSTNAME_TO_CHECK)
132 raise NetworkFailException()
133
134
135=== modified file 'ubuntu_sso/networkstate/linux.py'
136--- ubuntu_sso/networkstate/linux.py 2012-05-24 04:20:08 +0000
137+++ ubuntu_sso/networkstate/linux.py 2012-06-22 17:06:18 +0000
138@@ -79,7 +79,7 @@
139 # the user has connected in some other way
140 self.call_result_cb(ONLINE)
141 else:
142- logger.error("Error contacting NetworkManager: %s" % \
143+ logger.error("Error contacting NetworkManager: %s" %
144 str(error))
145 self.call_result_cb(UNKNOWN)
146
147
148=== modified file 'ubuntu_sso/qt/setup_account_page.py'
149--- ubuntu_sso/qt/setup_account_page.py 2012-06-08 13:33:39 +0000
150+++ ubuntu_sso/qt/setup_account_page.py 2012-06-22 17:06:18 +0000
151@@ -245,8 +245,8 @@
152 common.NORMAL))
153
154 self.ui.refresh_label.linkActivated.connect(self.hide_error)
155- self.ui.refresh_label.linkActivated.connect(lambda url: \
156- self._refresh_captcha())
157+ self.ui.refresh_label.linkActivated.connect(
158+ lambda url: self._refresh_captcha())
159 # We need to check if we enable the button on many signals
160 self.ui.name_edit.textEdited.connect(self._enable_setup_button)
161 self.ui.email_edit.textEdited.connect(self._enable_setup_button)
162
163=== modified file 'ubuntu_sso/qt/sso_wizard_page.py'
164--- ubuntu_sso/qt/sso_wizard_page.py 2012-04-09 17:38:24 +0000
165+++ ubuntu_sso/qt/sso_wizard_page.py 2012-06-22 17:06:18 +0000
166@@ -253,7 +253,7 @@
167 if app_name == self.app_name:
168 result = f(app_name, *args, **kwargs)
169 else:
170- logger.info('%s: ignoring call since received app_name '\
171+ logger.info('%s: ignoring call since received app_name '
172 '"%s" (expected "%s")',
173 f.__name__, app_name, self.app_name)
174 return result
175
176=== modified file 'ubuntu_sso/qt/tests/test_common.py'
177--- ubuntu_sso/qt/tests/test_common.py 2012-04-09 17:38:24 +0000
178+++ ubuntu_sso/qt/tests/test_common.py 2012-06-22 17:06:18 +0000
179@@ -362,8 +362,8 @@
180 result = build_general_error_message(err_dict)
181
182 expected = '\n'.join(
183- [('%s: %s' % (k, v)) \
184- for k, v in {'my_bad': error, 'odd_error': error2}.iteritems()])
185+ [('%s: %s' % (k, v))
186+ for k, v in {'my_bad': error, 'odd_error': error2}.iteritems()])
187 self.assertEqual(result, expected)
188
189 def test_with_not_dict(self):
190
191=== modified file 'ubuntu_sso/tests/test_account.py'
192--- ubuntu_sso/tests/test_account.py 2012-05-29 16:58:30 +0000
193+++ ubuntu_sso/tests/test_account.py 2012-06-22 17:06:18 +0000
194@@ -230,7 +230,7 @@
195
196 def verify_frc_shutdown(self):
197 """Verify that the FakeRestfulClient was stopped."""
198- assert self.frc.started == False, "Restfulclient must be shut down."
199+ assert self.frc.started is False, "Restfulclient must be shut down."
200
201 @defer.inlineCallbacks
202 def test_generate_captcha(self):
203
204=== removed directory 'ubuntu_sso/xdg_base_directory'
205=== removed file 'ubuntu_sso/xdg_base_directory/__init__.py'
206--- ubuntu_sso/xdg_base_directory/__init__.py 2012-04-09 17:38:24 +0000
207+++ ubuntu_sso/xdg_base_directory/__init__.py 1970-01-01 00:00:00 +0000
208@@ -1,104 +0,0 @@
209-# -*- coding: utf-8 -*-
210-#
211-# Copyright 2011-2012 Canonical Ltd.
212-#
213-# This program is free software: you can redistribute it and/or modify it
214-# under the terms of the GNU General Public License version 3, as published
215-# by the Free Software Foundation.
216-#
217-# This program is distributed in the hope that it will be useful, but
218-# WITHOUT ANY WARRANTY; without even the implied warranties of
219-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
220-# PURPOSE. See the GNU General Public License for more details.
221-#
222-# You should have received a copy of the GNU General Public License along
223-# with this program. If not, see <http://www.gnu.org/licenses/>.
224-#
225-# In addition, as a special exception, the copyright holders give
226-# permission to link the code of portions of this program with the
227-# OpenSSL library under certain conditions as described in each
228-# individual source file, and distribute linked combinations
229-# including the two.
230-# You must obey the GNU General Public License in all respects
231-# for all of the code used other than OpenSSL. If you modify
232-# file(s) with this exception, you may extend this exception to your
233-# version of the file(s), but you are not obligated to do so. If you
234-# do not wish to do so, delete this exception statement from your
235-# version. If you delete this exception statement from all source
236-# files in the program, then also delete it here.
237-"""XDG multiplatform."""
238-
239-import os
240-import sys
241-import warnings
242-
243-
244-def unicode_path(utf8path):
245- """Turn an utf8 path into a unicode path."""
246- return utf8path.decode("utf-8")
247-
248-
249-def native_path(utf8path):
250- """Turn an utf8 path into a path useable in the current encoding."""
251- warnings.warn('native_path will be removed soon', DeprecationWarning)
252- return unicode_path(utf8path)
253-
254-
255-def syncdaemon_path(mbcspath):
256- """Turn a mbcs path in a utf-8 path as CURRENTLY used inside syncdaemon."""
257- warnings.warn('syncdaemon_path will be removed soon', DeprecationWarning)
258- return mbcspath.decode(sys.getfilesystemencoding()).encode("utf-8")
259-
260-
261-# pylint: disable=C0103,F0401,E0611,E1101
262-if sys.platform == "win32":
263- from ubuntu_sso.xdg_base_directory import windows
264- source = windows
265- xdg_home = source.home_path
266-else:
267- import xdg.BaseDirectory
268- source = xdg.BaseDirectory
269- xdg_home = os.path.expanduser('~')
270-
271-xdg_cache_home = source.xdg_cache_home
272-
273-xdg_config_home = source.xdg_config_home
274-xdg_config_dirs = source.xdg_config_dirs
275-
276-xdg_data_home = source.xdg_data_home
277-xdg_data_dirs = source.xdg_data_dirs
278-
279-
280-def load_config_paths(*resource):
281- """Iterator of configuration paths.
282-
283- Return an iterator which gives each directory named 'resource' in
284- the configuration search path. Information provided by earlier
285- directories should take precedence over later ones (ie, the user's
286- config dir comes first).
287- """
288- resource = os.path.join(*resource)
289- for config_dir in xdg_config_dirs:
290- path = os.path.join(config_dir, resource)
291- # access the file system always with unicode
292- # to properly behave in some operating systems
293- if os.path.exists(unicode_path(path)):
294- yield path
295-
296-
297-def save_config_path(*resource):
298- """Path to save configuration.
299-
300- Ensure $XDG_CONFIG_HOME/<resource>/ exists, and return its path.
301- 'resource' should normally be the name of your application. Use this
302- when SAVING configuration settings. Use the xdg_config_dirs variable
303- for loading.
304- """
305- resource = os.path.join(*resource)
306- assert not resource.startswith('/')
307- path = os.path.join(xdg_config_home, resource)
308- # access the file system always with unicode
309- # to properly behave in some operating systems
310- if not os.path.isdir(unicode_path(path)):
311- os.makedirs(unicode_path(path), 0700)
312- return path
313
314=== removed directory 'ubuntu_sso/xdg_base_directory/tests'
315=== removed file 'ubuntu_sso/xdg_base_directory/tests/__init__.py'
316--- ubuntu_sso/xdg_base_directory/tests/__init__.py 2012-04-09 17:38:24 +0000
317+++ ubuntu_sso/xdg_base_directory/tests/__init__.py 1970-01-01 00:00:00 +0000
318@@ -1,29 +0,0 @@
319-# ubuntu_sso - Ubuntu Single Sign On client support for desktop apps
320-#
321-# Copyright 2009-2012 Canonical Ltd.
322-#
323-# This program is free software: you can redistribute it and/or modify it
324-# under the terms of the GNU General Public License version 3, as published
325-# by the Free Software Foundation.
326-#
327-# This program is distributed in the hope that it will be useful, but
328-# WITHOUT ANY WARRANTY; without even the implied warranties of
329-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
330-# PURPOSE. See the GNU General Public License for more details.
331-#
332-# You should have received a copy of the GNU General Public License along
333-# with this program. If not, see <http://www.gnu.org/licenses/>.
334-#
335-# In addition, as a special exception, the copyright holders give
336-# permission to link the code of portions of this program with the
337-# OpenSSL library under certain conditions as described in each
338-# individual source file, and distribute linked combinations
339-# including the two.
340-# You must obey the GNU General Public License in all respects
341-# for all of the code used other than OpenSSL. If you modify
342-# file(s) with this exception, you may extend this exception to your
343-# version of the file(s), but you are not obligated to do so. If you
344-# do not wish to do so, delete this exception statement from your
345-# version. If you delete this exception statement from all source
346-# files in the program, then also delete it here.
347-"""XDG tests."""
348
349=== removed file 'ubuntu_sso/xdg_base_directory/tests/test_common.py'
350--- ubuntu_sso/xdg_base_directory/tests/test_common.py 2012-04-09 17:38:24 +0000
351+++ ubuntu_sso/xdg_base_directory/tests/test_common.py 1970-01-01 00:00:00 +0000
352@@ -1,91 +0,0 @@
353-# -*- coding: utf-8 -*-
354-#
355-# Authors: Natalia B. Bidart <natalia.bidart@canonical.com>
356-#
357-# Copyright 2011-2012 Canonical Ltd.
358-#
359-# This program is free software: you can redistribute it and/or modify it
360-# under the terms of the GNU General Public License version 3, as published
361-# by the Free Software Foundation.
362-#
363-# This program is distributed in the hope that it will be useful, but
364-# WITHOUT ANY WARRANTY; without even the implied warranties of
365-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
366-# PURPOSE. See the GNU General Public License for more details.
367-#
368-# You should have received a copy of the GNU General Public License along
369-# with this program. If not, see <http://www.gnu.org/licenses/>.
370-#
371-# In addition, as a special exception, the copyright holders give
372-# permission to link the code of portions of this program with the
373-# OpenSSL library under certain conditions as described in each
374-# individual source file, and distribute linked combinations
375-# including the two.
376-# You must obey the GNU General Public License in all respects
377-# for all of the code used other than OpenSSL. If you modify
378-# file(s) with this exception, you may extend this exception to your
379-# version of the file(s), but you are not obligated to do so. If you
380-# do not wish to do so, delete this exception statement from your
381-# version. If you delete this exception statement from all source
382-# files in the program, then also delete it here.
383-"""Platform independent tests for the XDG constants."""
384-
385-import os
386-
387-from twisted.trial.unittest import TestCase
388-
389-from ubuntu_sso import xdg_base_directory
390-
391-
392-class TestBaseDirectory(TestCase):
393- """Tests for the BaseDirectory module."""
394-
395- def assert_utf8_bytes(self, value):
396- """Check that 'value' is a bytes sequence encoded with utf-8."""
397- self.assertIsInstance(value, str)
398- try:
399- value.decode('utf-8')
400- except UnicodeDecodeError:
401- self.fail('%r should be a utf8 encoded string.' % value)
402-
403- def test_xdg_home_is_utf8_bytes(self):
404- """The returned path is bytes."""
405- actual = xdg_base_directory.xdg_home
406- self.assert_utf8_bytes(actual)
407-
408- def test_xdg_cache_home_is_utf8_bytes(self):
409- """The returned path is bytes."""
410- actual = xdg_base_directory.xdg_cache_home
411- self.assert_utf8_bytes(actual)
412-
413- def test_xdg_config_home_is_utf8_bytes(self):
414- """The returned path is bytes."""
415- actual = xdg_base_directory.xdg_config_home
416- self.assert_utf8_bytes(actual)
417-
418- def test_xdg_config_dirs_are_bytes(self):
419- """The returned path is bytes."""
420- result = xdg_base_directory.xdg_config_dirs
421- for actual in result:
422- self.assert_utf8_bytes(actual)
423-
424- def test_xdg_data_home_is_utf8_bytes(self):
425- """The returned path is bytes."""
426- actual = xdg_base_directory.xdg_data_home
427- self.assert_utf8_bytes(actual)
428-
429- def test_xdg_data_dirs_are_bytes(self):
430- """The returned path is bytes."""
431- result = xdg_base_directory.xdg_data_dirs
432- for actual in result:
433- self.assert_utf8_bytes(actual)
434-
435- def test_load_config_paths_filter(self):
436- """Since those folders don't exist, this should be empty."""
437- self.assertEqual(list(xdg_base_directory.load_config_paths("x")), [])
438-
439- def test_save_config_path(self):
440- """The path should end with xdg_config/x (respecting the separator)."""
441- self.patch(os, "makedirs", lambda *args: None)
442- result = xdg_base_directory.save_config_path("x")
443- self.assertEqual(result.split(os.sep)[-2:], ['xdg_config', 'x'])
444
445=== removed file 'ubuntu_sso/xdg_base_directory/tests/test_windows.py'
446--- ubuntu_sso/xdg_base_directory/tests/test_windows.py 2012-04-09 17:38:24 +0000
447+++ ubuntu_sso/xdg_base_directory/tests/test_windows.py 1970-01-01 00:00:00 +0000
448@@ -1,157 +0,0 @@
449-# -*- coding: utf-8 -*-
450-#
451-# Copyright 2011-2012 Canonical Ltd.
452-#
453-# This program is free software: you can redistribute it and/or modify it
454-# under the terms of the GNU General Public License version 3, as published
455-# by the Free Software Foundation.
456-#
457-# This program is distributed in the hope that it will be useful, but
458-# WITHOUT ANY WARRANTY; without even the implied warranties of
459-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
460-# PURPOSE. See the GNU General Public License for more details.
461-#
462-# You should have received a copy of the GNU General Public License along
463-# with this program. If not, see <http://www.gnu.org/licenses/>.
464-#
465-# In addition, as a special exception, the copyright holders give
466-# permission to link the code of portions of this program with the
467-# OpenSSL library under certain conditions as described in each
468-# individual source file, and distribute linked combinations
469-# including the two.
470-# You must obey the GNU General Public License in all respects
471-# for all of the code used other than OpenSSL. If you modify
472-# file(s) with this exception, you may extend this exception to your
473-# version of the file(s), but you are not obligated to do so. If you
474-# do not wish to do so, delete this exception statement from your
475-# version. If you delete this exception statement from all source
476-# files in the program, then also delete it here.
477-"""Windows-specific tests for the XDG constants."""
478-
479-import os
480-import sys
481-
482-from twisted.trial.unittest import TestCase
483-
484-
485-# pylint: disable=E1101, E0611, F0401
486-import win32com.shell
487-from ubuntu_sso.xdg_base_directory.windows import (
488- get_config_dirs,
489- get_data_dirs,
490- get_env_path,
491- get_special_folders,
492-)
493-
494-
495-class FakeShellConModule(object):
496- """Override CSIDL_ constants."""
497-
498- CSIDL_PROFILE = 0
499- CSIDL_LOCAL_APPDATA = 1
500- CSIDL_COMMON_APPDATA = 2
501-
502-
503-class FakeShellModule(object):
504-
505- """Fake Shell Module."""
506-
507- def __init__(self):
508- """Set the proper mapping between CSIDL_ consts."""
509- self.values = {
510- 0: u'c:\\path\\to\\users\\home',
511- 1: u'c:\\path\\to\\users\\home\\appData\\local',
512- 2: u'c:\\programData',
513- }
514-
515- # pylint: disable=C0103
516- def SHGetFolderPath(self, dummy0, shellconValue, dummy2, dummy3):
517- """Override SHGetFolderPath functionality."""
518- return self.values[shellconValue]
519- # pylint: enable=C0103
520-
521-
522-class TestBaseDirectoryWindows(TestCase):
523- """Tests for the BaseDirectory module."""
524-
525- def test_get_special_folders(self):
526- """Make sure we can import the platform module."""
527-
528- shell_module = FakeShellModule()
529- self.patch(win32com.shell, "shell", shell_module)
530- self.patch(win32com.shell, "shellcon", FakeShellConModule())
531- special_folders = get_special_folders()
532- self.assertTrue('Personal' in special_folders)
533- self.assertTrue('Local AppData' in special_folders)
534- self.assertTrue('AppData' in special_folders)
535- self.assertTrue('Common AppData' in special_folders)
536-
537- self.assertTrue(special_folders['Personal'] == \
538- shell_module.values[FakeShellConModule.CSIDL_PROFILE])
539- self.assertTrue(special_folders['Local AppData'] == \
540- shell_module.values[FakeShellConModule.CSIDL_LOCAL_APPDATA])
541- self.assertTrue(special_folders['Local AppData'].startswith(
542- special_folders['AppData']))
543- self.assertTrue(special_folders['Common AppData'] == \
544- shell_module.values[FakeShellConModule.CSIDL_COMMON_APPDATA])
545-
546- for val in special_folders.itervalues():
547- self.assertIsInstance(val, str)
548- val.decode('utf8')
549- # Should not raise exceptions
550-
551- def test_get_data_dirs(self):
552- """Check thet get_data_dirs uses pathsep correctly."""
553- bad_sep = filter(lambda x: x not in os.pathsep, ":;")
554- dir_list = ["A", "B", bad_sep, "C"]
555- self.patch(os, "environ",
556- dict(XDG_DATA_DIRS=os.pathsep.join(
557- dir_list)))
558- dirs = get_data_dirs()
559- self.assertEqual(dirs, dir_list)
560-
561- def test_get_config_dirs(self):
562- """Check thet get_data_dirs uses pathsep correctly."""
563- bad_sep = filter(lambda x: x not in os.pathsep, ":;")
564- dir_list = ["A", "B", bad_sep, "C"]
565- self.patch(os, "environ",
566- dict(XDG_CONFIG_DIRS=os.pathsep.join(
567- dir_list)))
568- dirs = get_config_dirs()[1:]
569- self.assertEqual(dirs, dir_list)
570-
571- def set_fake_environ(self, key, value):
572- """Set (and restore) a fake environ variable."""
573- if key in os.environ:
574- prev = os.environ[key]
575- self.addCleanup(os.environ.__setitem__, key, prev)
576- else:
577- self.addCleanup(os.environ.__delitem__, key)
578- os.environ[key] = value
579-
580- def unset_fake_environ(self, key):
581- """Unset (and restore) a fake environ variable."""
582- if key in os.environ:
583- current_value = os.environ[key]
584- self.addCleanup(os.environ.__setitem__, key, current_value)
585- del(os.environ[key])
586-
587- def test_get_env_path_var(self):
588- """Test that get_env_path transforms an env var."""
589- fake_path = u"C:\\Users\\Ñandú"
590- fake_env_var = "FAKE_ENV_VAR"
591-
592- mbcs_path = fake_path.encode(sys.getfilesystemencoding())
593- utf8_path = fake_path.encode("utf-8")
594-
595- self.set_fake_environ(fake_env_var, mbcs_path)
596- self.assertEqual(get_env_path(fake_env_var, "unexpected"), utf8_path)
597-
598- def test_get_env_path_no_var(self):
599- """Test that get_env_path returns the default when env var not set."""
600- fake_path = u"C:\\Users\\Ñandú"
601- fake_env_var = "fake_env_var"
602- default = fake_path.encode(sys.getfilesystemencoding())
603-
604- self.unset_fake_environ(fake_env_var)
605- self.assertEqual(get_env_path(fake_env_var, default), default)
606
607=== removed file 'ubuntu_sso/xdg_base_directory/windows.py'
608--- ubuntu_sso/xdg_base_directory/windows.py 2012-04-09 17:38:24 +0000
609+++ ubuntu_sso/xdg_base_directory/windows.py 1970-01-01 00:00:00 +0000
610@@ -1,113 +0,0 @@
611-# -*- coding: utf-8 -*-
612-#
613-# Copyright 2011-2012 Canonical Ltd.
614-#
615-# This program is free software: you can redistribute it and/or modify it
616-# under the terms of the GNU General Public License version 3, as published
617-# by the Free Software Foundation.
618-#
619-# This program is distributed in the hope that it will be useful, but
620-# WITHOUT ANY WARRANTY; without even the implied warranties of
621-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
622-# PURPOSE. See the GNU General Public License for more details.
623-#
624-# You should have received a copy of the GNU General Public License along
625-# with this program. If not, see <http://www.gnu.org/licenses/>.
626-#
627-# In addition, as a special exception, the copyright holders give
628-# permission to link the code of portions of this program with the
629-# OpenSSL library under certain conditions as described in each
630-# individual source file, and distribute linked combinations
631-# including the two.
632-# You must obey the GNU General Public License in all respects
633-# for all of the code used other than OpenSSL. If you modify
634-# file(s) with this exception, you may extend this exception to your
635-# version of the file(s), but you are not obligated to do so. If you
636-# do not wish to do so, delete this exception statement from your
637-# version. If you delete this exception statement from all source
638-# files in the program, then also delete it here.
639-"""XDG helpers for windows."""
640-
641-import os
642-import sys
643-
644-
645-# pylint: disable=C0103
646-def get_special_folders():
647- """ Routine to grab all the Windows Special Folders locations.
648-
649- If successful, returns dictionary
650- of shell folder locations indexed on Windows keyword for each;
651- otherwise, returns an empty dictionary.
652- """
653- # pylint: disable=W0621, F0401, E0611
654- special_folders = {}
655-
656- from win32com.shell import shell, shellcon
657- # CSIDL_LOCAL_APPDATA = C:\Users\<username>\AppData\Local
658- # CSIDL_PROFILE = C:\Users\<username>
659- # CSIDL_COMMON_APPDATA = C:\ProgramData
660- # More information on these constants at
661- # http://msdn.microsoft.com/en-us/library/bb762494
662-
663- # as per http://msdn.microsoft.com/en-us/library/windows/desktop/bb762181,
664- # SHGetFolderPath is deprecated, we should migrate to SHGetKnownFolderPath
665- # (http://msdn.microsoft.com/en-us/library/windows/desktop/bb762188)
666- get_path = lambda name: shell.SHGetFolderPath(
667- 0, getattr(shellcon, name), None, 0).encode('utf8')
668- special_folders['Personal'] = get_path("CSIDL_PROFILE")
669- special_folders['Local AppData'] = get_path("CSIDL_LOCAL_APPDATA")
670- special_folders['AppData'] = os.path.dirname(
671- special_folders['Local AppData'])
672- special_folders['Common AppData'] = get_path("CSIDL_COMMON_APPDATA")
673- return special_folders
674-
675-
676-def get_env_path(key, default):
677- """Get a utf8 path from an environment variable."""
678- if key in os.environ:
679- # on windows, environment variables are mbcs bytes
680- # so we must turn them into utf-8 Syncdaemon paths
681- path = os.environ.get(key)
682- return path.decode(sys.getfilesystemencoding()).encode("utf-8")
683- else:
684- return default
685-
686-
687-special_folders = get_special_folders()
688-
689-home_path = special_folders['Personal']
690-app_local_data_path = special_folders['Local AppData']
691-app_global_data_path = special_folders['Common AppData']
692-
693-xdg_data_home = get_env_path('XDG_DATA_HOME',
694- os.path.join(app_local_data_path, 'xdg'))
695-
696-xdg_cache_home = get_env_path('XDG_CACHE_HOME',
697- os.path.join(xdg_data_home, 'cache'))
698-
699-xdg_config_home = get_env_path('XDG_CONFIG_HOME',
700- app_local_data_path)
701-
702-
703-def get_data_dirs():
704- """Returns XDG data directories."""
705- return get_env_path('XDG_DATA_DIRS',
706- '{0}{1}{2}'.format(app_local_data_path, os.pathsep,
707- app_global_data_path)).split(os.pathsep)
708-
709-
710-xdg_data_dirs = get_data_dirs()
711-
712-
713-def get_config_dirs():
714- """Return XDG config directories."""
715- return [xdg_config_home] + \
716- get_env_path('XDG_CONFIG_DIRS',
717- app_global_data_path,
718- ).split(os.pathsep)
719-
720-xdg_config_dirs = get_config_dirs()
721-
722-xdg_data_dirs = filter(lambda x: x, xdg_data_dirs)
723-xdg_config_dirs = filter(lambda x: x, xdg_config_dirs)

Subscribers

People subscribed via source and target branches