def makedirs_with_parent_perms(p):
 p = os.path.abspath(p)
 parent = os.path.dirname(p)
 if ((not os.path.exists(p)) and p and (parent != p)):
  makedirs_with_parent_perms(parent)
  s = os.stat(parent)
  os.mkdir(p)
  s2 = os.stat(p)
  if ((s.st_uid != s2.st_uid) or (s.st_gid != s2.st_gid)):
   os.chown(p, s.st_uid, s.st_gid)
  if (s.st_mode != s2.st_mode):
   os.chmod(p, s.st_mode)

def makedirs_with_parent_perms ( p ) : p = os . path . abspath ( p ) parent = os . path . dirname ( p ) if ( ( not os . path . exists ( p ) ) and p and ( parent != p ) ) : makedirs_with_parent_perms ( parent ) s = os . stat ( parent ) os . mkdir ( p ) s2 = os . stat ( p ) if ( ( s . st_uid != s2 . st_uid ) or ( s . st_gid != s2 . st_gid ) ) : os . chown ( p , s . st_uid , s . st_gid ) if ( s . st_mode != s2 . st_mode ) : os . chmod ( p , s . st_mode )
create the directory using the permissions of the nearest parent directory .