/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Parth Malwankar
  • Date: 2010-03-06 05:28:17 UTC
  • mto: (5094.3.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5107.
  • Revision ID: parth.malwankar@gmail.com-20100306052817-5ygp4co5l6frp0d1
removed parent_dir.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1785
1785
            real_handlers[kind](abspath, relpath)
1786
1786
 
1787
1787
 
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)
1792
 
    if pdir == '':
1793
 
        pdir = '.'
1794
 
    return pdir
1795
 
 
1796
 
 
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':
1801
1792
        return False
 
1793
 
 
1794
    if src == None:
 
1795
        src = os.path.dirname(dst)
 
1796
        if src == '':
 
1797
            src = '.'
 
1798
 
1802
1799
    try:
1803
1800
        s = os.stat(src)
1804
1801
        os.chown(dst, s.st_uid, s.st_gid)
1808
1805
 
1809
1806
 
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"""
1813
1812
    os.mkdir(path)
1814
 
    if ownership_src != None:
1815
 
        copy_ownership(path, ownership_src)
 
1813
    copy_ownership(path, ownership_src)
 
1814
 
1816
1815
 
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
 
1820
    directory."""
1822
1821
    f = open(filename, mode, bufsize)
1823
 
    if ownership_src != None:
1824
 
        copy_ownership(filename, ownership_src)
 
1822
    copy_ownership(filename, ownership_src)
1825
1823
    return f
1826
1824
 
1827
1825