Merge lp:~mandel/ubuntuone-client/better-encoding into lp:ubuntuone-client

Proposed by Manuel de la Peña on 2012-06-22
Status: Merged
Approved by: Alejandro J. Cura on 2012-06-26
Approved revision: 1266
Merged at revision: 1266
Proposed branch: lp:~mandel/ubuntuone-client/better-encoding
Merge into: lp:ubuntuone-client
Diff against target: 167 lines (+90/-10)
3 files modified
tests/platform/os_helper/test_darwin.py (+64/-7)
ubuntuone/platform/os_helper/darwin.py (+25/-3)
ubuntuone/platform/os_helper/unix.py (+1/-0)
To merge this branch: bzr merge lp:~mandel/ubuntuone-client/better-encoding
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve on 2012-06-26
Diego Sarmentero (community) 2012-06-22 Approve on 2012-06-22
Review via email: mp+111580@code.launchpad.net

Commit Message

- Removed test that makes no sense (LP: #1016459).
- Implement the os_helper methods that return file names to the sd so that they use the correct encoding (LP: #1015672).

Description of the Change

- Removed test that makes no sense (LP: #1016459).
- Implement the os_helper methods that return file names to the sd so that they use the correct encoding (LP: #1015672).

To post a comment you must log in.
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
dobey (dobey) wrote :

136 + return unicodedata.normalize('NFC', unicode(path, 'utf-8')).encode('utf-8')

I think this probably needs to be path.decode('utf-8') instead of using unicode(), just to make life a little easier, one line at a time, when we have to make it work on Python 3.x. :)

Alejandro J. Cura (alecu) wrote :

_build_invalid_darwin_path_name should be a constant instead.

Otherwise the branch looks ok.

review: Needs Fixing
Alejandro J. Cura (alecu) wrote :

+1

review: Approve
Alejandro J. Cura (alecu) wrote :

== Python Lint Notices ==

./tests/platform/os_helper/test_darwin.py:
    40: 'set_application_name' imported but unused

review: Needs Fixing
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (24.9 KiB)

The attempt to merge lp:~mandel/ubuntuone-client/better-encoding into lp:ubuntuone-client failed. Below is the output from the failed tests.

/usr/bin/gnome-autogen.sh
checking for autoconf >= 2.53...
  testing autoconf2.50... not found.
  testing autoconf... found 2.69
checking for automake >= 1.10...
  testing automake-1.11... found 1.11.5
checking for libtool >= 1.5...
  testing libtoolize... found 2.4.2
checking for intltool >= 0.30...
  testing intltoolize... found 0.50.2
checking for pkg-config >= 0.14.0...
  testing pkg-config... found 0.26
checking for gtk-doc >= 1.0...
  testing gtkdocize... found 1.18
Checking for required M4 macros...
Checking for forbidden M4 macros...
Processing ./configure.ac
Running libtoolize...
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
Running intltoolize...
Running gtkdocize...
Running aclocal-1.11...
Running autoconf...
Running autoheader...
Running automake-1.11...
Running ./configure --enable-gtk-doc --enable-debug ...
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking for library containing strerror... none required
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking dependency style of gcc... (cached) gcc3
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
ch...

1266. By Manuel de la Peña on 2012-06-26

Fix lint issue.

Alejandro J. Cura (alecu) 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/os_helper/test_darwin.py'
2--- tests/platform/os_helper/test_darwin.py 2012-05-17 12:23:12 +0000
3+++ tests/platform/os_helper/test_darwin.py 2012-06-26 10:58:37 +0000
4@@ -1,3 +1,4 @@
5+# -*- encoding: utf-8 -*-
6 # tests.platform.os_helper - darwin platform tests
7 #
8 # Copyright 2012 Canonical Ltd.
9@@ -39,18 +40,22 @@
10 from ubuntuone.platform import (
11 move_to_trash,
12 open_file,
13- set_application_name,
14 stat_path,
15 )
16
17+DARWIN_TEST_FILE_NAME = u'naïve_test_file'
18+
19
20 class OSWrapperTests(test_os_helper.OSWrapperTests):
21 """Tests for os wrapper functions."""
22
23 @defer.inlineCallbacks
24- def setUp(self):
25+ def setUp(self, test_dir_name=None, test_file_name=None,
26+ valid_file_path_builder=None):
27 """Set up."""
28- yield super(OSWrapperTests, self).setUp()
29+ yield super(OSWrapperTests, self).setUp(
30+ test_dir_name=test_dir_name, test_file_name=test_file_name,
31+ valid_file_path_builder=None)
32 self.handler = MementoHandler()
33 self.handler.setLevel(logging.DEBUG)
34 self._logger = logging.getLogger('ubuntuone.SyncDaemon')
35@@ -74,10 +79,6 @@
36 self.assertNotEqual(os.stat(link).st_ino, stat_path(link).st_ino)
37 self.assertEqual(os.lstat(link).st_ino, stat_path(link).st_ino)
38
39- def test_set_application_name(self):
40- """Check that the implementation of set_application_name fails."""
41- self.assertRaises(Exception, set_application_name, "test")
42-
43 def test_movetotrash_file_bad(self):
44 """Something bad happen when moving to trash, removed anyway."""
45 path = os.path.join(self.basedir, 'foo')
46@@ -102,3 +103,59 @@
47 self.assertFalse(os.path.exists(path))
48 self.assertTrue(self.handler.check_warning("Problems moving to trash!",
49 "Removing anyway", "foo"))
50+
51+
52+class TestIllegalPaths(OSWrapperTests):
53+ """Test all the operations using illegal paths."""
54+
55+ @defer.inlineCallbacks
56+ def setUp(self, test_dir_name=None, test_file_name=None,
57+ valid_file_path_builder=None):
58+ """Set up for the tests."""
59+ test_file_name = DARWIN_TEST_FILE_NAME
60+ yield super(TestIllegalPaths, self).setUp(
61+ test_dir_name=test_dir_name, test_file_name=test_file_name)
62+
63+ def test_listdir(self, expected_result=None):
64+ """Return a list of the files in a dir."""
65+ _, valid_path_name = os.path.split(self.valid_path)
66+ expected_result = [valid_path_name.encode('utf-8')]
67+ super(TestIllegalPaths, self).test_listdir(expected_result)
68+
69+ def _assert_read_link(self, target):
70+ """Assert if the target path of the link is correct."""
71+ destination = os.path.join(self.basedir, target)
72+ darwin.make_link(self.testfile, destination)
73+
74+ target = darwin.read_link(destination)
75+ self.assertEqual(self.testfile.encode('utf-8'), target)
76+
77+ def test_make_link(self):
78+ """The link is properly made."""
79+ destination = os.path.join(self.basedir, 'destination')
80+ darwin.make_link(self.testfile, destination)
81+
82+ self.assertTrue(darwin.is_link(destination))
83+ self.assertEqual(self.testfile.encode('utf-8'),
84+ darwin.read_link(destination))
85+
86+
87+class TestIllegalPathsWalk(test_os_helper.WalkTests):
88+ """Tests for os wrapper functions."""
89+
90+ @defer.inlineCallbacks
91+ def setUp(self, test_dir_name=None, test_file_name=None,
92+ valid_file_path_builder=None, valid_file_name_builder=None):
93+ """Setup for the tests."""
94+ test_file_name = DARWIN_TEST_FILE_NAME
95+ yield super(TestIllegalPathsWalk, self).setUp(
96+ test_dir_name=test_dir_name, test_file_name=test_file_name)
97+
98+ def test_top_down(self, topdown=True, expected=None):
99+ """Walk the tree top-down."""
100+ result = os.walk(self.basedir, topdown)
101+ expected = self._build_dict_from_walk(result,
102+ path_transformer=darwin.get_syncdaemon_valid_path,
103+ name_transformer=darwin.get_syncdaemon_valid_path)
104+ super(TestIllegalPathsWalk, self).test_top_down(topdown=topdown,
105+ expected=expected)
106
107=== modified file 'ubuntuone/platform/os_helper/darwin.py'
108--- ubuntuone/platform/os_helper/darwin.py 2012-06-19 14:57:19 +0000
109+++ ubuntuone/platform/os_helper/darwin.py 2012-06-26 10:58:37 +0000
110@@ -37,6 +37,7 @@
111 import logging
112 import os
113 import shutil
114+import unicodedata
115
116 from ubuntuone.platform.os_helper import unix
117
118@@ -61,11 +62,8 @@
119 native_rename = unix.native_rename
120 recursive_move = unix.recursive_move
121 make_link = unix.make_link
122-read_link = unix.read_link
123 is_link = unix.is_link
124 remove_link = unix.remove_link
125-listdir = unix.listdir
126-walk = unix.walk
127 access = unix.access
128 can_write = unix.can_write
129 stat_path = unix.stat_path
130@@ -108,3 +106,27 @@
131 def set_application_name(app_name):
132 """Set the name of the application."""
133 # nothing to be done let the plist take care of it
134+
135+def get_syncdaemon_valid_path(path):
136+ """Get a 'darwin' path and modify it so that it can be used in sd."""
137+ return unicodedata.normalize('NFC', path.decode('utf-8')).encode('utf-8')
138+
139+
140+def read_link(path):
141+ """Read the destination of a link."""
142+ destination = os.readlink(path)
143+ return get_syncdaemon_valid_path(destination)
144+
145+
146+def listdir(directory):
147+ """List a directory."""
148+ return map(get_syncdaemon_valid_path, os.listdir(directory))
149+
150+
151+def walk(path, topdown=True):
152+ """Walk a dir."""
153+ for dirpath, dirnames, filenames in os.walk(path, topdown):
154+ dirpath = get_syncdaemon_valid_path(dirpath)
155+ dirnames = map(get_syncdaemon_valid_path, dirnames)
156+ filenames = map(get_syncdaemon_valid_path, filenames)
157+ yield dirpath, dirnames, filenames
158
159=== modified file 'ubuntuone/platform/os_helper/unix.py'
160--- ubuntuone/platform/os_helper/unix.py 2012-05-17 11:57:49 +0000
161+++ ubuntuone/platform/os_helper/unix.py 2012-06-26 10:58:37 +0000
162@@ -153,6 +153,7 @@
163
164
165 def walk(path, topdown=True):
166+ """Walk a dir."""
167 return os.walk(path, topdown)
168
169

Subscribers

People subscribed via source and target branches