Merge lp:~facundo/magicicada-client/new-trash into lp:magicicada-client

Proposed by Facundo Batista
Status: Merged
Approved by: Natalia Bidart
Approved revision: 1442
Merged at revision: 1441
Proposed branch: lp:~facundo/magicicada-client/new-trash
Merge into: lp:magicicada-client
Diff against target: 293 lines (+55/-114)
7 files modified
Makefile (+6/-3)
dependencies-devel.txt (+0/-1)
requirements-devel.txt (+1/-0)
requirements.txt (+1/-0)
run-tests (+1/-9)
ubuntuone/platform/os_helper/linux.py (+17/-29)
ubuntuone/platform/tests/os_helper/test_linux.py (+29/-72)
To merge this branch: bzr merge lp:~facundo/magicicada-client/new-trash
Reviewer Review Type Date Requested Status
Natalia Bidart Approve
Review via email: mp+341764@code.launchpad.net

Commit message

Start using a new way to send to trash, going away from Gnome.

Description of the change

Start using a new way to send to trash, going away from Gnome.

Now we start using a package installed in a virtualenv, so I normalized some stuff around it:

- create it at bootstrap time, not everytime on every make test

- install packages listed in requirements-{devel}.txt, not hardcoded

- pinpointed flake8 in the requirements, and removed it as a system dependency

Also cleaned up the `run-tests` script:

- no more building when running tests, only at bootstrap

- run u1trial from inside the venv

- removed quotes around $MODULE, so we can do now

      ./run-tests -t TestClass.test_foo tests/test_bleh.py
Start using a new way to send to trash, going away from Gnome.

Now we start using a package installed in a virtualenv, so I normalized some stuff around it:

- create it at bootstrap time, not everytime on every make test

- install packages listed in requirements-{devel}.txt, not hardcoded

- pinpointed flake8 in the requirements, and removed it as a system dependency

Also cleaned up the `run-tests` script:

- no more building when running tests, only at bootstrap

- run u1trial from inside the venv

- removed quotes around $MODULE, so we can do now

      ./run-tests -t TestClass.test_foo tests/test_bleh.py

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

