Python ensure dirs

21 Python code examples are found related to " ensure dirs". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: persist.py    From ngraph-python with Apache License 2.0 6 votes vote down vote up
def ensure_dirs_exist(path):
    """
    Simple helper that ensures that any directories specified in the path are
    created prior to use.

    Arguments:
        path (str): the path (may be to a file or directory).  Any intermediate
                    directories will be created.

    Returns:
        str: The unmodified path value.
    """
    outdir = os.path.dirname(path)
    if outdir != '' and not os.path.isdir(outdir):
        os.makedirs(outdir)
    return path 
Example 2
Source File: compat.py    From pipenv with MIT License 6 votes vote down vote up
def ensure_resolution_dirs(**kwargs):
    # type: (Any) -> Iterator[Dict[str, Any]]
    """
    Ensures that the proper directories are scaffolded and present in the provided kwargs
    for performing dependency resolution via pip.

    :return: A new kwargs dictionary with scaffolded directories for **build_dir**, **src_dir**,
        **download_dir**, and **wheel_download_dir** added to the key value pairs.
    :rtype: Dict[str, Any]
    """
    keys = ("build_dir", "src_dir", "download_dir", "wheel_download_dir")
    if not any(kwargs.get(key) is None for key in keys):
        yield kwargs
    else:
        with TemporaryDirectory(prefix="pip-shims-") as base_dir:
            for key in keys:
                if kwargs.get(key) is not None:
                    continue
                target = os.path.join(base_dir, key)
                os.makedirs(target)
                kwargs[key] = target
            yield kwargs 
Example 3
Source File: base.py    From FeelUOwn with GNU General Public License v3.0 5 votes vote down vote up
def ensure_dirs():
    for d in (HOME_DIR,
              DATA_DIR,
              USER_THEMES_DIR,
              USER_PLUGINS_DIR,
              CACHE_DIR,
              SONG_DIR,
              COLLECTIONS_DIR):
        if not os.path.exists(d):
            os.mkdir(d) 
Example 4
Source File: cli.py    From fediplay with MIT License 5 votes vote down vote up
def ensure_dirs():
    '''Make sure the application directories exist.'''

    if not path.exists(DIRS.user_config_dir):
        os.makedirs(DIRS.user_config_dir)

    if not path.exists(DIRS.user_cache_dir):
        os.makedirs(DIRS.user_cache_dir) 
Example 5
Source File: appveyor-download.py    From python-fields with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def ensure_dirs(filename):
    """Make sure the directories exist for `filename`."""
    dirname = os.path.dirname(filename)
    if dirname and not os.path.exists(dirname):
        os.makedirs(dirname) 
Example 6
Source File: android.py    From fips with MIT License 5 votes vote down vote up
def ensure_sdk_dirs(fips_dir) :
    if not os.path.isdir(get_sdk_dir(fips_dir)) :
        os.makedirs(get_sdk_dir(fips_dir))

#------------------------------------------------------------------------------- 
Example 7
Source File: app.py    From pypath with GNU General Public License v3.0 5 votes vote down vote up
def ensure_dirs(self):
        """
        Checks if the directories for tables, figures and pickles exist and
        creates them if necessary.
        """

        if self.get_param('timestamp_dirs'):

            self.tables_dir = os.path.join(
                self.get_param('tables_dir'),
                self.timestamp
            )
            self.figures_dir = os.path.join(
                self.get_param('figures_dir'),
                self.timestamp,
            )
            settings.setup(
                tables_dir = self.tables_dir,
                figures_dir = self.figures_dir,
            )

        os.makedirs(self.get_param('pickle_dir'), exist_ok = True)

        for _dir in ('pickle', 'tables', 'figures'):

            path = self.get_param('%s_dir' % _dir)
            self._log(
                '%s directory: `%s` (exists: %s).' % (
                    _dir.capitalize(),
                    path,
                    'yes' if os.path.exists(path) else 'no',
                )
            ) 
Example 8
Source File: detection_database.py    From agents-aea with Apache License 2.0 5 votes vote down vote up
def ensure_dirs_exist(self):
        """Test if we have our temp directotries, and if we don't create them."""
        if not os.path.isdir(self.temp_dir):
            os.mkdir(self.temp_dir)
        if not os.path.isdir(self.raw_image_dir):
            os.mkdir(self.raw_image_dir)
        if not os.path.isdir(self.processed_image_dir):
            os.mkdir(self.processed_image_dir) 
Example 9
Source File: download_appveyor.py    From coveragepy with Apache License 2.0 5 votes vote down vote up
def ensure_dirs(filename):
    """Make sure the directories exist for `filename`."""
    dirname, _ = os.path.split(filename)
    if dirname and not os.path.exists(dirname):
        os.makedirs(dirname) 
Example 10
Source File: helpers.py    From rdopkg with Apache License 2.0 5 votes vote down vote up
def ensure_new_file_dirs(path):
    if path[-1] == os.sep:
        raise exception.NotAFile(path=path)
    _dir = os.path.dirname(path)
    if _dir:
        ensure_dir(_dir) 
Example 11
Source File: generate_website_2_data.py    From nototools with Apache License 2.0 5 votes vote down vote up
def ensure_target_dirs_exist(self):
        def mkdirs(p):
            if not path.exists(p):
                os.makedirs(p)

        mkdirs(self.target)
        mkdirs(self.pkgs)
        mkdirs(self.css)
        mkdirs(self.fonts)
        mkdirs(self.samples)
        mkdirs(self.data)
        if self.pretty_json:
            mkdirs(path.join(self.data, "pretty")) 
Example 12
Source File: dataloader.py    From models with MIT License 5 votes vote down vote up
def ensure_dirs(fname):
    """Ensure that the basepath of the given file path exists.

    Args:
      fname: (full) file path
    """
    required_path = "/".join(fname.split("/")[:-1])
    if not os.path.exists(required_path):
        os.makedirs(required_path) 
Example 13
Source File: models.py    From mhw_armor_edit with The Unlicense 5 votes vote down vote up
def ensure_dirs(self, rel_path):
        abs_path, _ = self.get_child_path(rel_path)
        dir_path = os.path.dirname(abs_path)
        try:
            os.makedirs(dir_path)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise 
Example 14
Source File: io.py    From cadasta-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
def ensure_dirs():
    path = os.path.join(settings.MEDIA_ROOT, 'temp')
    if not os.path.exists(path):
        os.makedirs(path)
    return path 
Example 15
Source File: io.py    From winapi-deobfuscation with GNU Lesser General Public License v3.0 5 votes vote down vote up
def ensure_dirs(directory):
	"""
	Recursive version of ensure_dir
	"""
	if not os.path.isdir(directory):
		os.makedirs(directory) 
Example 16
Source File: utils.py    From 2D-Motion-Retargeting with MIT License 5 votes vote down vote up
def ensure_dirs(paths):
    """
    create paths by first checking their existence
    :param paths: list of path
    :return:
    """
    if isinstance(paths, list) and not isinstance(paths, str):
        for path in paths:
            ensure_dir(path)
    else:
        ensure_dir(paths)