Merge lp:~nataliabidart/ubuntuone-client/fix-807235 into lp:ubuntuone-client

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 1047
Merged at revision: 1047
Proposed branch: lp:~nataliabidart/ubuntuone-client/fix-807235
Merge into: lp:ubuntuone-client
Diff against target: 466 lines (+92/-143)
8 files modified
tests/platform/linux/test_vm.py (+1/-26)
tests/platform/windows/test_vm_helper.py (+3/-26)
tests/syncdaemon/test_vm.py (+44/-17)
ubuntuone/platform/linux/__init__.py (+0/-1)
ubuntuone/platform/linux/vm_helper.py (+0/-32)
ubuntuone/platform/windows/__init__.py (+0/-1)
ubuntuone/platform/windows/vm_helper.py (+1/-32)
ubuntuone/syncdaemon/volume_manager.py (+43/-8)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-client/fix-807235
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve
Roberto Alsina (community) code review only Approve
Review via email: mp+67320@code.launchpad.net

Commit message

- Renamed 'get_share_path' to 'get_share_dir_name' and unified the implementation between the platforms (LP: #807235).

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

+1

review: Approve (code review only)
Revision history for this message
Manuel de la Peña (mandel) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/platform/linux/test_vm.py'
2--- tests/platform/linux/test_vm.py 2011-06-15 14:46:04 +0000
3+++ tests/platform/linux/test_vm.py 2011-07-08 12:29:23 +0000
4@@ -26,7 +26,7 @@
5 LegacyShareFileShelf, _Share, Share, Shared, Root, UDF, _UDF,
6 MetadataUpgrader, VMFileShelf,
7 )
8-from ubuntuone.platform.linux import get_udf_path, get_share_path
9+from ubuntuone.platform.linux import get_udf_path
10
11
12 class VolumesTests(BaseVolumeManagerTests):
13@@ -41,31 +41,6 @@
14 suggested_path.encode('utf-8')),
15 udf_path)
16
17- def test_get_share_path(self):
18- """Test for get_share_path."""
19- share_id = uuid.uuid4()
20- name = 'The little pretty share'
21- other_name = 'Dorian Grey'
22- share = self._create_share_volume(volume_id=share_id, name=name,
23- other_visible_name=other_name)
24- result = get_share_path(share)
25-
26- expected = '%s (%s, %s)' % (name, other_name, share_id)
27- self.assertEqual(result, expected)
28-
29- def test_get_share_path_visible_name_empty(self):
30- """Test for get_share_path."""
31- share_id = uuid.uuid4()
32- name = 'The little pretty share'
33- other_name = ''
34- share = self._create_share_volume(volume_id=share_id, name=name,
35- other_visible_name=other_name)
36- result = get_share_path(share)
37-
38- expected = '%s (%s)' % (name, share_id)
39- self.assertEqual(result, expected)
40-
41-
42 class MetadataOldLayoutTests(MetadataTestCase):
43 """Tests for 'old' layouts and metadata upgrade"""
44
45
46=== modified file 'tests/platform/windows/test_vm_helper.py'
47--- tests/platform/windows/test_vm_helper.py 2011-06-15 09:41:04 +0000
48+++ tests/platform/windows/test_vm_helper.py 2011-07-08 12:29:23 +0000
49@@ -18,7 +18,7 @@
50 """Windows specific tests for vm_helper."""
51
52 import os
53-import uuid
54+
55 from mocker import Mocker
56
57 from contrib.testing.testcase import environ
58@@ -26,7 +26,8 @@
59
60 from ubuntuone.platform.windows.os_helper import LONG_PATH_PREFIX
61 from ubuntuone.platform.windows.vm_helper import (
62- create_shares_link, get_udf_path, get_udf_path_name, get_share_path)
63+ create_shares_link, get_udf_path, get_udf_path_name,
64+)
65
66
67 class VMHelperTest(BaseVolumeManagerTests):
68@@ -77,27 +78,3 @@
69 self.assertTrue(LONG_PATH_PREFIX in udf_path)
70 self.assertFalse('/' in udf_path)
71 self.mocker.verify()
72-
73- def test_get_share_path(self):
74- """Test for get_share_path."""
75- share_id = uuid.uuid4()
76- name = 'The little pretty share'
77- other_name = 'Dorian Grey'
78- share = self._create_share_volume(volume_id=share_id, name=name,
79- other_visible_name=other_name)
80- result = get_share_path(share)
81-
82- expected = '%s (%s, %s)' % (name, other_name, share_id)
83- self.assertEqual(result, expected)
84-
85- def test_get_share_path_visible_name_empty(self):
86- """Test for get_share_path."""
87- share_id = uuid.uuid4()
88- name = 'The little pretty share'
89- other_name = ''
90- share = self._create_share_volume(volume_id=share_id, name=name,
91- other_visible_name=other_name)
92- result = get_share_path(share)
93-
94- expected = '%s (%s)' % (name, share_id)
95- self.assertEqual(result, expected)
96
97=== modified file 'tests/syncdaemon/test_vm.py'
98--- tests/syncdaemon/test_vm.py 2011-06-30 16:01:16 +0000
99+++ tests/syncdaemon/test_vm.py 2011-07-08 12:29:23 +0000
100@@ -28,19 +28,20 @@
101 import uuid
102
103 from mocker import Mocker, MATCH
104+from twisted.internet import defer, reactor
105
106-from ubuntuone.storageprotocol.client import ListShares
107-from ubuntuone.storageprotocol.sharersp import (
108- NotifyShareHolder,
109- ShareResponse,
110-)
111-from ubuntuone.storageprotocol import volumes, request
112 from contrib.testing.testcase import (
113 FakeMain,
114 BaseTwistedTestCase,
115 environ,
116 )
117 from ubuntuone.devtools.handlers import MementoHandler
118+from ubuntuone.storageprotocol import volumes, request
119+from ubuntuone.storageprotocol.client import ListShares
120+from ubuntuone.storageprotocol.sharersp import (
121+ NotifyShareHolder,
122+ ShareResponse,
123+)
124 from ubuntuone.syncdaemon import config, event_queue, tritcask
125 from ubuntuone.syncdaemon.volume_manager import (
126 Share,
127@@ -49,6 +50,7 @@
128 Root,
129 _Share,
130 allow_writes,
131+ get_share_dir_name,
132 VolumeManager,
133 LegacyShareFileShelf,
134 MetadataUpgrader,
135@@ -59,11 +61,10 @@
136 from ubuntuone.platform import (
137 abspath,
138 get_udf_path,
139- get_share_path,
140 make_link,
141 make_dir,
142- remove_link)
143-from twisted.internet import defer, reactor
144+ remove_link,
145+)
146
147 # grab the metadata version before tests fiddle with it
148 CURRENT_METADATA_VERSION = VolumeManager.METADATA_VERSION
149@@ -179,7 +180,7 @@
150 node_id=node_id, name=name, generation=generation,
151 free_bytes=free_bytes, access_level=access_level,
152 accepted=accepted, other_visible_name=other_visible_name)
153- dir_name = get_share_path(share_volume)
154+ dir_name = get_share_dir_name(share_volume)
155 share_path = os.path.join(self.shares_dir, dir_name)
156 share = Share.from_share_volume(share_volume, share_path)
157 share.subscribed = subscribed
158@@ -187,6 +188,33 @@
159 return share
160
161
162+class GetShareDirNameTests(BaseVolumeManagerTests):
163+
164+ def test_get_share_dir_name(self):
165+ """Test for get_share_dir_name."""
166+ share_id = uuid.uuid4()
167+ name = 'The little pretty share'
168+ other_name = 'Dorian Grey'
169+ share = self._create_share_volume(volume_id=share_id, name=name,
170+ other_visible_name=other_name)
171+ result = get_share_dir_name(share)
172+
173+ expected = '%s (%s, %s)' % (name, other_name, share_id)
174+ self.assertEqual(result, expected)
175+
176+ def test_get_share_dir_name_visible_name_empty(self):
177+ """Test for get_share_dir_name."""
178+ share_id = uuid.uuid4()
179+ name = 'The little pretty share'
180+ other_name = ''
181+ share = self._create_share_volume(volume_id=share_id, name=name,
182+ other_visible_name=other_name)
183+ result = get_share_dir_name(share)
184+
185+ expected = '%s (%s)' % (name, share_id)
186+ self.assertEqual(result, expected)
187+
188+
189 class VolumeManagerTests(BaseVolumeManagerTests):
190 """ Tests for Volume Manager internal API. """
191
192@@ -253,7 +281,7 @@
193 share = self._create_share(access_level='View', subscribed=False)
194 yield self.vm.add_share(share)
195
196- dir_name = get_share_path(share)
197+ dir_name = get_share_dir_name(share)
198 share_path = os.path.join(self.shares_dir, dir_name)
199 self.assertEqual(share_path, share.path)
200 self.assertEqual(2, len(self.vm.shares)) # root and share
201@@ -292,7 +320,7 @@
202 share = self._create_share(access_level='Modify', subscribed=False)
203 yield self.vm.add_share(share)
204
205- dir_name = get_share_path(share)
206+ dir_name = get_share_dir_name(share)
207 share_path = os.path.join(self.shares_dir, dir_name)
208 self.assertEqual(share_path, share.path)
209 self.assertEqual(2, len(self.vm.shares)) # root and share
210@@ -1263,7 +1291,7 @@
211 # check
212 share = self.vm.shares['share_id']
213 shouldbe_dir = os.path.join(self.shares_dir,
214- get_share_path(share_response))
215+ get_share_dir_name(share_response))
216 self.assertEquals(abspath(shouldbe_dir), share.path)
217
218 def test_handle_SHARES_visible_username(self):
219@@ -1282,7 +1310,7 @@
220 # check
221 share = self.vm.shares['share_id']
222 shouldbe_dir = os.path.join(self.shares_dir,
223- get_share_path(share_response))
224+ get_share_dir_name(share_response))
225 self.assertEquals(abspath(shouldbe_dir), share.path)
226
227 def test_handle_SV_SHARE_CHANGED_sharename(self):
228@@ -1294,7 +1322,7 @@
229 self.vm._got_root('root_uuid')
230 self.vm.handle_SV_SHARE_CHANGED(info=share_holder)
231 shouldbe_dir = os.path.join(self.shares_dir,
232- get_share_path(share_holder))
233+ get_share_dir_name(share_holder))
234 self.assertEquals(abspath(shouldbe_dir),
235 abspath(self.vm.shares['share_id'].path))
236
237@@ -1307,7 +1335,7 @@
238 self.vm._got_root('root_uuid')
239 self.vm.handle_SV_SHARE_CHANGED(info=share_holder)
240 shouldbe_dir = os.path.join(self.shares_dir,
241- get_share_path(share_holder))
242+ get_share_dir_name(share_holder))
243 self.assertEquals(abspath(shouldbe_dir),
244 abspath(self.vm.shares['share_id'].path))
245
246@@ -3908,4 +3936,3 @@
247 self.assertEqual(self.shelf._root_key,
248 self.shelf._get_key(request.ROOT))
249 self.assertEqual('foo', self.shelf._get_key('foo'))
250-
251
252=== modified file 'ubuntuone/platform/linux/__init__.py'
253--- ubuntuone/platform/linux/__init__.py 2011-06-29 17:09:32 +0000
254+++ ubuntuone/platform/linux/__init__.py 2011-07-08 12:29:23 +0000
255@@ -57,7 +57,6 @@
256 )
257 from ubuntuone.platform.linux.vm_helper import (
258 create_shares_link,
259- get_share_path,
260 get_udf_path_name,
261 get_udf_path,
262 )
263
264=== modified file 'ubuntuone/platform/linux/vm_helper.py'
265--- ubuntuone/platform/linux/vm_helper.py 2011-06-28 21:23:19 +0000
266+++ ubuntuone/platform/linux/vm_helper.py 2011-07-08 12:29:23 +0000
267@@ -69,35 +69,3 @@
268 # Unicode boundary! the name is Unicode in protocol and server,
269 # but here we use bytes for paths
270 return os.path.expanduser(suggested_path).encode("utf8")
271-
272-
273-def get_share_path(share):
274- """Builds the root path of a share using the share information."""
275- if hasattr(share, 'volume_id'):
276- share_id = share.volume_id
277- elif hasattr(share, 'share_id'):
278- share_id = share.share_id
279- else:
280- share_id = share.id
281-
282- if hasattr(share, 'name'):
283- share_name = share.name
284- else:
285- share_name = share.share_name
286-
287- if hasattr(share, 'other_visible_name'):
288- visible_name = share.other_visible_name
289- else:
290- visible_name = share.from_visible_name
291-
292- if visible_name:
293- dir_name = '%s (%s, %s)' % (share_name, visible_name, share_id)
294- else:
295- dir_name = '%s (%s)' % (share_name, share_id)
296-
297- # Unicode boundary! the name is Unicode in protocol and server,
298- # but here we use bytes for paths
299- dir_name = dir_name.encode("utf8")
300-
301- return dir_name
302-
303
304=== modified file 'ubuntuone/platform/windows/__init__.py'
305--- ubuntuone/platform/windows/__init__.py 2011-06-30 20:57:41 +0000
306+++ ubuntuone/platform/windows/__init__.py 2011-07-08 12:29:23 +0000
307@@ -27,7 +27,6 @@
308 from ubuntuone.platform.windows.vm_helper import (
309 get_udf_path_name,
310 get_udf_path,
311- get_share_path,
312 create_shares_link
313 )
314
315
316=== modified file 'ubuntuone/platform/windows/vm_helper.py'
317--- ubuntuone/platform/windows/vm_helper.py 2011-06-17 16:59:53 +0000
318+++ ubuntuone/platform/windows/vm_helper.py 2011-07-08 12:29:23 +0000
319@@ -21,7 +21,7 @@
320 from ubuntuone.platform.windows.os_helper import (
321 LONG_PATH_PREFIX,
322 make_link,
323- abspath)
324+)
325
326 def create_shares_link(source, dest):
327 """Create the shares symlink."""
328@@ -69,34 +69,3 @@
329 """Build the udf path using the suggested_path."""
330 path = suggested_path.replace('/', '\\')
331 return LONG_PATH_PREFIX + os.path.expanduser(path).encode("utf8")
332-
333-
334-def get_share_path(share):
335- """Builds the root path of a share using the share information."""
336- if hasattr(share, 'volume_id'):
337- share_id = share.volume_id
338- elif hasattr(share, 'share_id'):
339- share_id = share.share_id
340- else:
341- share_id = share.id
342-
343- if hasattr(share, 'name'):
344- share_name = share.name
345- else:
346- share_name = share.share_name
347-
348- if hasattr(share, 'other_visible_name'):
349- visible_name = share.other_visible_name
350- else:
351- visible_name = share.from_visible_name
352-
353- if visible_name:
354- dir_name = '%s (%s, %s)' % (share_name, visible_name, share_id)
355- else:
356- dir_name = '%s (%s)' % (share_name, share_id)
357-
358- # Unicode boundary! the name is Unicode in protocol and server,
359- # but here we use bytes for paths
360- dir_name = dir_name.encode("utf8")
361-
362- return abspath(dir_name)
363
364=== modified file 'ubuntuone/syncdaemon/volume_manager.py'
365--- ubuntuone/syncdaemon/volume_manager.py 2011-06-30 19:26:53 +0000
366+++ ubuntuone/syncdaemon/volume_manager.py 2011-07-08 12:29:23 +0000
367@@ -46,7 +46,6 @@
368 expanduser,
369 get_path_list,
370 get_udf_path,
371- get_share_path,
372 get_udf_path_name,
373 is_link,
374 listdir,
375@@ -69,6 +68,41 @@
376 UDF_ROW_TYPE = 5
377
378
379+def get_share_dir_name(share):
380+ """Builds the directory name of a share using the share information.
381+
382+ This method is not platform dependent, so do not override in platform.
383+
384+ """
385+ if hasattr(share, 'volume_id'):
386+ share_id = share.volume_id
387+ elif hasattr(share, 'share_id'):
388+ share_id = share.share_id
389+ else:
390+ share_id = share.id
391+
392+ if hasattr(share, 'name'):
393+ share_name = share.name
394+ else:
395+ share_name = share.share_name
396+
397+ if hasattr(share, 'other_visible_name'):
398+ visible_name = share.other_visible_name
399+ else:
400+ visible_name = share.from_visible_name
401+
402+ if visible_name:
403+ dir_name = '%s (%s, %s)' % (share_name, visible_name, share_id)
404+ else:
405+ dir_name = '%s (%s)' % (share_name, share_id)
406+
407+ # Unicode boundary! the name is Unicode in protocol and server,
408+ # but here we use bytes for paths
409+ dir_name = dir_name.encode("utf8")
410+
411+ return dir_name
412+
413+
414 class _Share(object):
415 """Represents a share or mount point"""
416
417@@ -632,7 +666,7 @@
418 """
419 self.log.debug('_handle_new_volume: volume %r.', volume)
420 if isinstance(volume, ShareVolume):
421- dir_name = get_share_path(volume)
422+ dir_name = get_share_dir_name(volume)
423 path = os.path.join(self.m.shares_dir, dir_name)
424 share = Share.from_share_volume(volume, path)
425 autosubscribe = config.get_user_config().get_share_autosubscribe()
426@@ -668,7 +702,7 @@
427 self.log.debug('share %r: id=%s, name=%r', a_share.direction,
428 share_id, a_share.name)
429 if a_share.direction == "to_me":
430- dir_name = get_share_path(a_share)
431+ dir_name = get_share_dir_name(a_share)
432 path = os.path.join(self.m.shares_dir, dir_name)
433 share = Share.from_response(a_share, path)
434 shares.append(share.volume_id)
435@@ -750,7 +784,7 @@
436 self.log.debug("New share notification, share_id: %s",
437 info.share_id)
438 # XXX: request a refresh of the shares list(?)
439- dir_name = get_share_path(info)
440+ dir_name = get_share_dir_name(info)
441 path = os.path.join(self.m.shares_dir, dir_name)
442 share = Share.from_notify_holder(info, path)
443 self.add_share(share)
444@@ -1797,9 +1831,11 @@
445 shutil.rmtree(self._shared_md_dir)
446 shutil.rmtree(self._udfs_md_dir)
447
448+
449 class VMFileShelf(file_shelf.CachedFileShelf):
450- """Custom file shelf that allow request.ROOT as key, it's replaced
451- by the string: root_node_id.
452+ """Custom file shelf.
453+
454+ Allow request.ROOT as key, it's replaced by the string: root_node_id.
455
456 """
457
458@@ -1846,8 +1882,7 @@
459
460
461 class LegacyShareFileShelf(VMFileShelf):
462- """A FileShelf capable of replacing pickled classes
463- with a different class.
464+ """A FileShelf capable of replacing pickled classes with a different class.
465
466 upgrade_map attribute is a dict of (module, name):class
467

Subscribers

People subscribed via source and target branches