

def build_directory(dct, force=False, topdir='.'):
    "Create a directory structure based on the contents of a nested dict.\n    The directory is created in the specified top directory or in the current\n    working directory if one isn't specified. If a file being created already\n    exists, a warning will be issued and the file will not be changed if force\n    is False. If force is True, the file will be overwritten.\n\n    The structure of the dict is as follows: if the value at a key is a\n    dict, then that key is used to create a directory. Otherwise, the key is\n    used to create a file, and the value stored at that key is written to the\n    file. All keys must be relative names or a RuntimeError will be raised.\n\n    Args\n    ----\n    dct : dict\n        Dictionary containing nested folder structure.\n    force : bool, optional\n        Set to True to overwrite existing files\n    topdir : string, optional\n        Specify a top directory.\n    "
    startdir = os.getcwd()
    topdir = os.path.abspath(topdir)
    try:
        for (key, val) in iteritems(dct):
            os.chdir(topdir)
            if os.path.isabs(key):
                raise RuntimeError(('build_directory: key (%s) is not a relative name' % key))
            if isinstance(val, dict):
                if (not os.path.exists(key)):
                    os.makedirs(key)
                os.chdir(key)
                build_directory(val, force)
            elif (os.path.exists(key) and (force is False)):
                warnings.warn(("File '%s' already exists and will not be overwritten." % key), Warning)
            else:
                dname = os.path.dirname(key)
                if (dname and (not os.path.isdir(dname))):
                    os.makedirs(dname)
                with open(key, 'w') as f:
                    f.write(val)
    finally:
        os.chdir(startdir)

dataset/ETHPy150Open OpenMDAO/OpenMDAO/openmdao/util/file_util.py build_directory/original