예제 #1
0
def _load(f: TextIOBase, close) -> Configuration:
    # here's the thing -- it's just python!
    try:
        source = f.read()
    finally:
        if close:
            f.close()

    config = Configuration()
    value_cap = ConfigHandler(config, config.is_config_value)
    # capture configuration values
    # the code should define a method called "configure"
    # that method will be called with the config obj as the only argument
    cfg_vars = {}
    exec(source, cfg_vars)

    if 'configure' not in cfg_vars:
        raise KeyError(
            "Configure code did not define a method named 'configure'")

    cfg_vars['configure'](value_cap)

    config.validate_values()

    return config
예제 #2
0
def get_next_output_file(book_output_path: str,
                         current_output_file: TextIOBase = None):

    global current_file_to_write

    if current_output_file is not None:
        current_output_file.close()

    open_new_file(book_output_path)

    return current_file_to_write