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 tkinter import ttk
from platformdirs import PlatformDirs from platformdirs import PlatformDirs
from beanify.base.converter import SKIP, Converter
from .base.rules import DummyRuleInterface, JSONRuleInterface, RuleSet from .base.rules import DummyRuleInterface, JSONRuleInterface, RuleSet
from .gui import MainWindow from .gui import MainWindow
from .converters import converters_available, converter_factory from .converters import converters_available, converter_factory
@@ -96,15 +98,12 @@ parser.add_argument(
default=None, default=None,
help="'json' or 'dummy'", help="'json' or 'dummy'",
) )
parser.add_argument(
""" "--batch",
TODO: dest="batch",
- [ ] Add parser arguments action="store_true",
- [ ] Find config file, or create and close help="Run the ingester in batch mode. The rule file must be complete. The ledger will be output to stdout.",
- [ ] 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
"""
async def main(): async def main():
@@ -207,10 +206,31 @@ async def main():
return return
ruleset = RuleSet.load_from(rule_interface) ruleset = RuleSet.load_from(rule_interface)
window = MainWindow( if args.batch:
config, converter, ruleset, initial_files=args.ingest, theme="clam" # Batch mode
) batch_mode_process(config, converter, ruleset, args.ingest)
window.mainloop() 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(): async def _main():