def makedirs_(path, user=None, group=None, mode=None):
 path = os.path.expanduser(path)
 dirname = os.path.normpath(os.path.dirname(path))
 if os.path.isdir(dirname):
  msg = "Directory '{0}' already exists".format(dirname)
  log.debug(msg)
  return msg
 if os.path.exists(dirname):
  msg = "The path '{0}' already exists and is not a directory".format(dirname)
  log.debug(msg)
  return msg
 directories_to_create = []
 while True:
  if os.path.isdir(dirname):
   break
  directories_to_create.append(dirname)
  current_dirname = dirname
  dirname = os.path.dirname(dirname)
  if (current_dirname == dirname):
   raise SaltInvocationError("Recursive creation for path '{0}' would result in an infinite loop. Please use an absolute path.".format(dirname))
 directories_to_create.reverse()
 for directory_to_create in directories_to_create:
  log.debug('Creating directory: %s', directory_to_create)
  mkdir(directory_to_create, user=user, group=group, mode=mode)

def makedirs_ ( path , user = None , group = None , mode = None ) : path = os . path . expanduser ( path ) dirname = os . path . normpath ( os . path . dirname ( path ) ) if os . path . isdir ( dirname ) : msg = "Directory '{0}' already exists" . format ( dirname ) log . debug ( msg ) return msg if os . path . exists ( dirname ) : msg = "The path '{0}' already exists and is not a directory" . format ( dirname ) log . debug ( msg ) return msg directories_to_create = [ ] while True : if os . path . isdir ( dirname ) : break directories_to_create . append ( dirname ) current_dirname = dirname dirname = os . path . dirname ( dirname ) if ( current_dirname == dirname ) : raise SaltInvocationError ( "Recursive creation for path '{0}' would result in an infinite loop. Please use an absolute path." . format ( dirname ) ) directories_to_create . reverse ( ) for directory_to_create in directories_to_create : log . debug ( 'Creating directory: %s' , directory_to_create ) mkdir ( directory_to_create , user = user , group = group , mode = mode )
ensure that the directory containing this path is available .