Rearrange arguments to allow multiple rule files
This commit is contained in:
parent
94dd62ffc4
commit
15e558c90b
|
@ -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
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -247,16 +248,26 @@ 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()
|
||||||
text = rf.read()
|
ap.add_argument("--dbname")
|
||||||
ps = parser.ParseState(text)
|
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:
|
rules = []
|
||||||
ps.printerror()
|
for f in args.files:
|
||||||
sys.exit(1)
|
with open(f) as rf:
|
||||||
|
text = rf.read()
|
||||||
|
ps = parser.ParseState(text)
|
||||||
|
|
||||||
db = psycopg2.connect(sys.argv[2])
|
ps2 = parser.parse_ruleset(ps)
|
||||||
fit(db, ps2.ast)
|
|
||||||
|
if not ps2:
|
||||||
|
ps.printerror()
|
||||||
|
sys.exit(1)
|
||||||
|
rules.extend(ps2.ast)
|
||||||
|
|
||||||
|
fit(db, rules)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue