in core/export.py [0:0]
def main(ctx: Ctx, log: Logger, dry_run: bool):
"""Export data to file or standard output."""
format = ctx.format
if format is None:
if ctx.file_name:
format = Path(ctx.file_name).suffix.lower()[1:]
log.debug(f"export file format guessed from file extension: {format}")
else:
format = "yaml"
log.debug(f"assuming export file format: {format}")
if dry_run:
return
node = ctx.get_binding("state").node
msg_state = "everything" if node is None else f"'{node}'"
msg_file_name = f"'{ctx.file_name}'" if ctx.file_name else "standard output"
log.info(f"exporting {msg_state} to {msg_file_name}...")
if ctx.file_name:
with open(Path(ctx.base_dir) / ctx.file_name, "w") as f:
serialize(f, ctx.state, format=format)
else:
serialize(sys.stdout, ctx.state, format=format)