From 6856e49f2d926da905f4aca507f5dae8bd548c56 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 6 Apr 2010 18:55:30 +0200 Subject: [PATCH] Added the plat_other module (for Linux). --- send2trash/__init__.py | 2 +- send2trash/plat_other.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 send2trash/plat_other.py diff --git a/send2trash/__init__.py b/send2trash/__init__.py index 00c63af..e0dbe9a 100644 --- a/send2trash/__init__.py +++ b/send2trash/__init__.py @@ -5,4 +5,4 @@ if sys.platform == 'darwin': elif sys.platform == 'win32': from plat_win import send2trash else: - print "Unsupported platform" + from plat_other import send2trash diff --git a/send2trash/plat_other.py b/send2trash/plat_other.py new file mode 100644 index 0000000..5a681f5 --- /dev/null +++ b/send2trash/plat_other.py @@ -0,0 +1,21 @@ +from __future__ import unicode_literals +import sys +import os +import os.path as op + +TRASH_PATH = op.expanduser('~/.Trash') + +# XXX Make this work on external volumes + +def send2trash(path): + if not isinstance(path, unicode): + path = unicode(path, sys.getfilesystemencoding()) + filename = op.basename(path) + destpath = op.join(TRASH_PATH, filename) + counter = 0 + while op.exists(destpath): + counter += 1 + base_name, ext = op.splitext(filename) + new_filename = '{0} {1}{2}'.format(base_name, counter, ext) + destpath = op.join(TRASH_PATH, new_filename) + os.rename(path, destpath)