plat_gio.py 752 B

12345678910111213141516171819
  1. # Copyright 2017 Virgil Dupras
  2. # This software is licensed under the "BSD" License as described in the "LICENSE" file,
  3. # which should be included with this package. The terms are also available at
  4. # http://www.hardcoded.net/licenses/bsd_license
  5. from gi.repository import GObject, Gio
  6. from .exceptions import TrashPermissionError
  7. def send2trash(path):
  8. try:
  9. f = Gio.File.new_for_path(path)
  10. f.trash(cancellable=None)
  11. except GObject.GError as e:
  12. if e.code == Gio.IOErrorEnum.NOT_SUPPORTED:
  13. # We get here if we can't create a trash directory on the same
  14. # device. I don't know if other errors can result in NOT_SUPPORTED.
  15. raise TrashPermissionError('')
  16. raise OSError(e.message)