From 5aa48117258800743b27607aefcb39a63359deec Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 6 Apr 2010 08:58:56 +0200 Subject: [PATCH] Added the osx module. --- .hgignore | 4 ++++ modules/trash_osx.c | 36 ++++++++++++++++++++++++++++++++++++ send2trash/__init__.py | 0 setup.py | 25 +++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 .hgignore create mode 100644 modules/trash_osx.c create mode 100644 send2trash/__init__.py create mode 100644 setup.py diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..444a474 --- /dev/null +++ b/.hgignore @@ -0,0 +1,4 @@ +syntax: glob + +build +.DS_Store \ No newline at end of file diff --git a/modules/trash_osx.c b/modules/trash_osx.c new file mode 100644 index 0000000..ea3ebe9 --- /dev/null +++ b/modules/trash_osx.c @@ -0,0 +1,36 @@ +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#include + +static PyObject* trash_osx_send(PyObject *self, PyObject *args) +{ + UInt8 *utf8_chars; + FSRef fp; + OSStatus op_result; + + if (!PyArg_ParseTuple(args, "es", "utf-8", &utf8_chars)) { + return NULL; + } + + FSPathMakeRefWithOptions(utf8_chars, kFSPathMakeRefDoNotFollowLeafSymlink, &fp, NULL); + op_result = FSMoveObjectToTrashSync(&fp, NULL, kFSFileOperationDefaultOptions); + if (op_result != noErr) { + PyErr_SetString(PyExc_IOError, GetMacOSStatusCommentString(op_result)); + return NULL; + } + return Py_None; +} + +static PyMethodDef TrashMethods[] = { + {"send", trash_osx_send, METH_VARARGS, ""}, +}; + +PyMODINIT_FUNC +init_trash_osx(void) +{ + PyObject *m = Py_InitModule("_trash_osx", TrashMethods); + if (m == NULL) { + return; + } +} + diff --git a/send2trash/__init__.py b/send2trash/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..77594d9 --- /dev/null +++ b/setup.py @@ -0,0 +1,25 @@ +import os.path as op + +from distutils.core import setup +from distutils.extension import Extension + +exts = [] + +exts.append(Extension( + '_trash_osx', + [op.join('modules', 'trash_osx.c')], + extra_link_args=['-framework', 'CoreServices'], +)) + +setup( + name='Send2Trash', + version='1.0.0', + author='Hardcoded Software', + author_email='hsoft@hardcoded.net', + packages=['send2trash'], + scripts=[], + ext_modules = exts, + url='http://www.hardcoded.net/docs/send2trash/', + license='LICENSE', + description='Send file to trash natively under Mac OS X, Windows and Linux.', +) \ No newline at end of file