Merge lp:~nataliabidart/ubuntuone-client/xdg-return-bytes into lp:ubuntuone-client
- xdg-return-bytes
- Merge into trunk
Proposed by
Natalia Bidart
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Natalia Bidart | ||||
Approved revision: | 1082 | ||||
Merged at revision: | 1080 | ||||
Proposed branch: | lp:~nataliabidart/ubuntuone-client/xdg-return-bytes | ||||
Merge into: | lp:ubuntuone-client | ||||
Diff against target: |
446 lines (+127/-88) 11 files modified
bin/ubuntuone-syncdaemon (+26/-13) tests/platform/test_xdg_base_directory.py (+10/-0) tests/platform/windows/test_xdg_base_directory.py (+5/-6) tests/syncdaemon/test_config.py (+49/-33) ubuntuone/platform/linux/__init__.py (+1/-1) ubuntuone/platform/linux/os_helper.py (+1/-6) ubuntuone/platform/windows/__init__.py (+0/-1) ubuntuone/platform/windows/os_helper.py (+0/-6) ubuntuone/platform/xdg_base_directory/windows.py (+4/-3) ubuntuone/syncdaemon/config.py (+28/-16) ubuntuone/syncdaemon/main.py (+3/-3) |
||||
To merge this branch: | bzr merge lp:~nataliabidart/ubuntuone-client/xdg-return-bytes | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alejandro J. Cura (community) | Approve | ||
Guillermo Gonzalez | Approve | ||
Review via email: mp+69808@code.launchpad.net |
Commit message
- XDG data dirs must return bytes (LP: #818030).
Description of the change
To post a comment you must log in.
- 1080. By Natalia Bidart
-
Typo!
Revision history for this message
Alejandro J. Cura (alecu) wrote : | # |
Waiting for a few style changes, but basically "Approved!!!!!"
review:
Approve
- 1081. By Natalia Bidart
-
Merged trunk in.
- 1082. By Natalia Bidart
-
Style fixes.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bin/ubuntuone-syncdaemon' | |||
2 | --- bin/ubuntuone-syncdaemon 2011-07-28 14:36:35 +0000 | |||
3 | +++ bin/ubuntuone-syncdaemon 2011-07-29 19:11:49 +0000 | |||
4 | @@ -37,7 +37,15 @@ | |||
5 | 37 | import sys | 37 | import sys |
6 | 38 | import shutil | 38 | import shutil |
7 | 39 | 39 | ||
9 | 40 | from ubuntuone.platform import is_already_running, set_application_name, is_root | 40 | from ubuntuone.platform import ( |
10 | 41 | can_write, | ||
11 | 42 | set_dir_readwrite, | ||
12 | 43 | is_already_running, | ||
13 | 44 | is_root, | ||
14 | 45 | make_dir, | ||
15 | 46 | path_exists, | ||
16 | 47 | set_application_name, | ||
17 | 48 | ) | ||
18 | 41 | from ubuntuone.syncdaemon import logger, config | 49 | from ubuntuone.syncdaemon import logger, config |
19 | 42 | from ubuntuone.syncdaemon.config import ( | 50 | from ubuntuone.syncdaemon.config import ( |
20 | 43 | get_config_files, | 51 | get_config_files, |
21 | @@ -127,31 +135,36 @@ | |||
22 | 127 | 135 | ||
23 | 128 | # check if we are using xdg_data_home and it doesn't exists | 136 | # check if we are using xdg_data_home and it doesn't exists |
24 | 129 | if xdg_data_home in options.data_dir and \ | 137 | if xdg_data_home in options.data_dir and \ |
26 | 130 | not os.path.exists(options.data_dir): | 138 | not path_exists(options.data_dir): |
27 | 131 | # if we have metadata in the old xdg_cache, move it! | 139 | # if we have metadata in the old xdg_cache, move it! |
28 | 132 | old_data_dir = options.data_dir.replace(xdg_data_home, xdg_cache_home) | 140 | old_data_dir = options.data_dir.replace(xdg_data_home, xdg_cache_home) |
30 | 133 | if os.path.exists(old_data_dir): | 141 | if path_exists(old_data_dir): |
31 | 134 | parent = os.path.dirname(options.data_dir) | 142 | parent = os.path.dirname(options.data_dir) |
33 | 135 | if os.path.exists(parent) and not os.access(parent, os.W_OK): | 143 | if path_exists(parent) and not can_write(parent): |
34 | 136 | # make the parent dir writable | 144 | # make the parent dir writable |
37 | 137 | os.chmod(parent, 0775) | 145 | set_dir_readwrite(parent) |
38 | 138 | elif not os.path.exists(parent): | 146 | elif not path_exists(parent): |
39 | 139 | # if it don't exits | 147 | # if it don't exits |
41 | 140 | os.makedirs(parent) | 148 | make_dir(parent, recursive=True) |
42 | 141 | shutil.move(old_data_dir, options.data_dir) | 149 | shutil.move(old_data_dir, options.data_dir) |
44 | 142 | if not os.path.exists(options.data_dir): | 150 | if not path_exists(options.data_dir): |
45 | 143 | parent = os.path.dirname(options.data_dir) | 151 | parent = os.path.dirname(options.data_dir) |
47 | 144 | if os.path.exists(parent) and not os.access(parent, os.W_OK): | 152 | if path_exists(parent) and not can_write(parent): |
48 | 145 | # make the parent dir writable | 153 | # make the parent dir writable |
51 | 146 | os.chmod(parent, 0775) | 154 | set_dir_readwrite(parent) |
52 | 147 | os.makedirs(options.data_dir) | 155 | make_dir(options.data_dir, recursive=True) |
53 | 148 | 156 | ||
54 | 149 | # create the partials_dir | 157 | # create the partials_dir |
55 | 150 | partials_dir = os.path.join(xdg_cache_home, 'ubuntuone', 'partials') | 158 | partials_dir = os.path.join(xdg_cache_home, 'ubuntuone', 'partials') |
58 | 151 | if not os.path.exists(partials_dir): | 159 | if not path_exists(partials_dir): |
59 | 152 | os.makedirs(partials_dir) | 160 | make_dir(partials_dir, recursive=True) |
60 | 153 | 161 | ||
61 | 154 | logger.rotate_logs() | 162 | logger.rotate_logs() |
62 | 163 | |||
63 | 164 | assert isinstance(options.root_dir, str) | ||
64 | 165 | assert isinstance(options.shares_dir, str) | ||
65 | 166 | assert isinstance(options.data_dir, str) | ||
66 | 167 | |||
67 | 155 | main = Main(options.root_dir, options.shares_dir, options.data_dir, | 168 | main = Main(options.root_dir, options.shares_dir, options.data_dir, |
68 | 156 | partials_dir, host=options.host, port=int(options.port), | 169 | partials_dir, host=options.host, port=int(options.port), |
69 | 157 | dns_srv=options.dns_srv, ssl=True, | 170 | dns_srv=options.dns_srv, ssl=True, |
70 | 158 | 171 | ||
71 | === modified file 'tests/platform/test_xdg_base_directory.py' | |||
72 | --- tests/platform/test_xdg_base_directory.py 2011-07-26 16:07:08 +0000 | |||
73 | +++ tests/platform/test_xdg_base_directory.py 2011-07-29 19:11:49 +0000 | |||
74 | @@ -34,3 +34,13 @@ | |||
75 | 34 | 'ubuntuone', 'log') | 34 | 'ubuntuone', 'log') |
76 | 35 | self.assertEqual(expected, xdg_base_directory.ubuntuone_log_dir) | 35 | self.assertEqual(expected, xdg_base_directory.ubuntuone_log_dir) |
77 | 36 | self.assertTrue(os.path.exists(expected)) | 36 | self.assertTrue(os.path.exists(expected)) |
78 | 37 | |||
79 | 38 | def test_xdg_cache_home_is_bytes(self): | ||
80 | 39 | """The returned path is bytes.""" | ||
81 | 40 | actual = xdg_base_directory.xdg_cache_home | ||
82 | 41 | self.assertIsInstance(actual, str) | ||
83 | 42 | |||
84 | 43 | def test_xdg_data_home_is_bytes(self): | ||
85 | 44 | """The returned path is bytes.""" | ||
86 | 45 | actual = xdg_base_directory.xdg_data_home | ||
87 | 46 | self.assertIsInstance(actual, str) | ||
88 | 37 | 47 | ||
89 | === modified file 'tests/platform/windows/test_xdg_base_directory.py' | |||
90 | --- tests/platform/windows/test_xdg_base_directory.py 2011-07-28 12:51:07 +0000 | |||
91 | +++ tests/platform/windows/test_xdg_base_directory.py 2011-07-29 19:11:49 +0000 | |||
92 | @@ -17,12 +17,11 @@ | |||
93 | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
94 | 18 | """Platform independent tests for the credentials management.""" | 18 | """Platform independent tests for the credentials management.""" |
95 | 19 | 19 | ||
96 | 20 | import os | ||
97 | 21 | |||
98 | 22 | import win32com.shell | 20 | import win32com.shell |
99 | 23 | 21 | ||
100 | 24 | from twisted.trial.unittest import TestCase | 22 | from twisted.trial.unittest import TestCase |
101 | 25 | 23 | ||
102 | 24 | from ubuntuone.platform.windows.os_helper import assert_syncdaemon_path | ||
103 | 26 | from ubuntuone.platform.xdg_base_directory.windows import get_special_folders | 25 | from ubuntuone.platform.xdg_base_directory.windows import get_special_folders |
104 | 27 | 26 | ||
105 | 28 | 27 | ||
106 | @@ -38,8 +37,8 @@ | |||
107 | 38 | def __init__(self): | 37 | def __init__(self): |
108 | 39 | """Set the proper mapping between CSIDL_ consts.""" | 38 | """Set the proper mapping between CSIDL_ consts.""" |
109 | 40 | self.values = { | 39 | self.values = { |
112 | 41 | 0: r'c:\path\to\users\home', | 40 | 0: u'c:\\path\\to\\users\\home', |
113 | 42 | 1: r'c:\path\to\users\home\appData\local'} | 41 | 1: u'c:\\path\\to\\users\\home\\appData\\local'} |
114 | 43 | 42 | ||
115 | 44 | def SHGetFolderPath(self, dummy0, shellconValue, dummy2, dummy3): | 43 | def SHGetFolderPath(self, dummy0, shellconValue, dummy2, dummy3): |
116 | 45 | """Override SHGetFolderPath functionality.""" | 44 | """Override SHGetFolderPath functionality.""" |
117 | @@ -67,5 +66,5 @@ | |||
118 | 67 | self.assertTrue(special_folders['Local AppData'].startswith( | 66 | self.assertTrue(special_folders['Local AppData'].startswith( |
119 | 68 | special_folders['AppData'])) | 67 | special_folders['AppData'])) |
120 | 69 | 68 | ||
123 | 70 | for k in special_folders: | 69 | for val in special_folders.itervalues(): |
124 | 71 | os.access(special_folders[k], os.W_OK) | 70 | assert_syncdaemon_path(val) |
125 | 72 | 71 | ||
126 | === modified file 'tests/syncdaemon/test_config.py' | |||
127 | --- tests/syncdaemon/test_config.py 2011-07-27 13:27:22 +0000 | |||
128 | +++ tests/syncdaemon/test_config.py 2011-07-29 19:11:49 +0000 | |||
129 | @@ -471,7 +471,7 @@ | |||
130 | 471 | 471 | ||
131 | 472 | 472 | ||
132 | 473 | class ConfigglueParsersTests(BaseTwistedTestCase): | 473 | class ConfigglueParsersTests(BaseTwistedTestCase): |
134 | 474 | """Tests for our custom configglue parsers""" | 474 | """Tests for our custom configglue parsers.""" |
135 | 475 | 475 | ||
136 | 476 | def test_throttling_limit_parser(self): | 476 | def test_throttling_limit_parser(self): |
137 | 477 | """Test throttling_limit_parser""" | 477 | """Test throttling_limit_parser""" |
138 | @@ -497,39 +497,55 @@ | |||
139 | 497 | self.assertEqual(logging.DEBUG, parser(bad_value)) | 497 | self.assertEqual(logging.DEBUG, parser(bad_value)) |
140 | 498 | self.assertEqual(logging.DEBUG, parser(invalid_value)) | 498 | self.assertEqual(logging.DEBUG, parser(invalid_value)) |
141 | 499 | 499 | ||
149 | 500 | def test_home_dir_parser(self): | 500 | |
150 | 501 | """Test home_dir_parser""" | 501 | class XdgHomeParsersTests(BaseTwistedTestCase): |
151 | 502 | good_value = '~/hola' | 502 | """Tests for our custom xdg parsers.""" |
152 | 503 | bad_value = 'hola' | 503 | |
153 | 504 | invalid_value = None | 504 | good_value = '~/hola/mundo' |
154 | 505 | parser = config.home_dir_parser | 505 | name = 'home' |
155 | 506 | homedir = os.path.join('/', 'home', 'fake') | 506 | xdg_dir = os.path.join('', 'home', 'fake') |
156 | 507 | |||
157 | 508 | @defer.inlineCallbacks | ||
158 | 509 | def setUp(self): | ||
159 | 510 | yield super(XdgHomeParsersTests, self).setUp() | ||
160 | 511 | self.parser = getattr(config, '%s_dir_parser' % self.name) | ||
161 | 512 | |||
162 | 513 | def test_good_value(self): | ||
163 | 514 | """Test the parser using a good value.""" | ||
164 | 515 | homedir = os.path.join('', 'home', 'fake') | ||
165 | 507 | with environ('HOME', homedir): | 516 | with environ('HOME', homedir): |
191 | 508 | self.assertEqual(os.path.join(homedir, 'hola'), parser(good_value)) | 517 | expected = os.path.join(self.xdg_dir, 'hola', 'mundo') |
192 | 509 | self.assertEqual('hola', parser(bad_value)) | 518 | actual = self.parser(self.good_value) |
193 | 510 | self.assertRaises(AttributeError, parser, invalid_value) | 519 | self.assertEqual(expected, actual) |
194 | 511 | 520 | self.assertIsInstance(actual, str) | |
195 | 512 | def test_xdg_cache_dir_parser(self): | 521 | self.assertNotIsInstance(actual, unicode) |
196 | 513 | """Test xdg_cache_dir_parser""" | 522 | |
197 | 514 | good_value = 'hola' | 523 | def test_bad_value(self): |
198 | 515 | bad_value = '/hola' | 524 | """Test the parser using a bad value.""" |
199 | 516 | invalid_value = None | 525 | bad_value = '/hola' |
200 | 517 | parser = config.xdg_cache_dir_parser | 526 | self.assertEqual(config.path_from_unix(bad_value), |
201 | 518 | self.assertEquals(os.path.join(xdg_cache_home, 'hola'), | 527 | self.parser(bad_value)) |
202 | 519 | parser(good_value)) | 528 | |
203 | 520 | self.assertEquals('/hola', parser(bad_value)) | 529 | def test_invalid_value(self): |
204 | 521 | self.assertRaises(AttributeError, parser, invalid_value) | 530 | """Test the parser using an invalid value.""" |
205 | 522 | 531 | invalid_value = None | |
206 | 523 | def test_xdg_data_dir_parser(self): | 532 | self.assertRaises(AttributeError, self.parser, invalid_value) |
207 | 524 | """Test xdg_data_dir_parser""" | 533 | |
208 | 525 | good_value = 'hola' | 534 | |
209 | 526 | bad_value = '/hola' | 535 | class XdgCacheParsersTests(XdgHomeParsersTests): |
210 | 527 | invalid_value = None | 536 | """Tests for our custom xdg parsers.""" |
211 | 528 | parser = config.xdg_data_dir_parser | 537 | |
212 | 529 | self.assertEquals(os.path.join(xdg_data_home, 'hola'), | 538 | good_value = 'hola/mundo' |
213 | 530 | parser(good_value)) | 539 | name = 'xdg_cache' |
214 | 531 | self.assertEquals('/hola', parser(bad_value)) | 540 | xdg_dir = xdg_cache_home |
215 | 532 | self.assertRaises(AttributeError, parser, invalid_value) | 541 | |
216 | 542 | |||
217 | 543 | class XdgDataParsersTests(XdgCacheParsersTests): | ||
218 | 544 | """Tests for our custom xdg parsers.""" | ||
219 | 545 | |||
220 | 546 | good_value = 'hola/mundo' | ||
221 | 547 | name = 'xdg_data' | ||
222 | 548 | xdg_dir = xdg_data_home | ||
223 | 533 | 549 | ||
224 | 534 | 550 | ||
225 | 535 | class SyncDaemonConfigParserTests(BaseTwistedTestCase): | 551 | class SyncDaemonConfigParserTests(BaseTwistedTestCase): |
226 | 536 | 552 | ||
227 | === modified file 'ubuntuone/platform/linux/__init__.py' | |||
228 | --- ubuntuone/platform/linux/__init__.py 2011-07-28 17:32:56 +0000 | |||
229 | +++ ubuntuone/platform/linux/__init__.py 2011-07-29 19:11:49 +0000 | |||
230 | @@ -52,13 +52,13 @@ | |||
231 | 52 | set_file_readwrite, | 52 | set_file_readwrite, |
232 | 53 | set_no_rights, | 53 | set_no_rights, |
233 | 54 | stat_path, | 54 | stat_path, |
234 | 55 | validate_path_from_unix, | ||
235 | 56 | ) | 55 | ) |
236 | 57 | from ubuntuone.platform.linux.credentials import CredentialsManagementTool | 56 | from ubuntuone.platform.linux.credentials import CredentialsManagementTool |
237 | 58 | from ubuntuone.platform.linux.logger import setup_filesystem_logging, get_filesystem_logger | 57 | from ubuntuone.platform.linux.logger import setup_filesystem_logging, get_filesystem_logger |
238 | 59 | from ubuntuone.platform.linux.filesystem_notifications import FilesystemMonitor | 58 | from ubuntuone.platform.linux.filesystem_notifications import FilesystemMonitor |
239 | 60 | from ubuntuone.platform.linux.notification import Notification | 59 | from ubuntuone.platform.linux.notification import Notification |
240 | 61 | 60 | ||
241 | 61 | |||
242 | 62 | class ExternalInterface(object): | 62 | class ExternalInterface(object): |
243 | 63 | """An ExternalInterface implemented with a DBus interface.""" | 63 | """An ExternalInterface implemented with a DBus interface.""" |
244 | 64 | 64 | ||
245 | 65 | 65 | ||
246 | === modified file 'ubuntuone/platform/linux/os_helper.py' | |||
247 | --- ubuntuone/platform/linux/os_helper.py 2011-07-19 21:59:27 +0000 | |||
248 | +++ ubuntuone/platform/linux/os_helper.py 2011-07-29 19:11:49 +0000 | |||
249 | @@ -154,12 +154,7 @@ | |||
250 | 154 | 154 | ||
251 | 155 | def is_root(): | 155 | def is_root(): |
252 | 156 | """Return if the user is running as root.""" | 156 | """Return if the user is running as root.""" |
259 | 157 | return not os.geteuid() | 157 | return not os.geteuid() |
254 | 158 | |||
255 | 159 | |||
256 | 160 | def validate_path_from_unix(path): | ||
257 | 161 | """Get a unix path and return it so that it cna be used.""" | ||
258 | 162 | return path | ||
260 | 163 | 158 | ||
261 | 164 | 159 | ||
262 | 165 | def get_path_list(path): | 160 | def get_path_list(path): |
263 | 166 | 161 | ||
264 | === modified file 'ubuntuone/platform/windows/__init__.py' | |||
265 | --- ubuntuone/platform/windows/__init__.py 2011-07-28 17:32:56 +0000 | |||
266 | +++ ubuntuone/platform/windows/__init__.py 2011-07-29 19:11:49 +0000 | |||
267 | @@ -51,7 +51,6 @@ | |||
268 | 51 | set_file_readwrite, | 51 | set_file_readwrite, |
269 | 52 | set_no_rights, | 52 | set_no_rights, |
270 | 53 | stat_path, | 53 | stat_path, |
271 | 54 | validate_path_from_unix, | ||
272 | 55 | ) | 54 | ) |
273 | 56 | from ubuntuone.platform.windows.credentials import CredentialsManagementTool | 55 | from ubuntuone.platform.windows.credentials import CredentialsManagementTool |
274 | 57 | from ubuntuone.platform.windows import event_logging | 56 | from ubuntuone.platform.windows import event_logging |
275 | 58 | 57 | ||
276 | === modified file 'ubuntuone/platform/windows/os_helper.py' | |||
277 | --- ubuntuone/platform/windows/os_helper.py 2011-07-28 15:43:05 +0000 | |||
278 | +++ ubuntuone/platform/windows/os_helper.py 2011-07-29 19:11:49 +0000 | |||
279 | @@ -716,12 +716,6 @@ | |||
280 | 716 | return False | 716 | return False |
281 | 717 | 717 | ||
282 | 718 | 718 | ||
283 | 719 | def validate_path_from_unix(path): | ||
284 | 720 | """Get a unix path and return it so that it can be used.""" | ||
285 | 721 | path = path.replace('/', '\\') | ||
286 | 722 | return path | ||
287 | 723 | |||
288 | 724 | |||
289 | 725 | @windowspath() | 719 | @windowspath() |
290 | 726 | def get_path_list(path): | 720 | def get_path_list(path): |
291 | 727 | """Return a list with the diff components of the path.""" | 721 | """Return a list with the diff components of the path.""" |
292 | 728 | 722 | ||
293 | === modified file 'ubuntuone/platform/xdg_base_directory/windows.py' | |||
294 | --- ubuntuone/platform/xdg_base_directory/windows.py 2011-07-27 21:09:30 +0000 | |||
295 | +++ ubuntuone/platform/xdg_base_directory/windows.py 2011-07-29 19:11:49 +0000 | |||
296 | @@ -31,11 +31,12 @@ | |||
297 | 31 | # CSIDL_LOCAL_APPDATA = C:\Users\<username>\AppData\Local | 31 | # CSIDL_LOCAL_APPDATA = C:\Users\<username>\AppData\Local |
298 | 32 | # CSIDL_PROFILE = C:\Users\<username> | 32 | # CSIDL_PROFILE = C:\Users\<username> |
299 | 33 | path = shell.SHGetFolderPath(0, shellcon.CSIDL_PROFILE, None, 0) | 33 | path = shell.SHGetFolderPath(0, shellcon.CSIDL_PROFILE, None, 0) |
301 | 34 | special_folders['Personal'] = path | 34 | special_folders['Personal'] = path.encode('utf8') |
302 | 35 | 35 | ||
303 | 36 | path = shell.SHGetFolderPath(0, shellcon.CSIDL_LOCAL_APPDATA, None, 0) | 36 | path = shell.SHGetFolderPath(0, shellcon.CSIDL_LOCAL_APPDATA, None, 0) |
306 | 37 | special_folders['Local AppData'] = path | 37 | special_folders['Local AppData'] = path.encode('utf8') |
307 | 38 | special_folders['AppData'] = os.path.dirname(path) | 38 | path = os.path.dirname(path) |
308 | 39 | special_folders['AppData'] = path.encode('utf8') | ||
309 | 39 | 40 | ||
310 | 40 | return special_folders | 41 | return special_folders |
311 | 41 | 42 | ||
312 | 42 | 43 | ||
313 | === modified file 'ubuntuone/syncdaemon/config.py' | |||
314 | --- ubuntuone/syncdaemon/config.py 2011-07-28 15:43:05 +0000 | |||
315 | +++ ubuntuone/syncdaemon/config.py 2011-07-29 19:11:49 +0000 | |||
316 | @@ -25,6 +25,7 @@ | |||
317 | 25 | 25 | ||
318 | 26 | from ConfigParser import NoOptionError, NoSectionError | 26 | from ConfigParser import NoOptionError, NoSectionError |
319 | 27 | from optparse import OptionParser | 27 | from optparse import OptionParser |
320 | 28 | from ubuntuone.platform import path_exists, rename | ||
321 | 28 | from ubuntuone.platform.xdg_base_directory import ( | 29 | from ubuntuone.platform.xdg_base_directory import ( |
322 | 29 | load_config_paths, | 30 | load_config_paths, |
323 | 30 | save_config_path, | 31 | save_config_path, |
324 | @@ -56,7 +57,6 @@ | |||
325 | 56 | TypedConfigParser = new_tcp | 57 | TypedConfigParser = new_tcp |
326 | 57 | del new_tcp | 58 | del new_tcp |
327 | 58 | # end of naming shenanigans | 59 | # end of naming shenanigans |
328 | 59 | from ubuntuone.platform import validate_path_from_unix | ||
329 | 60 | 60 | ||
330 | 61 | CONFIG_FILE = 'syncdaemon.conf' | 61 | CONFIG_FILE = 'syncdaemon.conf' |
331 | 62 | CONFIG_LOGS = 'logging.conf' | 62 | CONFIG_LOGS = 'logging.conf' |
332 | @@ -76,6 +76,8 @@ | |||
333 | 76 | # this object is the shared config | 76 | # this object is the shared config |
334 | 77 | _user_config = None | 77 | _user_config = None |
335 | 78 | 78 | ||
336 | 79 | path_from_unix = lambda path: path.replace('/', os.path.sep) | ||
337 | 80 | |||
338 | 79 | 81 | ||
339 | 80 | def home_dir_parser(value): | 82 | def home_dir_parser(value): |
340 | 81 | """Parser for the root_dir and shares_dir options. | 83 | """Parser for the root_dir and shares_dir options. |
341 | @@ -83,21 +85,31 @@ | |||
342 | 83 | Return the path using user home + value. | 85 | Return the path using user home + value. |
343 | 84 | 86 | ||
344 | 85 | """ | 87 | """ |
346 | 86 | return os.path.expanduser(validate_path_from_unix(value)) | 88 | result = os.path.expanduser(path_from_unix(value)) |
347 | 89 | assert isinstance(result, str) | ||
348 | 90 | return result | ||
349 | 87 | 91 | ||
350 | 88 | 92 | ||
351 | 89 | def xdg_cache_dir_parser(value): | 93 | def xdg_cache_dir_parser(value): |
354 | 90 | """ Parser for the data_dir option. | 94 | """Parser for the data_dir option. |
355 | 91 | returns the path using xdg_cache_home + value. | 95 | |
356 | 96 | Return the path using xdg_cache_home + value. | ||
357 | 97 | |||
358 | 92 | """ | 98 | """ |
360 | 93 | return os.path.join(xdg_cache_home, validate_path_from_unix(value)) | 99 | result = os.path.join(xdg_cache_home, path_from_unix(value)) |
361 | 100 | assert isinstance(result, str) | ||
362 | 101 | return result | ||
363 | 94 | 102 | ||
364 | 95 | 103 | ||
365 | 96 | def xdg_data_dir_parser(value): | 104 | def xdg_data_dir_parser(value): |
368 | 97 | """ Parser for the data_dir option. | 105 | """Parser for the data_dir option. |
369 | 98 | returns the path using xdg_data_home + value. | 106 | |
370 | 107 | Return the path using xdg_data_home + value. | ||
371 | 108 | |||
372 | 99 | """ | 109 | """ |
374 | 100 | return os.path.join(xdg_data_home, validate_path_from_unix(value)) | 110 | result = os.path.join(xdg_data_home, path_from_unix(value)) |
375 | 111 | assert isinstance(result, str) | ||
376 | 112 | return result | ||
377 | 101 | 113 | ||
378 | 102 | 114 | ||
379 | 103 | def log_level_parser(value): | 115 | def log_level_parser(value): |
380 | @@ -140,11 +152,11 @@ | |||
381 | 140 | config_files = [] | 152 | config_files = [] |
382 | 141 | for xdg_config_dir in load_config_paths('ubuntuone'): | 153 | for xdg_config_dir in load_config_paths('ubuntuone'): |
383 | 142 | config_file = os.path.join(xdg_config_dir, CONFIG_FILE) | 154 | config_file = os.path.join(xdg_config_dir, CONFIG_FILE) |
385 | 143 | if os.path.exists(config_file): | 155 | if path_exists(config_file): |
386 | 144 | config_files.append(config_file) | 156 | config_files.append(config_file) |
387 | 145 | 157 | ||
388 | 146 | config_logs = os.path.join(xdg_config_dir, CONFIG_LOGS) | 158 | config_logs = os.path.join(xdg_config_dir, CONFIG_LOGS) |
390 | 147 | if os.path.exists(config_logs): | 159 | if path_exists(config_logs): |
391 | 148 | config_files.append(config_logs) | 160 | config_files.append(config_logs) |
392 | 149 | 161 | ||
393 | 150 | # reverse the list as load_config_paths returns the user dir first | 162 | # reverse the list as load_config_paths returns the user dir first |
394 | @@ -152,11 +164,11 @@ | |||
395 | 152 | # if we are running from a branch, get the config files from it too | 164 | # if we are running from a branch, get the config files from it too |
396 | 153 | config_file = os.path.join(os.path.dirname(__file__), os.path.pardir, | 165 | config_file = os.path.join(os.path.dirname(__file__), os.path.pardir, |
397 | 154 | os.path.pardir, 'data', CONFIG_FILE) | 166 | os.path.pardir, 'data', CONFIG_FILE) |
399 | 155 | if os.path.exists(config_file): | 167 | if path_exists(config_file): |
400 | 156 | config_files.append(config_file) | 168 | config_files.append(config_file) |
401 | 157 | 169 | ||
402 | 158 | config_logs = os.path.join('data', CONFIG_LOGS) | 170 | config_logs = os.path.join('data', CONFIG_LOGS) |
404 | 159 | if os.path.exists(config_logs): | 171 | if path_exists(config_logs): |
405 | 160 | config_files.append(config_logs) | 172 | config_files.append(config_logs) |
406 | 161 | 173 | ||
407 | 162 | return config_files | 174 | return config_files |
408 | @@ -279,11 +291,11 @@ | |||
409 | 279 | for section in [MAIN, THROTTLING, NOTIFICATIONS]: | 291 | for section in [MAIN, THROTTLING, NOTIFICATIONS]: |
410 | 280 | if self.has_section(section) and not self.options(section): | 292 | if self.has_section(section) and not self.options(section): |
411 | 281 | self.remove_section(section) | 293 | self.remove_section(section) |
413 | 282 | with open(self.config_file+'.new', 'w') as fp: | 294 | with open(self.config_file + '.new', 'w') as fp: |
414 | 283 | self.write(fp) | 295 | self.write(fp) |
418 | 284 | if os.path.exists(self.config_file): | 296 | if path_exists(self.config_file): |
419 | 285 | os.rename(self.config_file, self.config_file+'.old') | 297 | rename(self.config_file, self.config_file + '.old') |
420 | 286 | os.rename(self.config_file+'.new', self.config_file) | 298 | rename(self.config_file + '.new', self.config_file) |
421 | 287 | 299 | ||
422 | 288 | def get_parsed(self, section, option): | 300 | def get_parsed(self, section, option): |
423 | 289 | """get that fallbacks to our custom defaults""" | 301 | """get that fallbacks to our custom defaults""" |
424 | 290 | 302 | ||
425 | === modified file 'ubuntuone/syncdaemon/main.py' | |||
426 | --- ubuntuone/syncdaemon/main.py 2011-06-23 13:10:19 +0000 | |||
427 | +++ ubuntuone/syncdaemon/main.py 2011-07-29 19:11:49 +0000 | |||
428 | @@ -98,6 +98,9 @@ | |||
429 | 98 | 98 | ||
430 | 99 | self.logger.info("Starting Ubuntu One client version %s", | 99 | self.logger.info("Starting Ubuntu One client version %s", |
431 | 100 | clientdefs.VERSION) | 100 | clientdefs.VERSION) |
432 | 101 | self.logger.info("Using %r as root dir", self.root_dir) | ||
433 | 102 | self.logger.info("Using %r as data dir", self.data_dir) | ||
434 | 103 | self.logger.info("Using %r as shares root dir", self.shares_dir) | ||
435 | 101 | self.db = tritcask.Tritcask(self.tritcask_dir) | 104 | self.db = tritcask.Tritcask(self.tritcask_dir) |
436 | 102 | self.vm = volume_manager.VolumeManager(self) | 105 | self.vm = volume_manager.VolumeManager(self) |
437 | 103 | self.fs = filesystem_manager.FileSystemManager( | 106 | self.fs = filesystem_manager.FileSystemManager( |
438 | @@ -135,9 +138,6 @@ | |||
439 | 135 | self.eventlog_listener = None | 138 | self.eventlog_listener = None |
440 | 136 | self.start_event_logger() | 139 | self.start_event_logger() |
441 | 137 | self.start_status_listener() | 140 | self.start_status_listener() |
442 | 138 | self.logger.info("Using %r as root dir", self.root_dir) | ||
443 | 139 | self.logger.info("Using %r as data dir", self.data_dir) | ||
444 | 140 | self.logger.info("Using %r as shares root dir", self.shares_dir) | ||
445 | 141 | self.mark = task.LoopingCall(self.log_mark) | 141 | self.mark = task.LoopingCall(self.log_mark) |
446 | 142 | self.mark.start(mark_interval) | 142 | self.mark.start(mark_interval) |
447 | 143 | 143 |
looks good.