Rearrange arguments to allow multiple rule files

This commit is contained in:
Peter J. Holzer 2022-03-10 11:53:40 +01:00 committed by Peter J. Holzer
parent 94dd62ffc4
commit 15e558c90b
2 changed files with 21 additions and 10 deletions

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = ProcruSQL name = ProcruSQL
version = 0.0.2 version = 0.0.3
author = Peter J. Holzer author = Peter J. Holzer
author_email = hjp@hjp.at author_email = hjp@hjp.at
description = Make a database fit its description description = Make a database fit its description

View File

@ -1,3 +1,4 @@
import argparse
import logging import logging
import sys import sys
@ -247,7 +248,17 @@ def dump_dot():
def main(): def main():
logging.basicConfig(format="%(asctime)s %(levelname)s %(name)s %(lineno)d | %(message)s", level=logging.DEBUG) logging.basicConfig(format="%(asctime)s %(levelname)s %(name)s %(lineno)d | %(message)s", level=logging.DEBUG)
with open(sys.argv[1]) as rf: ap = argparse.ArgumentParser()
ap.add_argument("--dbname")
ap.add_argument("--dbuser")
ap.add_argument("files", nargs="+")
args = ap.parse_args()
db = psycopg2.connect(dbname=args.dbname, user=args.dbuser)
rules = []
for f in args.files:
with open(f) as rf:
text = rf.read() text = rf.read()
ps = parser.ParseState(text) ps = parser.ParseState(text)
@ -256,7 +267,7 @@ def main():
if not ps2: if not ps2:
ps.printerror() ps.printerror()
sys.exit(1) sys.exit(1)
rules.extend(ps2.ast)
db = psycopg2.connect(sys.argv[2]) fit(db, rules)
fit(db, ps2.ast)