mirror of
https://github.com/arsenetar/send2trash.git
synced 2025-05-08 17:59:50 +00:00
Compare commits
No commits in common. "d249f0106bfd1fd9af747247f2f13d5ced90d268" and "6612545110d8a51b03016fd0eb7596f0202a9e33" have entirely different histories.
d249f0106b
...
6612545110
@ -22,14 +22,10 @@ issues and fixes would be most appreciated.
|
|||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
You can download it with pip:
|
You can download it with pip::
|
||||||
|
|
||||||
python -m pip install -U send2trash
|
python -m pip install -U send2trash
|
||||||
|
|
||||||
To install with pywin32 or pyobjc required specify the extra `nativeLib`:
|
|
||||||
|
|
||||||
python -m pip install -U send2trash[nativeLib]
|
|
||||||
|
|
||||||
or you can download the source from http://github.com/arsenetar/send2trash and install it with::
|
or you can download the source from http://github.com/arsenetar/send2trash and install it with::
|
||||||
|
|
||||||
>>> python setup.py install
|
>>> python setup.py install
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
|
|
||||||
from gi.repository import GObject, Gio
|
from gi.repository import GObject, Gio
|
||||||
from .exceptions import TrashPermissionError
|
from .exceptions import TrashPermissionError
|
||||||
from .util import preprocess_paths
|
|
||||||
|
|
||||||
|
|
||||||
def send2trash(paths):
|
def send2trash(paths):
|
||||||
paths = preprocess_paths(paths)
|
if not isinstance(paths, list):
|
||||||
|
paths = [paths]
|
||||||
for path in paths:
|
for path in paths:
|
||||||
try:
|
try:
|
||||||
f = Gio.File.new_for_path(path)
|
f = Gio.File.new_for_path(path)
|
||||||
|
@ -10,7 +10,6 @@ from ctypes import cdll, byref, Structure, c_char, c_char_p
|
|||||||
from ctypes.util import find_library
|
from ctypes.util import find_library
|
||||||
|
|
||||||
from .compat import binary_type
|
from .compat import binary_type
|
||||||
from .util import preprocess_paths
|
|
||||||
|
|
||||||
Foundation = cdll.LoadLibrary(find_library("Foundation"))
|
Foundation = cdll.LoadLibrary(find_library("Foundation"))
|
||||||
CoreServices = cdll.LoadLibrary(find_library("CoreServices"))
|
CoreServices = cdll.LoadLibrary(find_library("CoreServices"))
|
||||||
@ -41,7 +40,8 @@ def check_op_result(op_result):
|
|||||||
|
|
||||||
|
|
||||||
def send2trash(paths):
|
def send2trash(paths):
|
||||||
paths = preprocess_paths(paths)
|
if not isinstance(paths, list):
|
||||||
|
paths = [paths]
|
||||||
paths = [
|
paths = [
|
||||||
path.encode("utf-8") if not isinstance(path, binary_type) else path
|
path.encode("utf-8") if not isinstance(path, binary_type) else path
|
||||||
for path in paths
|
for path in paths
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
from Foundation import NSFileManager, NSURL
|
from Foundation import NSFileManager, NSURL
|
||||||
from .compat import text_type
|
from .compat import text_type
|
||||||
from .util import preprocess_paths
|
|
||||||
|
|
||||||
|
|
||||||
def check_op_result(op_result):
|
def check_op_result(op_result):
|
||||||
@ -17,7 +16,8 @@ def check_op_result(op_result):
|
|||||||
|
|
||||||
|
|
||||||
def send2trash(paths):
|
def send2trash(paths):
|
||||||
paths = preprocess_paths(paths)
|
if not isinstance(paths, list):
|
||||||
|
paths = [paths]
|
||||||
paths = [
|
paths = [
|
||||||
path.decode("utf-8") if not isinstance(path, text_type) else path
|
path.decode("utf-8") if not isinstance(path, text_type) else path
|
||||||
for path in paths
|
for path in paths
|
||||||
|
@ -30,7 +30,6 @@ except ImportError:
|
|||||||
from urllib import quote
|
from urllib import quote
|
||||||
|
|
||||||
from .compat import text_type, environb
|
from .compat import text_type, environb
|
||||||
from .util import preprocess_paths
|
|
||||||
from .exceptions import TrashPermissionError
|
from .exceptions import TrashPermissionError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -173,7 +172,8 @@ def get_dev(path):
|
|||||||
|
|
||||||
|
|
||||||
def send2trash(paths):
|
def send2trash(paths):
|
||||||
paths = preprocess_paths(paths)
|
if not isinstance(paths, list):
|
||||||
|
paths = [paths]
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if isinstance(path, text_type):
|
if isinstance(path, text_type):
|
||||||
path_b = fsencode(path)
|
path_b = fsencode(path)
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import os.path as op
|
import os.path as op
|
||||||
from .compat import text_type
|
from .compat import text_type
|
||||||
from .util import preprocess_paths
|
|
||||||
|
|
||||||
from ctypes import (
|
from ctypes import (
|
||||||
windll,
|
windll,
|
||||||
Structure,
|
Structure,
|
||||||
@ -103,7 +101,8 @@ def get_short_path_name(long_name):
|
|||||||
|
|
||||||
|
|
||||||
def send2trash(paths):
|
def send2trash(paths):
|
||||||
paths = preprocess_paths(paths)
|
if not isinstance(paths, list):
|
||||||
|
paths = [paths]
|
||||||
# convert data type
|
# convert data type
|
||||||
paths = [
|
paths = [
|
||||||
text_type(path, "mbcs") if not isinstance(path, text_type) else path
|
text_type(path, "mbcs") if not isinstance(path, text_type) else path
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import os.path as op
|
import os.path as op
|
||||||
from .compat import text_type
|
from .compat import text_type
|
||||||
from .util import preprocess_paths
|
|
||||||
from platform import version
|
from platform import version
|
||||||
import pythoncom
|
import pythoncom
|
||||||
import pywintypes
|
import pywintypes
|
||||||
@ -16,7 +15,8 @@ from .IFileOperationProgressSink import CreateSink
|
|||||||
|
|
||||||
|
|
||||||
def send2trash(paths):
|
def send2trash(paths):
|
||||||
paths = preprocess_paths(paths)
|
if not isinstance(paths, list):
|
||||||
|
paths = [paths]
|
||||||
# convert data type
|
# convert data type
|
||||||
paths = [
|
paths = [
|
||||||
text_type(path, "mbcs") if not isinstance(path, text_type) else path
|
text_type(path, "mbcs") if not isinstance(path, text_type) else path
|
||||||
@ -26,8 +26,6 @@ def send2trash(paths):
|
|||||||
paths = [op.abspath(path) if not op.isabs(path) else path for path in paths]
|
paths = [op.abspath(path) if not op.isabs(path) else path for path in paths]
|
||||||
# remove the leading \\?\ if present
|
# remove the leading \\?\ if present
|
||||||
paths = [path[4:] if path.startswith("\\\\?\\") else path for path in paths]
|
paths = [path[4:] if path.startswith("\\\\?\\") else path for path in paths]
|
||||||
# Need to initialize the com before using
|
|
||||||
pythoncom.CoInitialize()
|
|
||||||
# create instance of file operation object
|
# create instance of file operation object
|
||||||
fileop = pythoncom.CoCreateInstance(
|
fileop = pythoncom.CoCreateInstance(
|
||||||
shell.CLSID_FileOperation, None, pythoncom.CLSCTX_ALL, shell.IID_IFileOperation,
|
shell.CLSID_FileOperation, None, pythoncom.CLSCTX_ALL, shell.IID_IFileOperation,
|
||||||
@ -67,6 +65,3 @@ def send2trash(paths):
|
|||||||
# convert to standard OS error, allows other code to get a
|
# convert to standard OS error, allows other code to get a
|
||||||
# normal errno
|
# normal errno
|
||||||
raise OSError(None, error.strerror, path, error.hresult)
|
raise OSError(None, error.strerror, path, error.hresult)
|
||||||
finally:
|
|
||||||
# Need to make sure we call this once fore every init
|
|
||||||
pythoncom.CoUninitialize()
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
# encoding: utf-8
|
|
||||||
# Copyright 2017 Virgil Dupras
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
def preprocess_paths(paths):
|
|
||||||
if not isinstance(paths, list):
|
|
||||||
paths = [paths]
|
|
||||||
# Convert items such as pathlib paths to strings
|
|
||||||
paths = [
|
|
||||||
path.__fspath__() if hasattr(path, "__fspath__") else path for path in paths
|
|
||||||
]
|
|
||||||
return paths
|
|
9
setup.py
9
setup.py
@ -35,14 +35,7 @@ setup(
|
|||||||
description="Send file to trash natively under Mac OS X, Windows and Linux.",
|
description="Send file to trash natively under Mac OS X, Windows and Linux.",
|
||||||
long_description=LONG_DESCRIPTION,
|
long_description=LONG_DESCRIPTION,
|
||||||
classifiers=CLASSIFIERS,
|
classifiers=CLASSIFIERS,
|
||||||
extras_require={
|
extras_require={"win32": ["pywin32"], "objc": ["pyobjc-framework-Cocoa"]},
|
||||||
"win32": ['pywin32; sys_platform == "win32"'],
|
|
||||||
"objc": ['pyobjc-framework-Cocoa; sys_platform == "darwin"'],
|
|
||||||
"nativeLib": [
|
|
||||||
'pywin32; sys_platform == "win32"',
|
|
||||||
'pyobjc-framework-Cocoa; sys_platform == "darwin"',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
project_urls={"Bug Reports": "https://github.com/arsenetar/send2trash/issues"},
|
project_urls={"Bug Reports": "https://github.com/arsenetar/send2trash/issues"},
|
||||||
entry_points={"console_scripts": ["send2trash=send2trash.__main__:main"]},
|
entry_points={"console_scripts": ["send2trash=send2trash.__main__:main"]},
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user