def makedirs_perms(name, user=None, group=None, mode='0755'):
 name = os.path.expanduser(name)
 path = os.path
 (head, tail) = path.split(name)
 if (not tail):
  (head, tail) = path.split(head)
 if (head and tail and (not path.exists(head))):
  try:
   makedirs_perms(head, user, group, mode)
  except OSError as exc:
   if (exc.errno != errno.EEXIST):
    raise
  if (tail == os.curdir):
   return
 os.mkdir(name)
 check_perms(name, None, user, group, (int('{0}'.format(mode)) if mode else None))

def makedirs_perms ( name , user = None , group = None , mode = '0755' ) : name = os . path . expanduser ( name ) path = os . path ( head , tail ) = path . split ( name ) if ( not tail ) : ( head , tail ) = path . split ( head ) if ( head and tail and ( not path . exists ( head ) ) ) : try : makedirs_perms ( head , user , group , mode ) except OSError as exc : if ( exc . errno != errno . EEXIST ) : raise if ( tail == os . curdir ) : return os . mkdir ( name ) check_perms ( name , None , user , group , ( int ( '{0}' . format ( mode ) ) if mode else None ) )
set owner and permissions for each directory created .