Merged default branch with py3k. Py3k version of send2trash is now the default one (python 2 version is in the py2k branch).
commit
a8a771c9bd
@ -1,2 +1,3 @@
|
||||
48c2103380f5e7deca49364f44fb31ded9942bb7 1.0.0
|
||||
a7e04d8e47e161daaa1f031a7c1e98c52fa269ac 1.0.1
|
||||
de5f43fcce5e776eb28306951939afb9946cbd3d 1.1.0
|
||||
|
@ -1,14 +1,22 @@
|
||||
Changes
|
||||
=======
|
||||
|
||||
Version 1.1.0 -- 2010/10/18
|
||||
---------------------------
|
||||
|
||||
* Converted compiled modules to ctypes so that cross-platform compilation isn't necessary anymore.
|
||||
|
||||
Version 1.0.2 -- 2010/07/10
|
||||
---
|
||||
---------------------------
|
||||
|
||||
* Fixed bugs with external volumes in plat_other.
|
||||
|
||||
Version 1.0.1 -- 2010/04/19
|
||||
---
|
||||
---------------------------
|
||||
|
||||
* Fixed memory leak in OS X module.
|
||||
|
||||
Version 1.0.0 -- 2010/04/07
|
||||
---
|
||||
---------------------------
|
||||
|
||||
* Initial Release
|
@ -0,0 +1 @@
|
||||
include CHANGES
|
@ -1,45 +0,0 @@
|
||||
/* Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
||||
|
||||
This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
||||
which should be included with this package. The terms are also available at
|
||||
http://www.hardcoded.net/licenses/bsd_license
|
||||
*/
|
||||
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include "Python.h"
|
||||
#include <CoreServices/CoreServices.h>
|
||||
|
||||
static PyObject* send2trash_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);
|
||||
PyMem_Free(utf8_chars);
|
||||
if (op_result != noErr) {
|
||||
PyErr_SetString(PyExc_OSError, GetMacOSStatusCommentString(op_result));
|
||||
return NULL;
|
||||
}
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyMethodDef TrashMethods[] = {
|
||||
{"send", send2trash_osx_send, METH_VARARGS, ""},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC
|
||||
init_send2trash_osx(void)
|
||||
{
|
||||
PyObject *m = Py_InitModule("_send2trash_osx", TrashMethods);
|
||||
if (m == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,68 +0,0 @@
|
||||
/* Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
||||
|
||||
This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
||||
which should be included with this package. The terms are also available at
|
||||
http://www.hardcoded.net/licenses/bsd_license
|
||||
*/
|
||||
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include "Python.h"
|
||||
|
||||
#define WINDOWS_LEAN_AND_MEAN
|
||||
#include "windows.h"
|
||||
#include "shlobj.h"
|
||||
|
||||
/* WARNING: If the filepath is not fully qualified, Windows deletes the file
|
||||
rather than sending it to trash.
|
||||
*/
|
||||
|
||||
static PyObject* send2trash_win_send(PyObject *self, PyObject *args)
|
||||
{
|
||||
SHFILEOPSTRUCTW op;
|
||||
PyObject *filepath;
|
||||
Py_ssize_t len;
|
||||
WCHAR filechars[MAX_PATH+1];
|
||||
int r;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &filepath)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyUnicode_Check(filepath)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Unicode filename required");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = PyUnicode_GET_SIZE(filepath);
|
||||
memcpy(filechars, PyUnicode_AsUnicode(filepath), sizeof(WCHAR)*len);
|
||||
filechars[len] = '\0';
|
||||
filechars[len+1] = '\0';
|
||||
|
||||
op.hwnd = 0;
|
||||
op.wFunc = FO_DELETE;
|
||||
op.pFrom = (LPCWSTR)&filechars;
|
||||
op.pTo = NULL;
|
||||
op.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT;
|
||||
r = SHFileOperationW(&op);
|
||||
|
||||
if (r != 0) {
|
||||
PyErr_Format(PyExc_OSError, "Couldn't perform operation. Error code: %d", r);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyMethodDef TrashMethods[] = {
|
||||
{"send", send2trash_win_send, METH_VARARGS, ""},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC
|
||||
init_send2trash_win(void)
|
||||
{
|
||||
PyObject *m = Py_InitModule("_send2trash_win", TrashMethods);
|
||||
if (m == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue