Advertisement
Guest User

Untitled

a guest
Feb 18th, 2010
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. def parent_dir(path):
  2.     """same as os.path.dirname but returns '.' instead of ''
  3.    for paths that just have a filename in it e.g. 'foo'"""
  4.     pdir = os.path.dirname(path)
  5.     if pdir == '':
  6.         pdir = '.'
  7.     return pdir
  8.  
  9.  
  10. def copy_ownership(dst, src):
  11.     """copy user and group ownership from own_src file/dir to dst file/dir.
  12.    If own_src is None, the containing directory is used as source."""
  13.     if os.name != 'posix':
  14.         return False
  15.     try:
  16.         s = os.stat(src)
  17.         os.chown(dst, s.st_uid, s.st_gid)
  18.     except OSError, e:
  19.         warning("IOError: %s" % (e,))
  20.         warning("Unable to copy ownership from '%s' to '%s'" % (src, dst))
  21.     return True
  22.  
  23.  
  24. def mkdir(path, ownership_src=None):
  25.     """creates the directory 'path'. If ownership_src is given, copies (chown)
  26.    usr/grp ownership from 'ownership_src' to 'path'"""
  27.     os.mkdir(path)
  28.     if ownership_src != None:
  29.         copy_ownership(path, ownership_src)
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement