5 # http://www.hardcoded.net/licenses/bsd_license |
5 # http://www.hardcoded.net/licenses/bsd_license |
6 |
6 |
7 from __future__ import unicode_literals |
7 from __future__ import unicode_literals |
8 |
8 |
9 from gi.repository import GObject, Gio |
9 from gi.repository import GObject, Gio |
|
10 from .exceptions import TrashPermissionError |
10 |
11 |
11 def send2trash(path): |
12 def send2trash(path): |
12 try: |
13 try: |
13 f = Gio.File.new_for_path(path) |
14 f = Gio.File.new_for_path(path) |
14 f.trash(cancellable=None) |
15 f.trash(cancellable=None) |
15 except GObject.GError as e: |
16 except GObject.GError as e: |
|
17 if e.code == Gio.IOErrorEnum.NOT_SUPPORTED: |
|
18 # We get here if we can't create a trash directory on the same |
|
19 # device. I don't know if other errors can result in NOT_SUPPORTED. |
|
20 raise TrashPermissionError('') |
16 raise OSError(e.message) |
21 raise OSError(e.message) |