Given a path to a filename, make sure the directory exists

def _mkdir_for_config(cfg_file=cfg_file):
    """ Given a path to a filename, make sure the directory exists """
    dirname, filename = os.path.split(cfg_file)
    try:
        os.makedirs(dirname)
    except OSError as exc:
        if exc.errno == errno.EEXIST and os.path.isdir(dirname):
            pass
        else:
            raise