/usr/lib/python2.7/dist-packages/trashcli/fs.py is in trash-cli 0.12.9.14-2.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 | import os, shutil
class FileSystemListing:
def entries_if_dir_exists(self, path):
if os.path.exists(path):
for entry in os.listdir(path):
yield entry
def exists(self, path):
return os.path.exists(path)
class FileSystemReader(FileSystemListing):
def is_sticky_dir(self, path):
import os
return os.path.isdir(path) and has_sticky_bit(path)
def is_symlink(self, path):
return os.path.islink(path)
def contents_of(self, path):
return file(path).read()
class FileRemover:
def remove_file(self, path):
try:
return os.remove(path)
except OSError:
shutil.rmtree(path)
def remove_file_if_exists(self,path):
if os.path.exists(path): self.remove_file(path)
def contents_of(path): # TODO remove
return FileSystemReader().contents_of(path)
def has_sticky_bit(path): # TODO move to FileSystemReader
import os
import stat
return (os.stat(path).st_mode & stat.S_ISVTX) == stat.S_ISVTX
def parent_of(path):
return os.path.dirname(path)
def remove_file(path):
if(os.path.exists(path)):
try:
os.remove(path)
except:
return shutil.rmtree(path)
def move(path, dest) :
return shutil.move(path, str(dest))
def mkdirs_using_mode(path, mode):
if os.path.isdir(path):
os.chmod(path, mode)
return
os.makedirs(path, mode)
def list_files_in_dir(path):
for entry in os.listdir(path):
result = os.path.join(path, entry)
yield result
def mkdirs(path):
if os.path.isdir(path):
return
os.makedirs(path)
|