Skip to content

nbautoexport.sentinel

install_sentinel(directory, config, overwrite)

Writes the configuration file to a specified directory.

Source code in /home/runner/work/nbautoexport/nbautoexport/nbautoexport/sentinel.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def install_sentinel(directory: Path, config: NbAutoexportConfig, overwrite: bool):
    """Writes the configuration file to a specified directory."""
    sentinel_path = directory / SAVE_PROGRESS_INDICATOR_FILE

    if sentinel_path.exists() and (not overwrite):
        raise FileExistsError(
            f"""Detected existing autoexport configuration at {sentinel_path}. """
            """If you wish to overwrite, use the --overwrite flag."""
        )
    else:
        logger.info(f"Creating configuration file at {sentinel_path}")
        logger.info(f"\n{config.json(indent=2)}")
        with sentinel_path.open("w", encoding="utf-8") as fp:
            fp.write(config.json(indent=2))