1349
1351
normalized_filename = _inaccessible_normalized_filename
1354
def set_signal_handler(signum, handler, restart_syscall=True):
1355
"""A wrapper for signal.signal that also calls siginterrupt(signum, False)
1356
on platforms that support that.
1358
:param restart_syscall: if set, allow syscalls interrupted by a signal to
1359
automatically restart (by calling `signal.siginterrupt(signum,
1360
False)`). May be ignored if the feature is not available on this
1361
platform or Python version.
1363
old_handler = signal.signal(signum, handler)
1366
siginterrupt = signal.siginterrupt
1367
except AttributeError: # siginterrupt doesn't exist on this platform, or for this version of
1371
siginterrupt(signum, False)
1352
1375
default_terminal_width = 80
1353
1376
"""The default terminal width for ttys.
1456
1479
# the current design -- vila 20091216
1459
signal.signal(signal.SIGWINCH, _terminal_size_changed)
1482
set_signal_handler(signal.SIGWINCH, _terminal_size_changed)
1460
1483
_registered_sigwinch = True
1783
1806
real_handlers[kind](abspath, relpath)
1809
def copy_ownership(dst, src=None):
1810
"""Copy usr/grp ownership from src file/dir to dst file/dir.
1812
If src is None, the containing directory is used as source. If chown
1813
fails, the error is ignored and a warning is printed.
1815
has_chown = getattr(os, 'chown')
1816
if has_chown is None: return
1819
src = os.path.dirname(dst)
1825
os.chown(dst, s.st_uid, s.st_gid)
1827
trace.warning("Unable to copy ownership from '%s' to '%s': IOError: %s." % (src, dst, e))
1830
def mkdir_with_ownership(path, ownership_src=None):
1831
"""Create the directory 'path' with specified ownership.
1833
If ownership_src is given, copies (chown) usr/grp ownership
1834
from 'ownership_src' to 'path'. If ownership_src is None, use the
1835
containing dir ownership.
1838
copy_ownership(path, ownership_src)
1841
def open_with_ownership(filename, mode='r', bufsize=-1, ownership_src=None):
1842
"""Open the file 'filename' with the specified ownership.
1844
If ownership_src is specified, copy usr/grp ownership from ownership_src
1845
to filename. If ownership_src is None, copy ownership from containing
1847
Returns the opened file object.
1849
f = open(filename, mode, bufsize)
1850
copy_ownership(filename, ownership_src)
1786
1854
def path_prefix_key(path):
1787
1855
"""Generate a prefix-order path key for path.