mirror of
https://github.com/arsenetar/send2trash.git
synced 2025-05-07 09:29:48 +00:00
Properly reuse the "compat" unit
This commit is contained in:
parent
f3231ef857
commit
f324ff491e
@ -1,13 +1,18 @@
|
|||||||
# Copyright 2013 Hardcoded Software (http://www.hardcoded.net)
|
# Copyright 2013 Hardcoded Software (http://www.hardcoded.net)
|
||||||
|
|
||||||
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
# 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
|
# which should be included with this package. The terms are also available at
|
||||||
# http://www.hardcoded.net/licenses/bsd_license
|
# http://www.hardcoded.net/licenses/bsd_license
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
if sys.version < '3':
|
import os
|
||||||
text_type = unicode
|
|
||||||
binary_type = str
|
PY3 = sys.version_info[0] >= 3
|
||||||
else:
|
if PY3:
|
||||||
text_type = str
|
text_type = str
|
||||||
binary_type = bytes
|
binary_type = bytes
|
||||||
|
environb = os.environb
|
||||||
|
else:
|
||||||
|
text_type = unicode
|
||||||
|
binary_type = str
|
||||||
|
environb = os.environ
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Copyright 2013 Hardcoded Software (http://www.hardcoded.net)
|
# Copyright 2013 Hardcoded Software (http://www.hardcoded.net)
|
||||||
|
|
||||||
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
# 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
|
# which should be included with this package. The terms are also available at
|
||||||
# http://www.hardcoded.net/licenses/bsd_license
|
# http://www.hardcoded.net/licenses/bsd_license
|
||||||
|
|
||||||
# This is a reimplementation of plat_other.py with reference to the
|
# This is a reimplementation of plat_other.py with reference to the
|
||||||
@ -27,9 +27,7 @@ except ImportError:
|
|||||||
# Python 2
|
# Python 2
|
||||||
from urllib import quote
|
from urllib import quote
|
||||||
|
|
||||||
# PY2-PY3 compatibilty
|
from .compat import text_type, environb
|
||||||
text_type = str if sys.version_info[0] == 3 else unicode
|
|
||||||
environb = os.environb if sys.version_info[0] >= 3 else os.environ
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fsencode = os.fsencode # Python 3
|
fsencode = os.fsencode # Python 3
|
||||||
@ -96,10 +94,10 @@ def trash_move(src, dst, topdir=None):
|
|||||||
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
|
counter += 1
|
||||||
destname = base_name + b' ' + text_type(counter).encode('ascii') + ext
|
destname = base_name + b' ' + text_type(counter).encode('ascii') + ext
|
||||||
|
|
||||||
check_create(filespath)
|
check_create(filespath)
|
||||||
check_create(infopath)
|
check_create(infopath)
|
||||||
|
|
||||||
os.rename(src, op.join(filespath, destname))
|
os.rename(src, op.join(filespath, destname))
|
||||||
f = open(op.join(infopath, destname + INFO_SUFFIX), 'w')
|
f = open(op.join(infopath, destname + INFO_SUFFIX), 'w')
|
||||||
f.write(info_for(src, topdir))
|
f.write(info_for(src, topdir))
|
||||||
@ -119,7 +117,7 @@ def find_ext_volume_global_trash(volume_root):
|
|||||||
trash_dir = op.join(volume_root, TOPDIR_TRASH)
|
trash_dir = op.join(volume_root, TOPDIR_TRASH)
|
||||||
if not op.exists(trash_dir):
|
if not op.exists(trash_dir):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
mode = os.lstat(trash_dir).st_mode
|
mode = os.lstat(trash_dir).st_mode
|
||||||
# vol/.Trash must be a directory, cannot be a symlink, and must have the
|
# vol/.Trash must be a directory, cannot be a symlink, and must have the
|
||||||
# sticky bit set.
|
# sticky bit set.
|
||||||
@ -171,7 +169,7 @@ def send2trash(path):
|
|||||||
# if the file to be trashed is on the same device as HOMETRASH we
|
# if the file to be trashed is on the same device as HOMETRASH we
|
||||||
# want to move it there.
|
# want to move it there.
|
||||||
path_dev = get_dev(path_b)
|
path_dev = get_dev(path_b)
|
||||||
|
|
||||||
# If XDG_DATA_HOME or HOMETRASH do not yet exist we need to stat the
|
# If XDG_DATA_HOME or HOMETRASH do not yet exist we need to stat the
|
||||||
# home directory, and these paths will be created further on if needed.
|
# home directory, and these paths will be created further on if needed.
|
||||||
trash_dev = get_dev(op.expanduser(b'~'))
|
trash_dev = get_dev(op.expanduser(b'~'))
|
||||||
|
@ -5,6 +5,7 @@ import os
|
|||||||
from os import path as op
|
from os import path as op
|
||||||
import send2trash.plat_other
|
import send2trash.plat_other
|
||||||
from send2trash.plat_other import send2trash as s2t
|
from send2trash.plat_other import send2trash as s2t
|
||||||
|
from send2trash.compat import PY3
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from tempfile import mkdtemp, NamedTemporaryFile, mktemp
|
from tempfile import mkdtemp, NamedTemporaryFile, mktemp
|
||||||
import shutil
|
import shutil
|
||||||
@ -13,7 +14,6 @@ import sys
|
|||||||
# Could still use cleaning up. But no longer relies on ramfs.
|
# Could still use cleaning up. But no longer relies on ramfs.
|
||||||
|
|
||||||
HOMETRASH = send2trash.plat_other.HOMETRASH
|
HOMETRASH = send2trash.plat_other.HOMETRASH
|
||||||
PY3 = sys.version_info[0] >= 3
|
|
||||||
|
|
||||||
def touch(path):
|
def touch(path):
|
||||||
with open(path, 'a'):
|
with open(path, 'a'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user