mirror of
https://github.com/arsenetar/send2trash.git
synced 2026-03-12 10:51:37 +00:00
Compare commits
5 Commits
1.7.0a1
...
6612545110
| Author | SHA1 | Date | |
|---|---|---|---|
|
6612545110
|
|||
|
d52b4f206c
|
|||
|
33171dde82
|
|||
| 077598d2ce | |||
|
|
436686bf0f |
15
CHANGES.rst
15
CHANGES.rst
@@ -1,8 +1,19 @@
|
|||||||
Changes
|
Changes
|
||||||
=======
|
=======
|
||||||
|
Version 1.7.1 -- 2021/06/21
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
* Release stable version with changes from last 3 releases
|
||||||
|
* Fix handling of UNC names (#57)
|
||||||
|
|
||||||
|
Version 1.7.0a1 -- 2021/05/14
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
* Changed conditional for when to try to use pyobjc version (#51)
|
||||||
|
|
||||||
|
Version 1.7.0a0 -- 2021/04/20
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
Version 1.7.0a -- 2020/04/20
|
|
||||||
----------------------------
|
|
||||||
* Add console_script entry point (#50)
|
* Add console_script entry point (#50)
|
||||||
* Increased python CI versions (#52, #54)
|
* Increased python CI versions (#52, #54)
|
||||||
* Fix minor issue in setup.py (#53)
|
* Fix minor issue in setup.py (#53)
|
||||||
|
|||||||
10
README.rst
10
README.rst
@@ -3,11 +3,11 @@ Send2Trash -- Send files to trash on all platforms
|
|||||||
==================================================
|
==================================================
|
||||||
|
|
||||||
Send2Trash is a small package that sends files to the Trash (or Recycle Bin) *natively* and on
|
Send2Trash is a small package that sends files to the Trash (or Recycle Bin) *natively* and on
|
||||||
*all platforms*. On OS X, it uses native ``FSMoveObjectToTrashSync`` Cocoa calls. On Windows, it
|
*all platforms*. On OS X, it uses native ``FSMoveObjectToTrashSync`` Cocoa calls or can use pyobjc
|
||||||
uses native ``IFileOperation`` call if on Vista or newer and pywin32 is installed or falls back
|
with NSFileManager. On Windows, it uses native ``IFileOperation`` call if on Vista or newer and
|
||||||
to ``SHFileOperation`` calls. On other platforms, if `PyGObject`_ and `GIO`_ are available, it
|
pywin32 is installed or falls back to ``SHFileOperation`` calls. On other platforms, if `PyGObject`_
|
||||||
will use this. Otherwise, it will fallback to its own implementation of the `trash specifications
|
and `GIO`_ are available, it will use this. Otherwise, it will fallback to its own implementation of
|
||||||
from freedesktop.org`_.
|
the `trash specifications from freedesktop.org`_.
|
||||||
|
|
||||||
``ctypes`` is used to access native libraries, so no compilation is necessary.
|
``ctypes`` is used to access native libraries, so no compilation is necessary.
|
||||||
|
|
||||||
|
|||||||
@@ -51,18 +51,53 @@ FOF_ALLOWUNDO = 64
|
|||||||
FOF_NOERRORUI = 1024
|
FOF_NOERRORUI = 1024
|
||||||
|
|
||||||
|
|
||||||
|
def prefix_and_path(path):
|
||||||
|
r"""Guess the long-path prefix based on the kind of *path*.
|
||||||
|
Local paths (C:\folder\file.ext) and UNC names (\\server\folder\file.ext)
|
||||||
|
are handled.
|
||||||
|
|
||||||
|
Return a tuple of the long-path prefix and the prefixed path.
|
||||||
|
"""
|
||||||
|
prefix, long_path = "\\\\?\\", path
|
||||||
|
|
||||||
|
if not path.startswith(prefix):
|
||||||
|
if path.startswith("\\\\"):
|
||||||
|
# Likely a UNC name
|
||||||
|
prefix = "\\\\?\\UNC"
|
||||||
|
long_path = prefix + path[1:]
|
||||||
|
else:
|
||||||
|
# Likely a local path
|
||||||
|
long_path = prefix + path
|
||||||
|
elif path.startswith(prefix + "UNC\\"):
|
||||||
|
# UNC name with long-path prefix
|
||||||
|
prefix = "\\\\?\\UNC"
|
||||||
|
|
||||||
|
return prefix, long_path
|
||||||
|
|
||||||
|
|
||||||
|
def get_awaited_path_from_prefix(prefix, path):
|
||||||
|
"""Guess the correct path to pass to the SHFileOperationW() call.
|
||||||
|
The long-path prefix must be removed, so we should take care of
|
||||||
|
different long-path prefixes.
|
||||||
|
"""
|
||||||
|
if prefix == "\\\\?\\UNC":
|
||||||
|
# We need to prepend a backslash for UNC names, as it was removed
|
||||||
|
# in prefix_and_path().
|
||||||
|
return "\\" + path[len(prefix) :]
|
||||||
|
return path[len(prefix) :]
|
||||||
|
|
||||||
|
|
||||||
def get_short_path_name(long_name):
|
def get_short_path_name(long_name):
|
||||||
if not long_name.startswith("\\\\?\\"):
|
prefix, long_path = prefix_and_path(long_name)
|
||||||
long_name = "\\\\?\\" + long_name
|
buf_size = GetShortPathNameW(long_path, None, 0)
|
||||||
buf_size = GetShortPathNameW(long_name, None, 0)
|
|
||||||
# FIX: https://github.com/hsoft/send2trash/issues/31
|
# FIX: https://github.com/hsoft/send2trash/issues/31
|
||||||
# If buffer size is zero, an error has occurred.
|
# If buffer size is zero, an error has occurred.
|
||||||
if not buf_size:
|
if not buf_size:
|
||||||
err_no = GetLastError()
|
err_no = GetLastError()
|
||||||
raise WindowsError(err_no, FormatError(err_no), long_name[4:])
|
raise WindowsError(err_no, FormatError(err_no), long_path)
|
||||||
output = create_unicode_buffer(buf_size)
|
output = create_unicode_buffer(buf_size)
|
||||||
GetShortPathNameW(long_name, output, buf_size)
|
GetShortPathNameW(long_path, output, buf_size)
|
||||||
return output.value[4:] # Remove '\\?\' for SHFileOperationW
|
return get_awaited_path_from_prefix(prefix, output.value)
|
||||||
|
|
||||||
|
|
||||||
def send2trash(paths):
|
def send2trash(paths):
|
||||||
|
|||||||
4
setup.py
4
setup.py
@@ -24,7 +24,7 @@ with open("README.rst", "rt") as f1, open("CHANGES.rst", "rt") as f2:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="Send2Trash",
|
name="Send2Trash",
|
||||||
version="1.7.0a1",
|
version="1.7.1",
|
||||||
author="Andrew Senetar",
|
author="Andrew Senetar",
|
||||||
author_email="arsenetar@voltaicideas.net",
|
author_email="arsenetar@voltaicideas.net",
|
||||||
packages=["send2trash"],
|
packages=["send2trash"],
|
||||||
@@ -35,7 +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={"win32": ["pywin32"]},
|
extras_require={"win32": ["pywin32"], "objc": ["pyobjc-framework-Cocoa"]},
|
||||||
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"]},
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user