wuttasync.cli.base¶
wutta import-csv command
- class wuttasync.cli.base.ImportCommandHandler(config, import_handler=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_handlerdo it.- Parameters:
import_handler –
During construction, caller can specify the
import_handleras any of:import handler instance
import handler factory (e.g. class)
import handler spec (cf.
load_object())
For example:
handler = ImportCommandHandler( config, import_handler='wuttasync.importing.csv:FromCsvToWutta')
- 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(params, progress=None)[source]¶
Run the import/export job(s) based on command line params.
This mostly just calls
process_data()for theimport_handler.Unless
--list-modelswas specified on the command line in which case we dolist_models()instead.- Parameters:
params – Dict of params from command line. This must include a
'models'key, the rest are optional.progress – Optional progress indicator factory.
- 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 thefile_import_commanddecorator.
- wuttasync.cli.base.file_import_command_template(input_file_path: ~pathlib.Annotated[~pathlib.Path, <typer.models.OptionInfo object at 0x7ffb2c75a250>] = 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-foocommand: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 0x7ffb2ddf89d0>] = None, list_models: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7ffb2ddf8a50>] = False, create: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7ffb2c758f50>] = True, update: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7ffb2c759090>] = True, delete: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7ffb2c759250>] = False, fields: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7ffb2c7593d0>] = None, excluded_fields: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7ffb2c759590>] = None, keys: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7ffb2c759750>] = None, max_create: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7ffb2c759910>] = None, max_update: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7ffb2c759ad0>] = None, max_delete: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7ffb2c759c50>] = None, max_total: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7ffb2c759e50>] = None, dry_run: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7ffb2c75a050>] = False)[source]¶
Stub function which provides a common param signature; used with
import_command().