helper function for python 2 and 3 to call os.makedirs()
       avoiding an error if the directory to be created already exists
504789
def makedirs(name):
    """"""

    import os, errno

    try:
        os.makedirs(name)
    except OSError as ex:
        if ex.errno == errno.EEXIST and os.path.isdir(name):
            # ignore existing directory
            pass
        else:
            # a different error happened
            raise
553623
def make_dirs_if_dont_exist(path):
    
    if path[-1] not in ['/']: path += '/'
    path = os.path.dirname(path)
    if path != '':
        try: os.makedirs(path)
        except OSError: pass
1316270
def makedirs(name, mode=0o777, exist_ok=False):
    

    if os.path.exists(name):
        if not exist_ok:
            raise FileExistsError("File exists: " + name)
    else:
        os.makedirs(name, mode)
1042261
def create_directory(self, filename):
        """"""
        path = os.path.join(self.path, filename)
        makedirs(path)
        return path
586497
def check_dir():
    
    try:
        os.makedirs(reports_dir)
        logger.info('Creating reports directory: %s', reports_dir)
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise
558427
def make_dir(dst_dir, dry_run, print_func, recursed):
    
    parent = os.path.split(dst_dir.rstrip('/'))[0] # Check for nonexistent parent
    parent_files = auto(listdir_stat, parent) if parent else True # Relative dir
    if dry_run:
        if recursed: # Assume success: parent not actually created yet
            print_func("Creating directory {}".format(dst_dir))
        elif parent_files is None:
            print_func("Unable to create {}".format(dst_dir))
        return True
    if not mkdir(dst_dir):
        print_err("Unable to create {}".format(dst_dir))
        return False
    return True
298314
def ensure_directory_exists(directory):
  '''
  '''
  if not os.path.exists(directory):
    os.makedirs(directory)
  elif os.path.isfile(directory):
    raise RuntimeError('Path %s is a file, not a directory.' % directory)
646215
def create_directory(directory):
    """"""
    if os.path.exists(directory):
        rmtree(directory)
    os.makedirs(directory)
    return directory
542084
def command_mkdir(args):
    
    errors = 0
    for directory in args.dirs:
        if os.path.exists(directory):
            if not os.path.isdir(directory):
                # -- SANITY CHECK: directory exists, but as file...
                sys.stdout.write("mkdir: %s\n" % directory)
                sys.stdout.write("ERROR: Exists already, but as file...\n")
                errors += 1
        else:
            # -- NORMAL CASE: Directory does not exits yet.
            assert not os.path.isdir(directory)
            sys.stdout.write("mkdir: %s\n" % directory)
            os.makedirs(directory)
    return errors
451582
def ensure_outdir_exists(filepath):
    
    outdir = os.path.dirname(filepath)

    if outdir and not os.path.exists(outdir):
        LOGGER.debug("Making output dir: %s", outdir)
        os.makedirs(outdir)
364616
def ensure_path_exists(dir_path):
    
    if not os.path.exists(dir_path):
        os.makedirs(dir_path)
        return True
    return False
1028890
def safe_makedirs(path):
    
    if not os.path.exists(path):
        try:
            os.makedirs(path)
        except OSError:
            if not os.path.exists(path):
                raise
1085842
def try_to_create_directory(directory_path):
    
    logger = logging.getLogger("ray")
    directory_path = os.path.expanduser(directory_path)
    if not os.path.exists(directory_path):
        try:
            os.makedirs(directory_path)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise e
            logger.warning(
                "Attempted to create '{}', but the directory already "
                "exists.".format(directory_path))
        # Change the log directory permissions so others can use it. This is
        # important when multiple people are using the same machine.
    try:
        os.chmod(directory_path, 0o0777)
    except OSError as e:
        # Silently suppress the PermissionError that is thrown by the chmod.
        # This is done because the user attempting to change the permissions
        # on a directory may not own it. The chmod is attempted whether the
        # directory is new or not to avoid race conditions.
        # ray-project/ray/#3591
        if e.errno in [errno.EACCES, errno.EPERM]:
            pass
        else:
            raise
899941
def make(self):
        
        try:
            if not self.exists:
                logger.info("Creating %s" % self.path)
                os.makedirs(self.path)
        except os.error:
            pass
        return self
1280832
def create_and_validate_dir(data_dir):
    '''
    '''
    if data_dir != "":
        if not os.path.exists(data_dir):
            try:
                logging.info('create directory %s', data_dir)
                os.makedirs(data_dir)
            except OSError as exc:
                if exc.errno != errno.EEXIST:
                    raise OSError('failed to create ' + data_dir)
448540
def makedirs(d):
    """"""
    if sys.version_info[0] < 3:
        from distutils.dir_util import mkpath
        mkpath(d)
    else:
        os.makedirs(d, exist_ok=True)
913509
def make_dir(self):
        """"""
        if not os.path.exists(self.dirname):
            os.makedirs(self.dirname)