wuttasync.cli.base

wutta import-csv command

class wuttasync.cli.base.ImportCommandHandler(config, import_handler=None, key=None)[source]

This is the handler responsible for import/export command line runs.

Normally, the command (actually subcommand) logic will create this handler and call its run() method.

This handler does not know how to import/export data, but it knows how to make its import_handler do it. Likewise, the import handler is not “CLI-aware” - so this provides the glue.

Parameters:
  • import_handler

    During construction, caller can specify the import_handler as any of:

    • import handler instance

    • import handler factory (e.g. class)

    • import handler spec

  • key – Optional import/export key to use for handler lookup. Only used if import_handler param is not set.

Typical usage for custom commands will be to provide the spec:

handler = ImportCommandHandler(
    config, "poser.importing.foo:FromFooToPoser"
)

Library authors may prefer to use the import/export key; this lets the command work with any designated handler:

handler = ImportCommandHandler(
    config, key="import.to_poser.from_foo"
)

See also get_import_handler() which does the lookup by key.

import_handler = None

Reference to the import handler instance, which is to be invoked when command runs. See also run().

list_models(params)[source]

Query the import_handler’s supported target models and print the info to stdout.

This is what happens when command line has --list-models.

run(ctx, progress=None)[source]

Run the import/export job(s) based on command line params.

This mostly just calls process_data() for the import_handler.

Unless --list-models was specified on the command line in which case we do list_models() instead.

Parameters:
  • ctxtyper.Context instance.

  • progress – Optional progress indicator factory.

wuttasync.cli.base.file_export_command(fn)[source]

Decorator for file export commands. Adds common params based on file_export_command_template().

wuttasync.cli.base.file_export_command_template(output_file_path: ~pathlib.Annotated[~pathlib.Path, <typer.models.OptionInfo object at 0x7fe9c7609ed0>] = None)[source]

Stub function to provide signature for exporter commands which produce data file(s) as output. Used with file_export_command().

wuttasync.cli.base.file_import_command(fn)[source]

Decorator for import/export commands which require input file. Adds common params based on file_import_command_template().

To use this, it’s the same method as shown for import_command() except in this case you would use the file_import_command decorator.

wuttasync.cli.base.file_import_command_template(input_file_path: ~pathlib.Annotated[~pathlib.Path, <typer.models.OptionInfo object at 0x7fe9c7609fd0>] = None)[source]

Stub function to provide signature for import/export commands which require input file. Used with file_import_command().

wuttasync.cli.base.import_command(fn)[source]

Decorator for import/export commands. Adds common params based on import_command_template().

To use this, e.g. for poser import-foo command:

from poser.cli import poser_typer
from wuttasync.cli import import_command, ImportCommandHandler

@poser_typer.command()
@import_command
def import_foo(
        ctx: typer.Context,
        **kwargs
):
    """
    Import data from Foo API to Poser DB
    """
    config = ctx.parent.wutta_config
    handler = ImportCommandHandler(
        config, import_handler='poser.importing.foo:FromFooToPoser')
    handler.run(ctx.params)

See also ImportCommandHandler.

wuttasync.cli.base.import_command_template(models: ~typing.Annotated[~typing.List[str] | None, <typer.models.ArgumentInfo object at 0x7fe9c77fac90>] = None, list_models: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7fe9c77facd0>] = False, create: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7fe9c77fb7d0>] = True, update: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7fe9c77fb950>] = True, delete: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7fe9c77fbb50>] = False, fields: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7fe9c77fbd50>] = None, excluded_fields: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7fe9c77fbf50>] = None, keys: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7fe9c77f9990>] = None, max_create: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7fe9c7608210>] = None, max_update: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7fe9c76083d0>] = None, max_delete: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7fe9c7608590>] = None, max_total: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7fe9c7608750>] = None, warnings: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7fe9c7608910>] = False, warnings_recipients: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7fe9c7609bd0>] = None, warnings_max_diffs: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7fe9c7609cd0>] = 15, dry_run: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7fe9c7609dd0>] = False)[source]

Stub function which provides a common param signature; used with import_command().