|
1 # Copyright 2017 Virgil Dupras |
|
2 |
|
3 # This software is licensed under the "BSD" License as described in the "LICENSE" file, |
|
4 # which should be included with this package. The terms are also available at |
|
5 # http://www.hardcoded.net/licenses/bsd_license |
|
6 |
|
7 from __future__ import unicode_literals |
|
8 |
|
9 from gi.repository import GObject, Gio |
|
10 from .exceptions import TrashPermissionError |
|
11 |
|
12 def send2trash(path): |
|
13 try: |
|
14 f = Gio.File.new_for_path(path) |
|
15 f.trash(cancellable=None) |
|
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('') |
|
21 raise OSError(e.message) |