rattail-demo/rattail_demo/commands.py
2024-05-15 15:34:42 -05:00

71 lines
1.9 KiB
Python

# -*- coding: utf-8; -*-
"""
Rattail Demo Commands
"""
import typer
from rattail.commands.typer import (typer_callback, typer_get_runas_user,
importer_command, file_exporter_command)
from rattail.commands.importing import ImportCommandHandler
# nb. this is the top-level command for titeship
rattail_demo_typer = typer.Typer(
callback=typer_callback,
help="Rattail Demo (custom Rattail system)"
)
@rattail_demo_typer.command()
@file_exporter_command
def export_shopfoo(
ctx: typer.Context,
**kwargs
):
"""
Export data to the Harvest system
"""
config = ctx.parent.rattail_config
progress = ctx.parent.rattail_progress
handler = ImportCommandHandler(
config, import_handler_spec='rattail_demo.shopfoo.importing.rattail:FromRattailToShopfoo')
kwargs['user'] = typer_get_runas_user(ctx)
kwargs['handler_kwargs'] = {'output_dir': kwargs['output_dir']}
handler.run(kwargs, progress=progress)
@rattail_demo_typer.command()
@importer_command
def import_self(
ctx: typer.Context,
**kwargs
):
"""
Update "cascading" Rattail data based on "core" Rattail data
"""
config = ctx.parent.rattail_config
progress = ctx.parent.rattail_progress
handler = ImportCommandHandler(
config, import_handler_spec='rattail_demo.importing.local:FromRattailDemoToSelf')
kwargs['user'] = typer_get_runas_user(ctx)
handler.run(kwargs, progress=progress)
@rattail_demo_typer.command()
def install(
ctx: typer.Context,
):
"""
Install the Rattail Demo app
"""
from rattail.install import InstallHandler
config = ctx.parent.rattail_config
handler = InstallHandler(config,
app_title="Rattail Demo",
app_package='rattail_demo',
app_eggname='rattail_demo',
app_pypiname='rattail_demo')
handler.run()