rechu.command package

Subpackages

Submodules

rechu.command.alembic module

Subcommand to run Alembic commands for database migration.

final class rechu.command.alembic.Alembic[source]

Bases: Base

Run an alembic command.

run() None[source]

Execute the command.

subcommand: str = 'alembic'
subparser_arguments: ClassVar[Iterable[tuple[str | tuple[str, ...], ArgumentKeywords]]] = [('args', {'help': 'alembic arguments', 'nargs': '*'})]
subparser_keywords: ClassVar[SubparserKeywords] = {'add_help': False, 'help': 'Perform database revision management', 'prefix_chars': '\x00'}

rechu.command.base module

Base for receipt subcommands.

class rechu.command.base.ArgumentKeywords[source]

Bases: TypedDict

Keyword arguments acceptable for registering an argument to a subparser of an argument parser.

action: str
choices: Iterable[Any] | None
const: Any
default: Any
dest: str | None
help: str | None
metavar: str | tuple[str, ...] | None
nargs: int | str | None
required: bool
type: Callable[[str], Any]
class rechu.command.base.Base[source]

Bases: Namespace

Abstract command handling.

classmethod get_command(name: str) Base[source]

Create a command instance for the given subcommand name.

logger: Logger
program: str = 'rechu'
classmethod register(name: str) Callable[[type[CommandT]], type[CommandT]][source]

Register a subcommand.

classmethod register_arguments() ArgumentParser[source]

Create an argument parser for all registered subcommands.

abstractmethod run() None[source]

Execute the command.

settings: Settings
classmethod start(executable: str, argv: Sequence[str]) None[source]

Parse arguments from a sequence of command line arguments and determine which command to run, register any arguments to it and finally execute the action of the command.

subcommand: str = ''
subparser_arguments: ClassVar[Iterable[tuple[str | tuple[str, ...], ArgumentKeywords]]] = []
subparser_keywords: ClassVar[SubparserKeywords] = {}
class rechu.command.base.SubparserKeywords[source]

Bases: TypedDict

Keyword arguments acceptable for subcommands to register to a subparser of an argument parser.

add_help: bool
aliases: Sequence[str]
allow_abbrev: bool
description: str | None
epilog: str | None
fromfile_prefix_chars: str | None
help: str | None
prefix_chars: str

rechu.command.config module

Subcommand to generate an amalgamate settings file.

final class rechu.command.config.Config[source]

Bases: Base

Obtain settings file representation.

run() None[source]

Execute the command.

subcommand: str = 'config'
subparser_arguments: ClassVar[Iterable[tuple[str | tuple[str, ...], ArgumentKeywords]]] = [(('section',), {'help': 'Optional table section name to filter on', 'metavar': 'SECTION', 'nargs': '?'}), (('key',), {'help': 'Optional settings key to filter on', 'metavar': 'KEY', 'nargs': '?'}), (('-f', '--file'), {'help': 'Generate based on specific TOML file'}), (('-p', '--prefix'), {'default': (), 'help': 'Section prefixes in specific TOML file to look up', 'nargs': '+'})]
subparser_keywords: ClassVar[SubparserKeywords] = {'description': 'Generate settings TOML representation with comments.', 'help': 'Obtain settings representation'}

rechu.command.create module

Database schema creation subcommand.

final class rechu.command.create.Create[source]

Bases: Base

Create the database with the database schema.

run() None[source]

Execute the command.

subcommand: str = 'create'
subparser_keywords: ClassVar[SubparserKeywords] = {'description': 'Create database schema tables at the configured URI.', 'help': 'Create the database and schema'}

rechu.command.delete module

Subcommand to remove receipt YAML file(s) from data path and database.

final class rechu.command.delete.Delete[source]

Bases: Base

Delete YAML files and database entries for receipts.

run() None[source]

Execute the command.

