/usr/lib/python2.7/dist-packages/dispcalGUI/trash.py is in dispcalgui 1.7.1.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | # -*- coding: utf-8 -*-
import sys
import os
if sys.platform == "win32":
from win32com.shell import shell, shellcon
import win32api
def recycle(path):
path = os.path.join(win32api.GetShortPathName(os.path.split(path)[0]),
os.path.split(path)[1])
retcode, aborted = shell.SHFileOperation((0,
shellcon.FO_DELETE, path, "", shellcon.FOF_ALLOWUNDO |
shellcon.FOF_NOCONFIRMATION | shellcon.FOF_RENAMEONCOLLISION |
shellcon.FOF_SILENT, None, None))
return retcode == 0
else:
from time import strftime
from urllib import quote
import shutil
from util_os import getenvu, expanduseru
class TrashcanUnavailableError(Exception):
pass
def trash(paths):
"""
Move files and folders to the trash.
If a trashcan facility does not exist, do not touch the files.
Return a list of successfully processed paths.
"""
if isinstance(paths, (str, unicode)):
paths = [paths]
if not isinstance(paths, list):
raise TypeError(str(type(paths)) + " is not list")
deleted = []
if sys.platform == "win32":
for path in paths:
path = os.path.abspath(path)
if not os.path.exists(path):
raise IOError("No such file or directory: " + path)
if recycle(path):
deleted += [path]
else:
# http://freedesktop.org/wiki/Specifications/trash-spec
trashroot = os.path.join(getenvu("XDG_DATA_HOME",
os.path.join(expanduseru("~"), ".local", "share")), "Trash")
trashinfo = os.path.join(trashroot, "info")
if os.path.isdir(trashroot):
# modern Linux distros
trashcan = os.path.join(trashroot, "files")
else:
# older Linux distros and Mac OS X
trashcan = os.path.join(expanduseru("~"), ".Trash")
if not os.path.isdir(trashcan):
raise TrashcanUnavailableError("Not a directory: '%s'" % trashcan)
for path in paths:
if os.path.isdir(trashcan):
n = 1
dst = os.path.join(trashcan, os.path.basename(path))
while os.path.exists(dst):
# avoid name clashes
n += 1
dst = os.path.join(trashcan,
os.path.basename(path) + "." + str(n))
if os.path.isdir(trashinfo):
info = open(os.path.join(trashinfo,
os.path.basename(dst) +
".trashinfo"), "w")
info.write("[Trash Info]\n")
info.write("Path=%s\n" %
quote(path.encode(sys.getfilesystemencoding())))
info.write("DeletionDate=" +
strftime("%Y-%m-%dT%H:%M:%S"))
info.close()
shutil.move(path, dst)
else:
# if trashcan does not exist, simply delete file/folder?
pass
# if os.path.isdir(path) and not os.path.islink(path):
# shutil.rmtree(path)
# else:
# os.remove(path)
deleted += [path]
return deleted
|