Add batch edit mode and flag
This commit is contained in:
@@ -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,12 +206,33 @@ async def main():
|
|||||||
return
|
return
|
||||||
ruleset = RuleSet.load_from(rule_interface)
|
ruleset = RuleSet.load_from(rule_interface)
|
||||||
|
|
||||||
|
if args.batch:
|
||||||
|
# Batch mode
|
||||||
|
batch_mode_process(config, converter, ruleset, args.ingest)
|
||||||
|
else:
|
||||||
|
# GUI mode
|
||||||
window = MainWindow(
|
window = MainWindow(
|
||||||
config, converter, ruleset, initial_files=args.ingest, theme="clam"
|
config, converter, ruleset, initial_files=args.ingest, theme="clam"
|
||||||
)
|
)
|
||||||
window.mainloop()
|
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():
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
config_path = args.config
|
config_path = args.config
|
||||||
|
|||||||
Reference in New Issue
Block a user