From 8a1dff29472b6214e3978d331c87c8a6c7d4d2b8 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 6 Apr 2010 18:04:32 +0200 Subject: [PATCH] Renamed _trash_* modules to _send2trash_* and added python wrapper around them. --HG-- rename : modules/trash_osx.c => modules/send2trash_osx.c rename : modules/trash_win.c => modules/send2trash_win.c --- .hgignore | 1 + modules/{trash_osx.c => send2trash_osx.c} | 8 ++++---- modules/{trash_win.c => send2trash_win.c} | 8 ++++---- send2trash/__init__.py | 8 ++++++++ send2trash/plat_osx.py | 6 ++++++ send2trash/plat_win.py | 9 +++++++++ setup.py | 10 +++++----- 7 files changed, 37 insertions(+), 13 deletions(-) rename modules/{trash_osx.c => send2trash_osx.c} (75%) rename modules/{trash_win.c => send2trash_win.c} (81%) create mode 100644 send2trash/plat_osx.py create mode 100644 send2trash/plat_win.py diff --git a/.hgignore b/.hgignore index 444a474..17c74b6 100644 --- a/.hgignore +++ b/.hgignore @@ -1,4 +1,5 @@ syntax: glob +*.pyc build .DS_Store \ No newline at end of file diff --git a/modules/trash_osx.c b/modules/send2trash_osx.c similarity index 75% rename from modules/trash_osx.c rename to modules/send2trash_osx.c index f14b702..e222ea6 100644 --- a/modules/trash_osx.c +++ b/modules/send2trash_osx.c @@ -2,7 +2,7 @@ #include "Python.h" #include -static PyObject* trash_osx_send(PyObject *self, PyObject *args) +static PyObject* send2trash_osx_send(PyObject *self, PyObject *args) { UInt8 *utf8_chars; FSRef fp; @@ -22,13 +22,13 @@ static PyObject* trash_osx_send(PyObject *self, PyObject *args) } static PyMethodDef TrashMethods[] = { - {"send", trash_osx_send, METH_VARARGS, ""}, + {"send", send2trash_osx_send, METH_VARARGS, ""}, }; PyMODINIT_FUNC -init_trash_osx(void) +init_send2trash_osx(void) { - PyObject *m = Py_InitModule("_trash_osx", TrashMethods); + PyObject *m = Py_InitModule("_send2trash_osx", TrashMethods); if (m == NULL) { return; } diff --git a/modules/trash_win.c b/modules/send2trash_win.c similarity index 81% rename from modules/trash_win.c rename to modules/send2trash_win.c index 2741f36..54f389f 100644 --- a/modules/trash_win.c +++ b/modules/send2trash_win.c @@ -9,7 +9,7 @@ rather than sending it to trash. */ -static PyObject* trash_win_send(PyObject *self, PyObject *args) +static PyObject* send2trash_win_send(PyObject *self, PyObject *args) { SHFILEOPSTRUCTW op; PyObject *filepath; @@ -47,14 +47,14 @@ static PyObject* trash_win_send(PyObject *self, PyObject *args) } static PyMethodDef TrashMethods[] = { - {"send", trash_win_send, METH_VARARGS, ""}, + {"send", send2trash_win_send, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} }; PyMODINIT_FUNC -init_trash_win(void) +init_send2trash_win(void) { - PyObject *m = Py_InitModule("_trash_win", TrashMethods); + PyObject *m = Py_InitModule("_send2trash_win", TrashMethods); if (m == NULL) { return; } diff --git a/send2trash/__init__.py b/send2trash/__init__.py index e69de29..00c63af 100644 --- a/send2trash/__init__.py +++ b/send2trash/__init__.py @@ -0,0 +1,8 @@ +import sys + +if sys.platform == 'darwin': + from plat_osx import send2trash +elif sys.platform == 'win32': + from plat_win import send2trash +else: + print "Unsupported platform" diff --git a/send2trash/plat_osx.py b/send2trash/plat_osx.py new file mode 100644 index 0000000..26ab907 --- /dev/null +++ b/send2trash/plat_osx.py @@ -0,0 +1,6 @@ +import _send2trash_osx + +def send2trash(path): + if not isinstance(path, unicode): + path = unicode(path, 'utf-8') + _send2trash_osx.send(path) diff --git a/send2trash/plat_win.py b/send2trash/plat_win.py new file mode 100644 index 0000000..e2c5ca0 --- /dev/null +++ b/send2trash/plat_win.py @@ -0,0 +1,9 @@ +import os.path as op +import _send2trash_win + +def send2trash(path): + if not isinstance(path, unicode): + path = unicode(path, 'mbcs') + if not op.isabs(path): + path = op.abspath(path) + _send2trash_win.send(path) diff --git a/setup.py b/setup.py index 3a85b40..e66d14f 100644 --- a/setup.py +++ b/setup.py @@ -1,21 +1,21 @@ import sys import os.path as op -from distutils.core import setup +from setuptools import setup from distutils.extension import Extension exts = [] if sys.platform == 'darwin': exts.append(Extension( - '_trash_osx', - [op.join('modules', 'trash_osx.c')], + '_send2trash_osx', + [op.join('modules', 'send2trash_osx.c')], extra_link_args=['-framework', 'CoreServices'], )) if sys.platform == 'win32': exts.append(Extension( - '_trash_win', - [op.join('modules', 'trash_win.c')], + '_send2trash_win', + [op.join('modules', 'send2trash_win.c')], extra_link_args = ['shell32.lib'], ))