Esempio n. 1
0
async def main() -> None:
    args = parser.parse_args()

    boot_info = BootInfo.from_namespace(args)

    if not boot_info.base_dir.exists():
        if boot_info.is_ephemeral or get_xdg_data_home(
        ) in boot_info.base_dir.parents:
            boot_info.base_dir.mkdir(exist_ok=True)
        else:
            raise FileNotFoundError(
                "Not creating DDHT root directory as it is not present and is "
                f"not under the $XDG_DATA_HOME: {boot_info.base_dir}")

    if args.log_file is None:
        logdir = log_file = get_xdg_ddht_root() / "logs"
        logdir.mkdir(parents=True, exist_ok=True)

        log_file = logdir / "ddht.log"
    else:
        log_file = args.log_file

    setup_logging(log_file, args.log_level_file, args.log_level_stderr)

    logger.info(DDHT_HEADER)

    try:
        await args.func(boot_info)
    finally:
        if boot_info.is_ephemeral:
            shutil.rmtree(boot_info.base_dir)
Esempio n. 2
0
    def from_cli_args(cls, args: Sequence[str]) -> "AlexandriaBootInfo":
        # Import here to prevent circular imports
        from ddht.cli_parser import parser

        namespace = parser.parse_args(args)
        return cls.from_namespace(namespace)