/usr/lib/python3/dist-packages/cement/utils/fs.py is in python3-cement 2.10.0-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 | """Common File System Utilities."""
import os
import shutil
def abspath(path):
"""
Return an absolute path, while also expanding the '~' user directory
shortcut.
:param path: The original path to expand.
:rtype: str
"""
return os.path.abspath(os.path.expanduser(path))
def backup(path, suffix='.bak'):
"""
Rename a file or directory safely without overwriting an existing
backup of the same name.
:param path: The path to the file or directory to make a backup of.
:param suffix: The suffix to rename files with.
:returns: The new path of backed up file/directory
:rtype: str
"""
count = -1
new_path = None
while True:
if os.path.exists(path):
if count == -1:
new_path = "%s%s" % (path, suffix)
else:
new_path = "%s%s.%s" % (path, suffix, count)
if os.path.exists(new_path):
count += 1
continue
else:
if os.path.isfile(path):
shutil.copy(path, new_path)
elif os.path.isdir(path):
shutil.copytree(path, new_path)
break
else:
break
return new_path
# Kinda dirty, but should resolve issues on Windows per #183
if 'HOME' in os.environ:
HOME_DIR = abspath(os.environ['HOME'])
else:
HOME_DIR = abspath('~') # pragma: nocover
|