Add batch edit mode and flag

This commit is contained in:
2026-01-05 19:39:17 +10:00
parent 052f473855
commit c7d32520c4

View File

@@ -9,6 +9,8 @@ import toml
from tkinter import ttk
from platformdirs import PlatformDirs
from beanify.base.converter import SKIP, Converter
from .base.rules import DummyRuleInterface, JSONRuleInterface, RuleSet
from .gui import MainWindow
from .converters import converters_available, converter_factory
@@ -96,15 +98,12 @@ parser.add_argument(
default=None,
help="'json' or 'dummy'",
)
"""
TODO:
- [ ] Add parser arguments
- [ ] Find config file, or create and close
- [ ] Read available converters, read requested converter, make sure requested converter exists
- [ ] Create rule interface for requested converter, warn if dummy (support using system path)
- [ ] Load converter with options from config
"""
parser.add_argument(
"--batch",
dest="batch",
action="store_true",
help="Run the ingester in batch mode. The rule file must be complete. The ledger will be output to stdout.",
)
async def main():
@@ -207,10 +206,31 @@ async def main():
return
ruleset = RuleSet.load_from(rule_interface)
window = MainWindow(
config, converter, ruleset, initial_files=args.ingest, theme="clam"
)
window.mainloop()
if args.batch:
# Batch mode
batch_mode_process(config, converter, ruleset, args.ingest)
else:
# GUI mode
window = MainWindow(
config, converter, ruleset, initial_files=args.ingest, theme="clam"
)
window.mainloop()
def batch_mode_process(config, converter: Converter, ruleset: RuleSet, input_files):
transactions = []
for path in input_files:
records = converter.ingest_file(path)
for record in records:
partial = converter.convert(record, ruleset)
if partial is SKIP:
continue
if partial.partial:
raise ValueError(f"Insufficient rules to convert {record}")
txn = partial.upgrade()
transactions.append(txn)
for txn in transactions:
print(str(txn) + "\n")
async def _main():