subcommand: str = 'delete'
subparser_arguments: ClassVar[Iterable[tuple[str | tuple[str, ...], ArgumentKeywords]]] = [('files', {'help': 'One or more files to delete', 'metavar': 'FILE', 'nargs': '+'}), (('-k', '--keep'), {'action': 'store_true', 'default': False, 'help': 'Do not delete YAML file from data path'})]
subparser_keywords: ClassVar[SubparserKeywords] = {'aliases': ['rm'], 'description': 'Delete receipts from the YAML data paths and from the database.', 'help': 'Delete receipt files and/or database entries'}

rechu.command.dump module

Subcommand to export database entries as YAML files.

final class rechu.command.dump.Dump[source]

Bases: Base

Dump YAML files from the database.

run() None[source]

Execute the command.

subcommand: str = 'dump'
subparser_arguments: ClassVar[Iterable[tuple[str | tuple[str, ...], ArgumentKeywords]]] = [('files', {'help': 'One or more product inventories or receipts to write; if no filenames are given, then dump the entire database', 'metavar': 'FILE', 'nargs': '*'})]
subparser_keywords: ClassVar[SubparserKeywords] = {'description': 'Create one or more YAML files based on database state.', 'help': 'Export entities from the database'}

rechu.command.match module

Subcommand to match entities in the database.

final class rechu.command.match.Match[source]

Bases: Base

Update entities with references to metadata based on matching patterns.

run() None[source]

Execute the command.

subcommand: str = 'match'
subparser_arguments: ClassVar[Iterable[tuple[str | tuple[str, ...], ArgumentKeywords]]] = [(('-u', '--update'), {'action': 'store_true', 'default': False, 'help': 'Also update existing matched product references'})]
subparser_keywords: ClassVar[SubparserKeywords] = {'description': 'Match products based on labels, prices and discounts and connect the items to their product metadata.', 'help': 'Connect receipt product items to metadata'}

rechu.command.read module

Subcommand to import receipt YAML files.

final class rechu.command.read.Read[source]

Bases: Base

Read updated YAML files and import them to the database.

run() None[source]

Execute the command.

subcommand: str = 'read'
subparser_keywords: ClassVar[SubparserKeywords] = {'description': 'Find YAML files for products and receipts stored in the data paths and import new or updated entities to the database.', 'help': 'Import updated product and receipt files to the database'}
rechu.command.read.get_updated_time(path: Path) datetime[source]

Retrieve the latest modification time of a file or directory in the path as a datetime object.

Module contents

Subcommand collection package.

class rechu.command.Alembic[source]

Bases: Base

Run an alembic command.

args: list[str]
logger: logging.Logger
run() None[source]

Execute the command.

settings: Settings
subcommand: str = 'alembic'
subparser_arguments: ClassVar[Iterable[tuple[str | tuple[str, ...], ArgumentKeywords]]] = [('args', {'help': 'alembic arguments', 'nargs': '*'})]
subparser_keywords: ClassVar[SubparserKeywords] = {'add_help': False, 'help': 'Perform database revision management', 'prefix_chars': '\x00'}
class rechu.command.Base[source]

Bases: Namespace

Abstract command handling.

classmethod get_command(name: str) Base[source]

Create a command instance for the given subcommand name.

logger: Logger
program: str = 'rechu'
classmethod register(name: str) Callable[[type[CommandT]], type[CommandT]][source]

Register a subcommand.

classmethod register_arguments() ArgumentParser[source]

Create an argument parser for all registered subcommands.

abstractmethod run() None[source]

Execute the command.

settings: Settings
classmethod start(executable: str, argv: Sequence[str]) None[source]

Parse arguments from a sequence of command line arguments and determine which command to run, register any arguments to it and finally execute the action of the command.

subcommand: str = ''
subparser_arguments: ClassVar[Iterable[tuple[str | tuple[str, ...], ArgumentKeywords]]] = []
subparser_keywords: ClassVar[SubparserKeywords] = {}
class rechu.command.Config[source]

Bases: Base

Obtain settings file representation.

file: str
key: str
logger: logging.Logger
prefix: tuple[str, ...]
run() None[source]

Execute the command.

