mirror of
https://github.com/arsenetar/send2trash.git
synced 2026-01-25 16:11:39 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
2aa834be94
|
|||
|
5e4517aa53
|
|||
|
62849fba0b
|
|||
|
74f2dff57b
|
|||
|
922fc0342a
|
|||
| 1d1b8755a9 | |||
|
d0e4890a4d
|
|||
|
24079e245c
|
|||
|
24b38e4ffe
|
|||
|
69a82a5162
|
|||
|
2b3f9891c2
|
|||
|
039f92264b
|
|||
|
c2c47610c8
|
|||
|
66fc79695e
|
|||
|
454ebeb072
|
|||
|
7ca68e5473
|
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master ]
|
||||
schedule:
|
||||
- cron: '25 5 * * 4'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'python' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||
# Learn more:
|
||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
80
.github/workflows/default.yml
vendored
Normal file
80
.github/workflows/default.yml
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
# Workflow lints, and checks format in parallel then runs tests on all platforms
|
||||
|
||||
name: Default CI/CD
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python 3.x
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.x
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install flake8
|
||||
- name: Lint with flake8
|
||||
run: |
|
||||
flake8 .
|
||||
test:
|
||||
needs: lint
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
python-version: 3.10.0-alpha - 3.10.0
|
||||
- os: ubuntu-latest
|
||||
python-version: 3.9
|
||||
- os: ubuntu-latest
|
||||
python-version: 3.8
|
||||
- os: ubuntu-latest
|
||||
python-version: 3.7
|
||||
- os: ubuntu-latest
|
||||
python-version: 3.6
|
||||
- os: ubuntu-latest
|
||||
python-version: 3.5
|
||||
- os: ubuntu-latest
|
||||
python-version: 2.7
|
||||
# - os: macos-latest
|
||||
# python-version: 3.9
|
||||
# - os: macos-latest
|
||||
# python-version: 3.8
|
||||
# - os: macos-latest
|
||||
# python-version: 2.7
|
||||
- os: windows-latest
|
||||
python-version: 3.9
|
||||
- os: windows-latest
|
||||
python-version: 3.8
|
||||
- os: windows-latest
|
||||
python-version: 2.7
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install pytest
|
||||
- name: Install windows dependencies
|
||||
if: ${{ matrix.os == 'windows-latest' }}
|
||||
run: |
|
||||
pip install pywin32
|
||||
- name: Install macOS dependencies
|
||||
if: ${{ matrix.os == 'macos-latest' }}
|
||||
run: |
|
||||
pip install pyobjc-framework-Cocoa
|
||||
- name: Run tests
|
||||
run: |
|
||||
pytest
|
||||
26
.travis.yml
26
.travis.yml
@@ -1,30 +1,16 @@
|
||||
language: python
|
||||
matrix:
|
||||
include:
|
||||
- os: windows
|
||||
language: sh
|
||||
python: "3.8"
|
||||
env: "PATH=/c/Python38:/c/Python38/Scripts:$PATH"
|
||||
# Perform the manual steps on windows to install python3
|
||||
before_install:
|
||||
- choco install python --version=3.8.6
|
||||
- python -m pip install --upgrade pip
|
||||
before_script:
|
||||
- export TOXENV=py38
|
||||
- python: "2.7"
|
||||
- python: "3.4"
|
||||
- python: "3.5"
|
||||
- python: "3.6"
|
||||
- python: "3.7"
|
||||
- python: "3.8"
|
||||
- python: "3.9"
|
||||
- python: "nightly" # 3.10
|
||||
before_script:
|
||||
- export TOXENV=py310
|
||||
- python: "2.7"
|
||||
arch: ppc64le
|
||||
- python: "3.6"
|
||||
arch: ppc64le
|
||||
- python: "3.7"
|
||||
arch: ppc64le
|
||||
- python: "3.8"
|
||||
arch: ppc64le
|
||||
- python: "3.9"
|
||||
arch: ppc64le
|
||||
install:
|
||||
- python -m pip install tox
|
||||
before_script:
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
Changes
|
||||
=======
|
||||
|
||||
Version 1.8.1b0 -- 2021/09/20
|
||||
-----------------------------
|
||||
* Add fallback to HOMETRASH when cross device errors happen in plat_other (#26, $41, #63)
|
||||
|
||||
Version 1.8.0 -- 2021/08/08
|
||||
---------------------------
|
||||
|
||||
|
||||
6
pyproject.toml
Normal file
6
pyproject.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[build-system]
|
||||
requires = ["setuptools >= 40.6.0", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[tool.black]
|
||||
line-length = 120
|
||||
@@ -35,9 +35,7 @@ class FileOperationProgressSink(DesignatedWrapPolicy):
|
||||
# Can detect cases where to stop via flags and condition below, however the operation
|
||||
# does not actual stop, we can resort to raising an exception as that does stop things
|
||||
# but that may need some additional considerations before implementing.
|
||||
return (
|
||||
0 if flags & shellcon.TSF_DELETE_RECYCLE_IF_POSSIBLE else 0x80004005
|
||||
) # S_OK, or E_FAIL
|
||||
return 0 if flags & shellcon.TSF_DELETE_RECYCLE_IF_POSSIBLE else 0x80004005 # S_OK, or E_FAIL
|
||||
|
||||
def PostDeleteItem(self, flags, item, hrDelete, newlyCreated):
|
||||
if newlyCreated:
|
||||
@@ -58,31 +56,20 @@ class FileOperationProgressSink(DesignatedWrapPolicy):
|
||||
def PreMoveItem(self, Flags, Item, DestinationFolder, NewName):
|
||||
pass
|
||||
|
||||
def PostMoveItem(
|
||||
self, Flags, Item, DestinationFolder, NewName, hrMove, NewlyCreated
|
||||
):
|
||||
def PostMoveItem(self, Flags, Item, DestinationFolder, NewName, hrMove, NewlyCreated):
|
||||
pass
|
||||
|
||||
def PreCopyItem(self, Flags, Item, DestinationFolder, NewName):
|
||||
pass
|
||||
|
||||
def PostCopyItem(
|
||||
self, Flags, Item, DestinationFolder, NewName, hrCopy, NewlyCreated
|
||||
):
|
||||
def PostCopyItem(self, Flags, Item, DestinationFolder, NewName, hrCopy, NewlyCreated):
|
||||
pass
|
||||
|
||||
def PreNewItem(self, Flags, DestinationFolder, NewName):
|
||||
pass
|
||||
|
||||
def PostNewItem(
|
||||
self,
|
||||
Flags,
|
||||
DestinationFolder,
|
||||
NewName,
|
||||
TemplateName,
|
||||
FileAttributes,
|
||||
hrNew,
|
||||
NewItem,
|
||||
self, Flags, DestinationFolder, NewName, TemplateName, FileAttributes, hrNew, NewItem,
|
||||
):
|
||||
pass
|
||||
|
||||
@@ -100,6 +87,4 @@ class FileOperationProgressSink(DesignatedWrapPolicy):
|
||||
|
||||
|
||||
def CreateSink():
|
||||
return pythoncom.WrapObject(
|
||||
FileOperationProgressSink(), shell.IID_IFileOperationProgressSink
|
||||
)
|
||||
return pythoncom.WrapObject(FileOperationProgressSink(), shell.IID_IFileOperationProgressSink)
|
||||
|
||||
@@ -14,20 +14,20 @@ from send2trash import send2trash
|
||||
|
||||
|
||||
def main(args=None):
|
||||
parser = ArgumentParser(description='Tool to send files to trash')
|
||||
parser.add_argument('files', nargs='+')
|
||||
parser.add_argument('-v', '--verbose', action='store_true', help='Print deleted files')
|
||||
parser = ArgumentParser(description="Tool to send files to trash")
|
||||
parser.add_argument("files", nargs="+")
|
||||
parser.add_argument("-v", "--verbose", action="store_true", help="Print deleted files")
|
||||
args = parser.parse_args(args)
|
||||
|
||||
for filename in args.files:
|
||||
try:
|
||||
send2trash(filename)
|
||||
if args.verbose:
|
||||
print('Trashed «' + filename + '»')
|
||||
print("Trashed «" + filename + "»")
|
||||
except OSError as e:
|
||||
print(str(e), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -42,10 +42,7 @@ def check_op_result(op_result):
|
||||
|
||||
def send2trash(paths):
|
||||
paths = preprocess_paths(paths)
|
||||
paths = [
|
||||
path.encode("utf-8") if not isinstance(path, binary_type) else path
|
||||
for path in paths
|
||||
]
|
||||
paths = [path.encode("utf-8") if not isinstance(path, binary_type) else path for path in paths]
|
||||
for path in paths:
|
||||
fp = FSRef()
|
||||
opts = kFSPathMakeRefDoNotFollowLeafSymlink
|
||||
|
||||
@@ -18,10 +18,7 @@ def check_op_result(op_result):
|
||||
|
||||
def send2trash(paths):
|
||||
paths = preprocess_paths(paths)
|
||||
paths = [
|
||||
path.decode("utf-8") if not isinstance(path, text_type) else path
|
||||
for path in paths
|
||||
]
|
||||
paths = [path.decode("utf-8") if not isinstance(path, text_type) else path for path in paths]
|
||||
for path in paths:
|
||||
file_url = NSURL.fileURLWithPath_(path)
|
||||
fm = NSFileManager.defaultManager()
|
||||
|
||||
@@ -19,6 +19,7 @@ from __future__ import unicode_literals
|
||||
import errno
|
||||
import sys
|
||||
import os
|
||||
import shutil
|
||||
import os.path as op
|
||||
from datetime import datetime
|
||||
import stat
|
||||
@@ -95,7 +96,7 @@ def check_create(dir):
|
||||
os.makedirs(dir, 0o700)
|
||||
|
||||
|
||||
def trash_move(src, dst, topdir=None):
|
||||
def trash_move(src, dst, topdir=None, cross_dev=False):
|
||||
filename = op.basename(src)
|
||||
filespath = op.join(dst, FILES_DIR)
|
||||
infopath = op.join(dst, INFO_DIR)
|
||||
@@ -103,9 +104,7 @@ def trash_move(src, dst, topdir=None):
|
||||
|
||||
counter = 0
|
||||
destname = filename
|
||||
while op.exists(op.join(filespath, destname)) or op.exists(
|
||||
op.join(infopath, destname + INFO_SUFFIX)
|
||||
):
|
||||
while op.exists(op.join(filespath, destname)) or op.exists(op.join(infopath, destname + INFO_SUFFIX)):
|
||||
counter += 1
|
||||
destname = base_name + b" " + text_type(counter).encode("ascii") + ext
|
||||
|
||||
@@ -114,14 +113,18 @@ def trash_move(src, dst, topdir=None):
|
||||
|
||||
with open(op.join(infopath, destname + INFO_SUFFIX), "w") as f:
|
||||
f.write(info_for(src, topdir))
|
||||
os.rename(src, op.join(filespath, destname))
|
||||
destpath = op.join(filespath, destname)
|
||||
if cross_dev:
|
||||
shutil.move(src, destpath)
|
||||
else:
|
||||
os.rename(src, destpath)
|
||||
|
||||
|
||||
def find_mount_point(path):
|
||||
# Even if something's wrong, "/" is a mount point, so the loop will exit.
|
||||
# Use realpath in case it's a symlink
|
||||
path = op.realpath(path) # Required to avoid infinite loop
|
||||
while not op.ismount(path):
|
||||
while not op.ismount(path): # Note ismount() does not always detect mounts
|
||||
path = op.split(path)[0]
|
||||
return path
|
||||
|
||||
@@ -208,4 +211,11 @@ def send2trash(paths):
|
||||
if trash_dev != path_dev:
|
||||
raise OSError("Couldn't find mount point for %s" % path)
|
||||
dest_trash = find_ext_volume_trash(topdir)
|
||||
trash_move(path_b, dest_trash, topdir)
|
||||
try:
|
||||
trash_move(path_b, dest_trash, topdir)
|
||||
except OSError as error:
|
||||
# Cross link errors default back to HOMETRASH
|
||||
if error.errno == errno.EXDEV:
|
||||
trash_move(path_b, HOMETRASH_B, XDG_DATA_HOME, cross_dev=True)
|
||||
else:
|
||||
raise
|
||||
|
||||
@@ -105,10 +105,7 @@ def get_short_path_name(long_name):
|
||||
def send2trash(paths):
|
||||
paths = preprocess_paths(paths)
|
||||
# convert data type
|
||||
paths = [
|
||||
text_type(path, "mbcs") if not isinstance(path, text_type) else path
|
||||
for path in paths
|
||||
]
|
||||
paths = [text_type(path, "mbcs") if not isinstance(path, text_type) else path for path in paths]
|
||||
# convert to full paths
|
||||
paths = [op.abspath(path) if not op.isabs(path) else path for path in paths]
|
||||
# get short path to handle path length issues
|
||||
|
||||
@@ -18,10 +18,7 @@ from .IFileOperationProgressSink import CreateSink
|
||||
def send2trash(paths):
|
||||
paths = preprocess_paths(paths)
|
||||
# convert data type
|
||||
paths = [
|
||||
text_type(path, "mbcs") if not isinstance(path, text_type) else path
|
||||
for path in paths
|
||||
]
|
||||
paths = [text_type(path, "mbcs") if not isinstance(path, text_type) else path for path in paths]
|
||||
# convert to full paths
|
||||
paths = [op.abspath(path) if not op.isabs(path) else path for path in paths]
|
||||
# remove the leading \\?\ if present
|
||||
@@ -33,19 +30,11 @@ def send2trash(paths):
|
||||
shell.CLSID_FileOperation, None, pythoncom.CLSCTX_ALL, shell.IID_IFileOperation,
|
||||
)
|
||||
# default flags to use
|
||||
flags = (
|
||||
shellcon.FOF_NOCONFIRMATION
|
||||
| shellcon.FOF_NOERRORUI
|
||||
| shellcon.FOF_SILENT
|
||||
| shellcon.FOFX_EARLYFAILURE
|
||||
)
|
||||
flags = shellcon.FOF_NOCONFIRMATION | shellcon.FOF_NOERRORUI | shellcon.FOF_SILENT | shellcon.FOFX_EARLYFAILURE
|
||||
# determine rest of the flags based on OS version
|
||||
# use newer recommended flags if available
|
||||
if int(version().split(".", 1)[0]) >= 8:
|
||||
flags |= (
|
||||
0x20000000 # FOFX_ADDUNDORECORD win 8+
|
||||
| 0x00080000 # FOFX_RECYCLEONDELETE win 8+
|
||||
)
|
||||
flags |= 0x20000000 | 0x00080000 # FOFX_ADDUNDORECORD win 8+ # FOFX_RECYCLEONDELETE win 8+
|
||||
else:
|
||||
flags |= shellcon.FOF_ALLOWUNDO
|
||||
# set the flags
|
||||
|
||||
@@ -10,7 +10,5 @@ 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
|
||||
]
|
||||
paths = [path.__fspath__() if hasattr(path, "__fspath__") else path for path in paths]
|
||||
return paths
|
||||
|
||||
45
setup.cfg
Normal file
45
setup.cfg
Normal file
@@ -0,0 +1,45 @@
|
||||
[metadata]
|
||||
name = Send2Trash
|
||||
version = 1.8.1b0
|
||||
url = https://github.com/arsenetar/send2trash
|
||||
project_urls =
|
||||
Bug Reports = https://github.com/arsenetar/send2trash/issues
|
||||
author = Andrew Senetar
|
||||
author_email = arsenetar@voltaicideas.net
|
||||
license = BSD License
|
||||
license_files = LICENSE
|
||||
description = Send file to trash natively under Mac OS X, Windows and Linux
|
||||
long_description = file:README.rst
|
||||
long_description_content_type = text/x-rst
|
||||
classifiers =
|
||||
Development Status :: 5 - Production/Stable
|
||||
Intended Audience :: Developers
|
||||
License :: OSI Approved :: BSD License
|
||||
Operating System :: MacOS :: MacOS X
|
||||
Operating System :: Microsoft :: Windows
|
||||
Operating System :: POSIX
|
||||
Programming Language :: Python :: 2.7
|
||||
Programming Language :: Python :: 3
|
||||
Programming Language :: Python :: 3.5
|
||||
Programming Language :: Python :: 3.6
|
||||
Programming Language :: Python :: 3.7
|
||||
Programming Language :: Python :: 3.8
|
||||
Programming Language :: Python :: 3.9
|
||||
Programming Language :: Python :: 3.10
|
||||
Topic :: Desktop Environment :: File Managers
|
||||
|
||||
[options]
|
||||
packages = send2trash
|
||||
tests_require = pytest
|
||||
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
|
||||
|
||||
[options.extras_require]
|
||||
win32 = pywin32; sys_platform == "win32"
|
||||
objc = pyobjc-framework-Cocoa; sys_platform == "darwin"
|
||||
nativeLib =
|
||||
pywin32; sys_platform == "win32"
|
||||
pyobjc-framework-Cocoa; sys_platform == "darwin"
|
||||
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
send2trash = send2trash.__main__:main
|
||||
49
setup.py
49
setup.py
@@ -1,49 +0,0 @@
|
||||
from setuptools import setup
|
||||
|
||||
CLASSIFIERS = [
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"Intended Audience :: Developers",
|
||||
"License :: OSI Approved :: BSD License",
|
||||
"Operating System :: MacOS :: MacOS X",
|
||||
"Operating System :: Microsoft :: Windows",
|
||||
"Operating System :: POSIX",
|
||||
"Programming Language :: Python :: 2.7",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.4",
|
||||
"Programming Language :: Python :: 3.5",
|
||||
"Programming Language :: Python :: 3.6",
|
||||
"Programming Language :: Python :: 3.7",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Topic :: Desktop Environment :: File Managers",
|
||||
]
|
||||
|
||||
with open("README.rst", "rt") as f1, open("CHANGES.rst", "rt") as f2:
|
||||
LONG_DESCRIPTION = f1.read() + "\n\n" + f2.read()
|
||||
|
||||
setup(
|
||||
name="Send2Trash",
|
||||
version="1.8.0",
|
||||
author="Andrew Senetar",
|
||||
author_email="arsenetar@voltaicideas.net",
|
||||
packages=["send2trash"],
|
||||
scripts=[],
|
||||
test_suite="tests",
|
||||
url="https://github.com/arsenetar/send2trash",
|
||||
license="BSD License",
|
||||
description="Send file to trash natively under Mac OS X, Windows and Linux.",
|
||||
long_description=LONG_DESCRIPTION,
|
||||
long_description_content_type="text/x-rst",
|
||||
classifiers=CLASSIFIERS,
|
||||
extras_require={
|
||||
"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"},
|
||||
entry_points={"console_scripts": ["send2trash=send2trash.__main__:main"]},
|
||||
)
|
||||
@@ -28,9 +28,7 @@ else:
|
||||
|
||||
@pytest.fixture
|
||||
def testfile():
|
||||
file = NamedTemporaryFile(
|
||||
dir=op.expanduser("~"), prefix="send2trash_test", delete=False
|
||||
)
|
||||
file = NamedTemporaryFile(dir=op.expanduser("~"), prefix="send2trash_test", delete=False)
|
||||
file.close()
|
||||
assert op.exists(file.name) is True
|
||||
yield file
|
||||
@@ -50,9 +48,7 @@ def testfiles():
|
||||
files = list(
|
||||
map(
|
||||
lambda index: NamedTemporaryFile(
|
||||
dir=op.expanduser("~"),
|
||||
prefix="send2trash_test{}".format(index),
|
||||
delete=False,
|
||||
dir=op.expanduser("~"), prefix="send2trash_test{}".format(index), delete=False,
|
||||
),
|
||||
range(10),
|
||||
)
|
||||
@@ -62,10 +58,7 @@ def testfiles():
|
||||
yield files
|
||||
filenames = [op.basename(file.name) for file in files]
|
||||
[os.remove(op.join(HOMETRASH, "files", filename)) for filename in filenames]
|
||||
[
|
||||
os.remove(op.join(HOMETRASH, "info", filename + ".trashinfo"))
|
||||
for filename in filenames
|
||||
]
|
||||
[os.remove(op.join(HOMETRASH, "info", filename + ".trashinfo")) for filename in filenames]
|
||||
|
||||
|
||||
def test_trash(testfile):
|
||||
@@ -136,10 +129,7 @@ class ExtVol:
|
||||
return st.st_dev
|
||||
|
||||
def s_ismount(path):
|
||||
if op.realpath(path) in (
|
||||
op.realpath(self.trashTopdir),
|
||||
op.realpath(self.trashTopdir_b),
|
||||
):
|
||||
if op.realpath(path) in (op.realpath(self.trashTopdir), op.realpath(self.trashTopdir_b),):
|
||||
return True
|
||||
return old_ismount(path)
|
||||
|
||||
@@ -172,15 +162,8 @@ def test_trash_topdir(testExtVol):
|
||||
|
||||
s2t(testExtVol[2])
|
||||
assert op.exists(testExtVol[2]) is False
|
||||
assert (
|
||||
op.exists(op.join(trashDir, str(os.getuid()), "files", testExtVol[1])) is True
|
||||
)
|
||||
assert (
|
||||
op.exists(
|
||||
op.join(trashDir, str(os.getuid()), "info", testExtVol[1] + ".trashinfo",)
|
||||
)
|
||||
is True
|
||||
)
|
||||
assert op.exists(op.join(trashDir, str(os.getuid()), "files", testExtVol[1])) is True
|
||||
assert op.exists(op.join(trashDir, str(os.getuid()), "info", testExtVol[1] + ".trashinfo",)) is True
|
||||
# info relative path (if another test is added, with the same fileName/Path,
|
||||
# then it gets renamed etc.)
|
||||
cfg = ConfigParser()
|
||||
@@ -191,17 +174,7 @@ def test_trash_topdir(testExtVol):
|
||||
def test_trash_topdir_fallback(testExtVol):
|
||||
s2t(testExtVol[2])
|
||||
assert op.exists(testExtVol[2]) is False
|
||||
assert (
|
||||
op.exists(
|
||||
op.join(
|
||||
testExtVol[0].trashTopdir,
|
||||
".Trash-" + str(os.getuid()),
|
||||
"files",
|
||||
testExtVol[1],
|
||||
)
|
||||
)
|
||||
is True
|
||||
)
|
||||
assert op.exists(op.join(testExtVol[0].trashTopdir, ".Trash-" + str(os.getuid()), "files", testExtVol[1],)) is True
|
||||
|
||||
|
||||
def test_trash_topdir_failure(testExtVol):
|
||||
@@ -221,15 +194,5 @@ def test_trash_symlink(testExtVol):
|
||||
os.symlink(op.join(testExtVol[0].trashTopdir, "subdir"), slDir)
|
||||
s2t(op.join(slDir, testExtVol[1]))
|
||||
assert op.exists(filePath) is False
|
||||
assert (
|
||||
op.exists(
|
||||
op.join(
|
||||
testExtVol[0].trashTopdir,
|
||||
".Trash-" + str(os.getuid()),
|
||||
"files",
|
||||
testExtVol[1],
|
||||
)
|
||||
)
|
||||
is True
|
||||
)
|
||||
assert op.exists(op.join(testExtVol[0].trashTopdir, ".Trash-" + str(os.getuid()), "files", testExtVol[1],)) is True
|
||||
os.remove(slDir)
|
||||
|
||||
@@ -144,7 +144,10 @@ def longdir(tmp_path):
|
||||
dirname = "\\\\?\\" + str(tmp_path)
|
||||
name = "A" * 100
|
||||
yield op.join(dirname, name, name, name)
|
||||
shutil.rmtree(dirname, ignore_errors=True)
|
||||
try:
|
||||
shutil.rmtree(dirname, ignore_errors=True)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -14,9 +14,7 @@ if sys.platform != "win32":
|
||||
|
||||
@pytest.fixture
|
||||
def file():
|
||||
file = NamedTemporaryFile(
|
||||
dir=op.expanduser("~"), prefix="send2trash_test", delete=False
|
||||
)
|
||||
file = NamedTemporaryFile(dir=op.expanduser("~"), prefix="send2trash_test", delete=False)
|
||||
file.close()
|
||||
# Verify file was actually created
|
||||
assert op.exists(file.name) is True
|
||||
|
||||
4
tox.ini
4
tox.ini
@@ -1,6 +1,7 @@
|
||||
[tox]
|
||||
envlist = py{27,34,35,36,37,38,39,310}
|
||||
skip_missing_interpreters = True
|
||||
isolated_build = True
|
||||
|
||||
[testenv]
|
||||
deps =
|
||||
@@ -20,4 +21,5 @@ deps =
|
||||
[flake8]
|
||||
exclude = .tox,env,build
|
||||
max-line-length = 120
|
||||
ignore = E731,E203,E501,W503
|
||||
select = C,E,F,W,B,B950
|
||||
extend-ignore = E203, E501
|
||||
|
||||
Reference in New Issue
Block a user