File: __init__.py

package info (click to toggle)
jupyter-core 4.7.1-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 612 kB
  • sloc: python: 1,606; makefile: 167; sh: 77; javascript: 1
file content (16 lines) | stat: -rw-r--r-- 518 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import errno
import os

def ensure_dir_exists(path, mode=0o777):
    """ensure that a directory exists
    If it doesn't exist, try to create it, protecting against a race condition
    if another process is doing the same.
    The default permissions are determined by the current umask.
    """
    try:
        os.makedirs(path, mode=mode)
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise
    if not os.path.isdir(path):
        raise IOError("%r exists but is not a directory" % path)