Merge lp:~mandel/ubuntuone-client/legal_linux_chars into lp:ubuntuone-client

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 1042
Merged at revision: 1009
Proposed branch: lp:~mandel/ubuntuone-client/legal_linux_chars
Merge into: lp:ubuntuone-client
Prerequisite: lp:~mandel/ubuntuone-client/illegal_windows_chars
Diff against target: 277 lines (+64/-35)
3 files modified
tests/platform/windows/test_os_helper.py (+22/-15)
ubuntuone/platform/windows/filesystem_notifications.py (+4/-2)
ubuntuone/platform/windows/os_helper.py (+38/-18)
To merge this branch: bzr merge lp:~mandel/ubuntuone-client/legal_linux_chars
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+65285@code.launchpad.net

Commit message

Allow to send the events to the state machine that do not have the utf8 special chars.

Description of the change

Allow to send the events to the state machine that do not have the utf8 special chars. To test do:

python C:\Python27\Scripts\u1trial tests\platform\windows\test_os_helper.py

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) :
review: Approve
Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/platform/windows/test_os_helper.py'
2--- tests/platform/windows/test_os_helper.py 2011-06-20 16:50:13 +0000
3+++ tests/platform/windows/test_os_helper.py 2011-06-21 10:21:47 +0000
4@@ -20,8 +20,9 @@
5 import errno
6
7 from ubuntuone.platform.windows.os_helper import (
8- _remove_windows_illegal_chars,
9+ remove_windows_illegal_chars,
10 access,
11+ is_illegal_path,
12 listdir,
13 make_dir,
14 open_file,
15@@ -29,6 +30,7 @@
16 remove_dir,
17 remove_file,
18 rename,
19+ remove_utf8_chars,
20 set_no_rights,
21 set_file_readwrite,
22 stat_path,
23@@ -46,7 +48,7 @@
24 self.basedir = self.mktemp('test_root')
25 self.testfile = os.path.join(self.basedir, "test_file")
26 self.testfile += ''.join(WINDOWS_ILLEGAL_CHARS_MAP)
27- self.fd = open(_remove_windows_illegal_chars(self.testfile), 'w')
28+ self.fd = open(remove_windows_illegal_chars(self.testfile), 'w')
29
30 def test_path_file_exist_yes(self):
31 """Test that the file exists."""
32@@ -55,7 +57,7 @@
33 def test_path_file_exist_no(self):
34 """Test that the file doesn't exist."""
35 self.fd.close()
36- os.remove(_remove_windows_illegal_chars(self.testfile))
37+ os.remove(remove_windows_illegal_chars(self.testfile))
38 self.assertFalse(path_exists(self.testfile))
39
40 def test_path_dir_exist_yes(self):
41@@ -65,7 +67,7 @@
42 def test_path_dir_exist_no(self):
43 """Test that the dir doesn't exist."""
44 self.fd.close()
45- os.remove(_remove_windows_illegal_chars(self.testfile))
46+ os.remove(remove_windows_illegal_chars(self.testfile))
47 self.assertFalse(path_exists(os.path.join(self.basedir, 'nodir')))
48
49 def test_remove_file(self):
50@@ -73,7 +75,7 @@
51 self.fd.close()
52 remove_file(self.testfile)
53 self.assertFalse(os.path.exists(
54- _remove_windows_illegal_chars(self.testfile)))
55+ remove_windows_illegal_chars(self.testfile)))
56
57 def test_remove_dir(self):
58 """Test the remove dir."""
59@@ -143,23 +145,23 @@
60 """Rename a file."""
61 testfile1 = os.path.join(self.basedir, 'testfile1>')
62 testfile2 = os.path.join(self.basedir, 'testfile2<')
63- open(_remove_windows_illegal_chars(testfile1), 'w').close()
64+ open(remove_windows_illegal_chars(testfile1), 'w').close()
65 rename(testfile1, testfile2)
66 self.assertFalse(os.path.exists(
67- _remove_windows_illegal_chars(testfile1)))
68+ remove_windows_illegal_chars(testfile1)))
69 self.assertTrue(os.path.exists(
70- _remove_windows_illegal_chars(testfile2)))
71+ remove_windows_illegal_chars(testfile2)))
72
73 def test_rename_dir(self):
74 """Rename a dir."""
75 testdir1 = os.path.join(self.basedir, 'testdir1>')
76 testdir2 = os.path.join(self.basedir, 'testdir2<')
77- os.mkdir(_remove_windows_illegal_chars(testdir1))
78+ os.mkdir(remove_windows_illegal_chars(testdir1))
79 rename(testdir1, testdir2)
80 self.assertFalse(os.path.exists(
81- _remove_windows_illegal_chars(testdir1)))
82+ remove_windows_illegal_chars(testdir1)))
83 self.assertTrue(os.path.exists(
84- _remove_windows_illegal_chars(testdir2)))
85+ remove_windows_illegal_chars(testdir2)))
86
87 def test_listdir(self):
88 """Return a list of the files in a dir."""
89@@ -177,7 +179,7 @@
90
91 def test_access_ro(self):
92 """Test access on a file with read only permission."""
93- fixed_path = _remove_windows_illegal_chars(self.testfile)
94+ fixed_path = remove_windows_illegal_chars(self.testfile)
95 os.chmod(fixed_path, 0o444)
96 self.assertTrue(access(self.testfile))
97 os.chmod(fixed_path, 0o664)
98@@ -190,7 +192,7 @@
99
100 def test_stat_normal(self):
101 """Test on a normal file."""
102- self.assertEqual(os.stat(_remove_windows_illegal_chars(self.testfile)),
103+ self.assertEqual(os.stat(remove_windows_illegal_chars(self.testfile)),
104 stat_path(self.testfile))
105
106 def test_stat_no_path(self):
107@@ -207,7 +209,7 @@
108 def test_path_exists_file_no(self):
109 """The file is not there."""
110 self.fd.close()
111- os.remove(_remove_windows_illegal_chars(self.testfile))
112+ os.remove(remove_windows_illegal_chars(self.testfile))
113 self.assertFalse(path_exists(self.testfile))
114
115 def test_path_exists_dir_yes(self):
116@@ -217,4 +219,9 @@
117 def test_path_exists_dir_no(self):
118 """The dir is not there."""
119 self.fd.close()
120- self.assertFalse(path_exists(os.path.join(self.basedir, 'subdir')))
121\ No newline at end of file
122+ self.assertFalse(path_exists(os.path.join(self.basedir, 'subdir')))
123+
124+ def test_remove_utf8_chars(self):
125+ """Test that the path does not have utf chars."""
126+ path = remove_utf8_chars(remove_windows_illegal_chars(self.testfile))
127+ self.assertFalse(is_illegal_path(path))
128\ No newline at end of file
129
130=== modified file 'ubuntuone/platform/windows/filesystem_notifications.py'
131--- ubuntuone/platform/windows/filesystem_notifications.py 2011-06-17 09:25:12 +0000
132+++ ubuntuone/platform/windows/filesystem_notifications.py 2011-06-21 10:21:47 +0000
133@@ -67,7 +67,8 @@
134 GeneralINotifyProcessor)
135 from ubuntuone.platform.windows.os_helper import (
136 LONG_PATH_PREFIX,
137- listdir)
138+ listdir,
139+ remove_utf8_chars)
140 from ubuntuone import logger
141 from ubuntuone.platform.windows.os_helper import longpath
142 # our logging level
143@@ -275,7 +276,8 @@
144 # add the diff events to the q so that the can be processed no
145 # matter the speed.
146 for action, file in results:
147- full_filename = os.path.join(self._path, file)
148+ full_filename = remove_utf8_chars(os.path.join(self._path,
149+ file))
150 self._raw_events_queue.put((full_filename, action))
151 self.log.debug('Added %s to raw events queue.',
152 (full_filename, action))
153
154=== modified file 'ubuntuone/platform/windows/os_helper.py'
155--- ubuntuone/platform/windows/os_helper.py 2011-06-20 23:59:33 +0000
156+++ ubuntuone/platform/windows/os_helper.py 2011-06-21 10:21:47 +0000
157@@ -126,23 +126,22 @@
158 def _check_winerror_123(exception, cb, path, *args, **kwargs):
159 """Checks if an exception is a 123 error and executes the cb."""
160 if getattr(exception, "winerror", None) == 123 :
161- path = _remove_windows_illegal_chars(path)
162+ path = remove_windows_illegal_chars(path)
163 return cb(path, *args, **kwargs)
164 else:
165 raise exception
166
167
168-def _is_illegal_path(path):
169- """Return if the path is illegal in the system."""
170+def _contains_chars(path, chars):
171+ """Returns if one of the chars is in the path."""
172 if LONG_PATH_PREFIX in path:
173 path = path.replace(LONG_PATH_PREFIX, '')
174- return any(c in WINDOWS_ILLEGAL_CHARS_MAP
175- for c in os.path.splitdrive(path)[1])
176-
177-
178-def _remove_windows_illegal_chars(path):
179+ return any(c in chars for c in os.path.splitdrive(path)[1])
180+
181+
182+def _modify_chars(path, should_apply, chars):
183 """Remove illegal chars and return a valid windows path."""
184- if not _is_illegal_path(path):
185+ if not should_apply(path):
186 return path
187 prefix = False
188 # do not split the path if you have a long path prefix since the
189@@ -156,7 +155,7 @@
190 result = []
191 for partial in partial_paths:
192 # ensure that the illegal chars are not there
193- for illegal_char, replacement in WINDOWS_ILLEGAL_CHARS_MAP.iteritems():
194+ for illegal_char, replacement in chars.iteritems():
195 partial = partial.replace(illegal_char, replacement)
196 result.append(partial)
197 result = os.path.join(*result)
198@@ -166,6 +165,27 @@
199 result = LONG_PATH_PREFIX + result
200 return unicode(result)
201
202+
203+def is_illegal_path(path):
204+ """Return if the path is illegal in the system."""
205+ return _contains_chars(path, WINDOWS_ILLEGAL_CHARS_MAP)
206+
207+
208+def remove_windows_illegal_chars(path):
209+ """Remove illegal chars and return a valid windows path."""
210+ return _modify_chars(path, is_illegal_path, WINDOWS_ILLEGAL_CHARS_MAP)
211+
212+
213+def is_modified_path(path):
214+ """Return if the path contains the special utf8 chars."""
215+ return _contains_chars(path, LINUX_ILLEGAL_CHARS_MAP)
216+
217+
218+def remove_utf8_chars(path):
219+ """Remove the special chars from the path and use the basic ones."""
220+ return _modify_chars(path, is_modified_path, LINUX_ILLEGAL_CHARS_MAP)
221+
222+
223 def _set_file_attributes(path, groups):
224 """Set file attributes using the wind32api."""
225 security_descriptor = None
226@@ -176,7 +196,7 @@
227 'for path %s', path, groups)
228 #check if the issue was due to an illegal path
229 if getattr(e, "winerror", None) == 123:
230- path = _remove_windows_illegal_chars(path)
231+ path = remove_windows_illegal_chars(path)
232 return _set_file_attributes(path, groups)
233 else:
234 raise
235@@ -358,8 +378,8 @@
236 @longpath(paths_indexes=[0])
237 def path_exists(path):
238 """Return if the path exists."""
239- if _is_illegal_path(path):
240- path = _remove_windows_illegal_chars(path)
241+ if is_illegal_path(path):
242+ path = remove_windows_illegal_chars(path)
243 return os.path.exists(path)
244
245
246@@ -409,8 +429,8 @@
247 '%s to %s', path_from, path_to)
248 #check if the issue was due to an illegal path
249 if getattr(e, "winerror", None) == 123:
250- path_from = _remove_windows_illegal_chars(path_from)
251- path_to = _remove_windows_illegal_chars(path_to)
252+ path_from = remove_windows_illegal_chars(path_from)
253+ path_to = remove_windows_illegal_chars(path_to)
254 try:
255 MoveFileExW(
256 path_from, path_to,
257@@ -489,8 +509,8 @@
258 # since that will only occur in the case where the user created the path
259 # for a file to be readable it has to be readable either by the user or
260 # by the everyone group
261- if _is_illegal_path(path):
262- path = _remove_windows_illegal_chars(path)
263+ if is_illegal_path(path):
264+ path = remove_windows_illegal_chars(path)
265 if not os.path.exists(path):
266 return False
267 security_descriptor = GetFileSecurity(path, DACL_SECURITY_INFORMATION)
268@@ -588,7 +608,7 @@
269 """Return an abspath."""
270 # TODO: do we really need to do this, are the tests broken?
271 path = path.replace('/', '\\')
272- abs = os.path.abspath(_remove_windows_illegal_chars(path))
273+ abs = os.path.abspath(remove_windows_illegal_chars(path))
274 if not LONG_PATH_PREFIX in abs:
275 abs = LONG_PATH_PREFIX + abs
276 return abs
277\ No newline at end of file

Subscribers

People subscribed via source and target branches