section: str
settings: Settings
subcommand: str = 'config'
subparser_arguments: ClassVar[Iterable[tuple[str | tuple[str, ...], ArgumentKeywords]]] = [(('section',), {'help': 'Optional table section name to filter on', 'metavar': 'SECTION', 'nargs': '?'}), (('key',), {'help': 'Optional settings key to filter on', 'metavar': 'KEY', 'nargs': '?'}), (('-f', '--file'), {'help': 'Generate based on specific TOML file'}), (('-p', '--prefix'), {'default': (), 'help': 'Section prefixes in specific TOML file to look up', 'nargs': '+'})]
subparser_keywords: ClassVar[SubparserKeywords] = {'description': 'Generate settings TOML representation with comments.', 'help': 'Obtain settings representation'}
class rechu.command.Create[source]

Bases: Base

Create the database with the database schema.

logger: logging.Logger
run() None[source]

Execute the command.

settings: Settings
subcommand: str = 'create'
subparser_keywords: ClassVar[SubparserKeywords] = {'description': 'Create database schema tables at the configured URI.', 'help': 'Create the database and schema'}
class rechu.command.Delete[source]

Bases: Base

Delete YAML files and database entries for receipts.

files: list[str]
logger: logging.Logger
run() None[source]

Execute the command.

settings: Settings
subcommand: str = 'delete'
subparser_arguments: ClassVar[Iterable[tuple[str | tuple[str, ...], ArgumentKeywords]]] = [('files', {'help': 'One or more files to delete', 'metavar': 'FILE', 'nargs': '+'}), (('-k', '--keep'), {'action': 'store_true', 'default': False, 'help': 'Do not delete YAML file from data path'})]
subparser_keywords: ClassVar[SubparserKeywords] = {'aliases': ['rm'], 'description': 'Delete receipts from the YAML data paths and from the database.', 'help': 'Delete receipt files and/or database entries'}
class rechu.command.Dump[source]

Bases: Base

Dump YAML files from the database.

files: list[str]
logger: logging.Logger
run() None[source]

Execute the command.

settings: Settings
subcommand: str = 'dump'
subparser_arguments: ClassVar[Iterable[tuple[str | tuple[str, ...], ArgumentKeywords]]] = [('files', {'help': 'One or more product inventories or receipts to write; if no filenames are given, then dump the entire database', 'metavar': 'FILE', 'nargs': '*'})]
subparser_keywords: ClassVar[SubparserKeywords] = {'description': 'Create one or more YAML files based on database state.', 'help': 'Export entities from the database'}
class rechu.command.Match[source]

Bases: Base

Update entities with references to metadata based on matching patterns.

logger: logging.Logger
run() None[source]

Execute the command.

settings: Settings
subcommand: str = 'match'
subparser_arguments: ClassVar[Iterable[tuple[str | tuple[str, ...], ArgumentKeywords]]] = [(('-u', '--update'), {'action': 'store_true', 'default': False, 'help': 'Also update existing matched product references'})]
subparser_keywords: ClassVar[SubparserKeywords] = {'description': 'Match products based on labels, prices and discounts and connect the items to their product metadata.', 'help': 'Connect receipt product items to metadata'}
class rechu.command.New[source]

Bases: Base

Create a YAML file for a receipt and import it to the database.

run() None[source]

Execute the command.

subcommand: str = 'new'
subparser_arguments: ClassVar[Iterable[tuple[str | tuple[str, ...], ArgumentKeywords]]] = [(('-c', '--confirm'), {'action': 'store_true', 'default': False, 'help': 'Confirm before updating database files or exiting'}), (('-m', '--more'), {'action': 'store_true', 'default': False, 'help': 'Allow more discounts and metadata than product items'})]
subparser_keywords: ClassVar[SubparserKeywords] = {'description': 'Interactively fill in a YAML file for a receipt and import it to the database.', 'help': 'Create receipt file and import'}
class rechu.command.Read[source]

Bases: Base

Read updated YAML files and import them to the database.

logger: logging.Logger
run() None[source]

Execute the command.

settings: Settings
shops: Inventory[Shop]
subcommand: str = 'read'
subparser_keywords: ClassVar[SubparserKeywords] = {'description': 'Find YAML files for products and receipts stored in the data paths and import new or updated entities to the database.', 'help': 'Import updated product and receipt files to the database'}