From 15e558c90b5c28520ccf3f89ba2ebc5104161c9d Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Thu, 10 Mar 2022 11:53:40 +0100 Subject: [PATCH] Rearrange arguments to allow multiple rule files --- setup.cfg | 2 +- src/procrusql/__init__.py | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/setup.cfg b/setup.cfg index 60fd44e..e8eda2f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = ProcruSQL -version = 0.0.2 +version = 0.0.3 author = Peter J. Holzer author_email = hjp@hjp.at description = Make a database fit its description diff --git a/src/procrusql/__init__.py b/src/procrusql/__init__.py index 0d5c736..52c6625 100644 --- a/src/procrusql/__init__.py +++ b/src/procrusql/__init__.py @@ -1,3 +1,4 @@ +import argparse import logging import sys @@ -247,16 +248,26 @@ def dump_dot(): def main(): logging.basicConfig(format="%(asctime)s %(levelname)s %(name)s %(lineno)d | %(message)s", level=logging.DEBUG) - with open(sys.argv[1]) as rf: - text = rf.read() - ps = parser.ParseState(text) + ap = argparse.ArgumentParser() + ap.add_argument("--dbname") + ap.add_argument("--dbuser") + ap.add_argument("files", nargs="+") + args = ap.parse_args() - ps2 = parser.parse_ruleset(ps) + db = psycopg2.connect(dbname=args.dbname, user=args.dbuser) - if not ps2: - ps.printerror() - sys.exit(1) + rules = [] + for f in args.files: + with open(f) as rf: + text = rf.read() + ps = parser.ParseState(text) - db = psycopg2.connect(sys.argv[2]) - fit(db, ps2.ast) + ps2 = parser.parse_ruleset(ps) + + if not ps2: + ps.printerror() + sys.exit(1) + rules.extend(ps2.ast) + + fit(db, rules)