plat_gio.py 911 B

1234567891011121314151617181920212223
  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 Gio, GLib
  6. from send2trash.exceptions import TrashPermissionError
  7. from send2trash.util import preprocess_paths
  8. def send2trash(paths):
  9. paths = preprocess_paths(paths)
  10. for path in paths:
  11. try:
  12. f = Gio.File.new_for_path(path)
  13. f.trash(cancellable=None)
  14. except GLib.Error as e:
  15. if e.code == Gio.IOErrorEnum.NOT_SUPPORTED:
  16. # We get here if we can't create a trash directory on the same
  17. # device. I don't know if other errors can result in NOT_SUPPORTED.
  18. raise TrashPermissionError("") from e
  19. raise OSError(e.message) from e