1785
1785
real_handlers[kind](abspath, relpath)
1788
def parent_dir(path):
1789
"""same as os.path.dirname but returns '.' instead of ''
1790
for paths that just have a filename in it e.g. 'foo'"""
1791
pdir = os.path.dirname(path)
1797
def copy_ownership(dst, src):
1798
"""copy user and group ownership from own_src file/dir to dst file/dir.
1799
If own_src is None, the containing directory is used as source."""
1788
def copy_ownership(dst, src=None):
1789
"""copy usr/grp ownership from src file/dir to dst file/dir.
1790
If src is None, the containing directory is used as source."""
1800
1791
if os.name != 'posix':
1795
src = os.path.dirname(dst)
1803
1800
s = os.stat(src)
1804
1801
os.chown(dst, s.st_uid, s.st_gid)
1810
1807
def mkdir_with_ownership(path, ownership_src=None):
1811
"""creates the directory 'path'. If ownership_src is given, copies (chown)
1812
usr/grp ownership from 'ownership_src' to 'path'"""
1808
"""creates the directory 'path' with specified ownership.
1809
If ownership_src is given, copies (chown) usr/grp ownership
1810
from 'ownership_src' to 'path'. If ownership_src is None, use the
1811
containing dir ownership"""
1814
if ownership_src != None:
1815
copy_ownership(path, ownership_src)
1813
copy_ownership(path, ownership_src)
1817
1816
def open_with_ownership(filename, mode='r', bufsize=-1, ownership_src=None):
1818
"""This function wraps the python builtin open. filename, mode and bufsize
1819
parameters behave the same as the builtin open[1]. If ownership_src is
1820
given, copies (chown) usr/grp ownership from 'ownership_src' to 'filename'.
1821
[1] http://python.org/doc/2.6.4/library/functions.html#open"""
1817
"""open a file with the specified ownership.
1818
If ownership_src is specified, copy usr/grp ownership from ownership_src
1819
to filename. If ownership_src is None, copy ownership from containing
1822
1821
f = open(filename, mode, bufsize)
1823
if ownership_src != None:
1824
copy_ownership(filename, ownership_src)
1822
copy_ownership(filename, ownership_src)