Looks great! Thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Makefile'
--- Makefile 2018-03-14 21:55:27 +0000
+++ Makefile 2018-03-20 19:57:57 +0000
@@ -44,16 +44,19 @@
44update-protocol:44update-protocol:
45 cd $(PROTOCOL_DIR) && bzr pull && python setup.py build45 cd $(PROTOCOL_DIR) && bzr pull && python setup.py build
4646
47bootstrap: deps $(PROTOCOL_DIR) $(PROTOCOL_LINK) update-protocol47bootstrap: deps $(PROTOCOL_DIR) $(PROTOCOL_LINK) update-protocol venv
48 $(ENV)/bin/python setup.py build
4849
49docker-bootstrap: clean50docker-bootstrap: clean
50 cat dependencies.txt | xargs apt-get install -y --no-install-recommends51 cat dependencies.txt | xargs apt-get install -y --no-install-recommends
51 cat dependencies-devel.txt | xargs apt-get install -y --no-install-recommends52 cat dependencies-devel.txt | xargs apt-get install -y --no-install-recommends
52 $(MAKE) $(PROTOCOL_DIR) $(PROTOCOL_LINK) update-protocol53 $(MAKE) $(PROTOCOL_DIR) $(PROTOCOL_LINK) update-protocol
5354
55venv:
56 virtualenv --system-site-packages $(ENV)
57 $(ENV)/bin/pip install -r requirements.txt -r requirements-devel.txt
58
54lint:59lint:
55 virtualenv $(ENV)
56 $(ENV)/bin/pip install flake8
57 $(ENV)/bin/flake8 --filename='*.py' --exclude='u1fsfsm.py,test_run_hello.py' ubuntuone60 $(ENV)/bin/flake8 --filename='*.py' --exclude='u1fsfsm.py,test_run_hello.py' ubuntuone
5861
59test: lint62test: lint
6063
=== modified file 'dependencies-devel.txt'
--- dependencies-devel.txt 2016-08-14 19:52:30 +0000
+++ dependencies-devel.txt 2018-03-20 19:57:57 +0000
@@ -1,6 +1,5 @@
1bzr1bzr
2make2make
3python-flake8
4python-mocker3python-mocker
5ubuntuone-dev-tools4ubuntuone-dev-tools
6virtualenv5virtualenv
76
=== added file 'requirements-devel.txt'
--- requirements-devel.txt 1970-01-01 00:00:00 +0000
+++ requirements-devel.txt 2018-03-20 19:57:57 +0000
@@ -0,0 +1,1 @@
1flake8==3.5.0
02
=== added file 'requirements.txt'
--- requirements.txt 1970-01-01 00:00:00 +0000
+++ requirements.txt 2018-03-20 19:57:57 +0000
@@ -0,0 +1,1 @@
1Send2Trash==1.5.0
02
=== modified file 'run-tests'
--- run-tests 2018-03-14 21:01:56 +0000
+++ run-tests 2018-03-20 19:57:57 +0000
@@ -28,10 +28,6 @@
28# version. If you delete this exception statement from all source28# version. If you delete this exception statement from all source
29# files in the program, then also delete it here.29# files in the program, then also delete it here.
3030
31# Allow alternative python executable via environment variable. This is
32# useful for virtualenv testing.
33PYTHON=${PYTHON:-'python'}
34
35set -e31set -e
36if [ $# -ne 0 ]; then32if [ $# -ne 0 ]; then
37 # run specific module given by the caller33 # run specific module given by the caller
@@ -42,7 +38,6 @@
42fi38fi
4339
44SYSNAME=`uname -s`40SYSNAME=`uname -s`
45
46if [ "$SYSNAME" == "Darwin" ]; then41if [ "$SYSNAME" == "Darwin" ]; then
47 IGNORE_FILES="test_linux.py,test_windows.py"42 IGNORE_FILES="test_linux.py,test_windows.py"
48 IGNORE_PATHS="ubuntuone/platform/tests/linux"43 IGNORE_PATHS="ubuntuone/platform/tests/linux"
@@ -54,8 +49,5 @@
5449
55echo "*** Running test suite for ""$MODULE"" ***"50echo "*** Running test suite for ""$MODULE"" ***"
56export SSL_CERTIFICATES_DIR=/etc/ssl/certs51export SSL_CERTIFICATES_DIR=/etc/ssl/certs
57$PYTHON ./setup.py build52.env/bin/python /usr/bin/u1trial -i "$IGNORE_FILES" -p "$IGNORE_PATHS" $MODULE
58u1trial -i "$IGNORE_FILES" -p "$IGNORE_PATHS" "$MODULE"
59$PYTHON ./setup.py clean
60rm -rf _trial_temp53rm -rf _trial_temp
61rm -rf build
6254
=== modified file 'ubuntuone/platform/os_helper/linux.py'
--- ubuntuone/platform/os_helper/linux.py 2013-02-12 23:15:48 +0000
+++ ubuntuone/platform/os_helper/linux.py 2018-03-20 19:57:57 +0000
@@ -31,17 +31,17 @@
31to support the linux platform.31to support the linux platform.
32"""32"""
3333
34import errno
35import logging34import logging
36import os35import os
37import shutil36import shutil
3837
39try:38try:
40 from gi.repository import Gio, GLib39 from gi.repository import GObject
41 has_gi = True40 has_gi = True
42except ImportError:41except ImportError:
43 import gio42 import gobject
44 has_gi = False43 has_gi = False
44from send2trash import send2trash
4545
46from ubuntuone.platform.os_helper import unix46from ubuntuone.platform.os_helper import unix
4747
@@ -50,44 +50,32 @@
50logger = logging.getLogger('ubuntuone.SyncDaemon')50logger = logging.getLogger('ubuntuone.SyncDaemon')
5151
5252
53def _remove_path(path):
54 """Remove the path, no matter if file or dir structure."""
55 if os.path.isdir(path):
56 shutil.rmtree(path)
57 else:
58 os.remove(path)
59
60
53def move_to_trash(path):61def move_to_trash(path):
54 """Move the file or dir to trash.62 """Move the file or dir to trash.
5563
56 If had any error, or the system can't do it, just remove it.64 If had any error, or the system can't do it, just remove it.
57 """65 """
58 if has_gi:66 try:
59 not_supported = Gio.IOErrorEnum.NOT_SUPPORTED67 send2trash(path)
60 try:68 except OSError as exc:
61 return_code = Gio.File.new_for_path(path).trash(None)69 logger.warning(
62 except GLib.GError:70 "Problems moving to trash! (%s) Removing anyway: %r", exc, path)
63 exc = OSError()71 _remove_path(path)
64 exc.errno = errno.ENOENT
65 raise exc
66 else:
67 not_supported = gio.ERROR_NOT_SUPPORTED
68 try:
69 return_code = gio.File(path).trash()
70 except gio.Error:
71 exc = OSError()
72 exc.errno = errno.ENOENT
73 raise exc
74
75 if not return_code or return_code == not_supported:
76 logger.warning("Problems moving to trash! (%s) Removing anyway: %r",
77 return_code, path)
78 if os.path.isdir(path):
79 shutil.rmtree(path)
80 else:
81 os.remove(path)
8272
8373
84def set_application_name(app_name):74def set_application_name(app_name):
85 """Set the name of the application."""75 """Set the name of the application."""
86 if has_gi:76 if has_gi:
87 from gi.repository import GObject
88 GObject.set_application_name(app_name)77 GObject.set_application_name(app_name)
89 else:78 else:
90 import gobject
91 gobject.set_application_name(app_name)79 gobject.set_application_name(app_name)
9280
9381
9482
=== modified file 'ubuntuone/platform/tests/os_helper/test_linux.py'
--- ubuntuone/platform/tests/os_helper/test_linux.py 2016-05-29 19:15:01 +0000
+++ ubuntuone/platform/tests/os_helper/test_linux.py 2018-03-20 19:57:57 +0000
@@ -29,17 +29,11 @@
29import logging29import logging
30import os30import os
3131
32try:
33 from gi.repository import Gio as gio
34 GIO_NOT_SUPPORTED = gio.IOErrorEnum.NOT_SUPPORTED
35except ImportError:
36 import gio
37 GIO_NOT_SUPPORTED = gio.ERROR_NOT_SUPPORTED
38
39from twisted.internet import defer32from twisted.internet import defer
40from ubuntuone.devtools.handlers import MementoHandler33from ubuntuone.devtools.handlers import MementoHandler
4134
42from ubuntuone.platform.tests.os_helper import test_os_helper35from ubuntuone.platform.tests.os_helper import test_os_helper
36from ubuntuone.platform.os_helper import linux
43from ubuntuone.platform import (37from ubuntuone.platform import (
44 move_to_trash,38 move_to_trash,
45 open_file,39 open_file,
@@ -47,24 +41,6 @@
47)41)
4842
4943
50class FakeGIOFile(object):
51 """Fake File for gio."""
52
53 _bad_trash_call = None
54
55 def __init__(self, path):
56 pass
57
58 @classmethod
59 def new_for_path(klass, path):
60 """Fake new_for_path for GI."""
61 return klass(path)
62
63 def trash(self, *args):
64 """Fake trash call."""
65 return self._bad_trash_call
66
67
68class OSWrapperTests(test_os_helper.OSWrapperTests):44class OSWrapperTests(test_os_helper.OSWrapperTests):
69 """Tests for os wrapper functions."""45 """Tests for os wrapper functions."""
7046
@@ -90,50 +66,31 @@
90 self.assertNotEqual(os.stat(link).st_ino, stat_path(link).st_ino)66 self.assertNotEqual(os.stat(link).st_ino, stat_path(link).st_ino)
91 self.assertEqual(os.lstat(link).st_ino, stat_path(link).st_ino)67 self.assertEqual(os.lstat(link).st_ino, stat_path(link).st_ino)
9268
93 def test_movetotrash_file_bad(self):69 def test_movetotrash_bad(self):
94 """Something bad happen when moving to trash, removed anyway."""70 """Something bad happen when moving to trash, removed anyway.
95 FakeGIOFile._bad_trash_call = False # error71
96 self.patch(gio, "File", FakeGIOFile)72 Simulating this as giving a non-existant path to the function, which
97 path = os.path.join(self.basedir, 'foo')73 will make it fail with OSError, which is the exception the send2trash
98 open_file(path, 'w').close()74 library raises on any problem.
99 move_to_trash(path)75 """
100 self.assertFalse(os.path.exists(path))76 called = []
101 self.assertTrue(self.handler.check_warning("Problems moving to trash!",77 self.patch(linux, '_remove_path', lambda p: called.append(p))
102 "Removing anyway", "foo"))78
10379 path = os.path.join(self.basedir, 'non-existant')
104 def test_movetotrash_dir_bad(self):80 move_to_trash(path)
105 """Something bad happen when moving to trash, removed anyway."""81 self.assertEqual(called[0], path)
106 FakeGIOFile._bad_trash_call = False # error82 self.assertTrue(self.handler.check_warning(
107 self.patch(gio, "File", FakeGIOFile)83 "Problems moving to trash!", "Removing anyway", path))
108 path = os.path.join(self.basedir, 'foo')84
109 os.mkdir(path)85 def test_remove_path_file(self):
110 open_file(os.path.join(path, 'file inside directory'), 'w').close()86 path = os.path.join(self.basedir, 'foo')
111 move_to_trash(path)87 open_file(path, 'w').close()
112 self.assertFalse(os.path.exists(path))88 linux._remove_path(path)
113 self.assertTrue(self.handler.check_warning("Problems moving to trash!",89 self.assertFalse(os.path.exists(path))
114 "Removing anyway", "foo"))90
11591 def test_remove_path_dir(self):
116 def test_movetotrash_file_systemnotcapable(self):92 path = os.path.join(self.basedir, 'foo')
117 """The system is not capable of moving into trash."""93 os.mkdir(path)
118 FakeGIOFile._bad_trash_call = GIO_NOT_SUPPORTED94 open_file(os.path.join(path, 'file inside directory'), 'w').close()
119 self.patch(gio, "File", FakeGIOFile)95 linux._remove_path(path)
120 path = os.path.join(self.basedir, 'foo')96 self.assertFalse(os.path.exists(path))
121 open_file(path, 'w').close()
122 move_to_trash(path)
123 self.assertFalse(os.path.exists(path))
124 self.assertTrue(self.handler.check_warning("Problems moving to trash!",
125 "Removing anyway", "foo",
126 "ERROR_NOT_SUPPORTED"))
127
128 def test_movetotrash_dir_systemnotcapable(self):
129 """The system is not capable of moving into trash."""
130 FakeGIOFile._bad_trash_call = GIO_NOT_SUPPORTED
131 self.patch(gio, "File", FakeGIOFile)
132 path = os.path.join(self.basedir, 'foo')
133 os.mkdir(path)
134 open_file(os.path.join(path, 'file inside directory'), 'w').close()
135 move_to_trash(path)
136 self.assertFalse(os.path.exists(path))
137 self.assertTrue(self.handler.check_warning("Problems moving to trash!",
138 "Removing anyway", "foo",
139 "ERROR_NOT_SUPPORTED"))

Subscribers

People subscribed via source and target branches

to all changes: