From 23963607312a888fc1c1949537497aa951b421c5 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 21 Oct 2018 15:18:41 -0400 Subject: Helpers for making directories --- coverage/misc.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'coverage/misc.py') diff --git a/coverage/misc.py b/coverage/misc.py index a923829d..59114863 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -8,6 +8,7 @@ import hashlib import inspect import locale import os +import os.path import re import sys import types @@ -181,6 +182,20 @@ def file_be_gone(path): raise +def ensure_dir(directory): + """Make sure the directory exists. + + If `directory` is None or empty, do nothing. + """ + if directory and not os.path.isdir(directory): + os.makedirs(directory) + + +def ensure_dir_for_file(path): + """Make sure the directory for the path exists.""" + ensure_dir(os.path.dirname(path)) + + def output_encoding(outfile=None): """Determine the encoding to use for output written to `outfile` or stdout.""" if outfile is None: -- cgit v1.2.1