diff --git a/src/procrusql-fit b/src/procrusql-fit deleted file mode 100755 index a086a29..0000000 --- a/src/procrusql-fit +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/python3 -import logging -import sys - -import psycopg2 - -import procrusql -import procrusql.parser - -if __name__ == "__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 = procrusql.parser.ParseState(text) - - ps2 = procrusql.parser.parse_ruleset(ps) - - if not ps2: - ps.printerror() - sys.exit(1) - - db = psycopg2.connect(sys.argv[2]) - procrusql.fit(db, ps2.ast) - -# vim: tw=0 diff --git a/src/procrusql/__init__.py b/src/procrusql/__init__.py index 866f781..e71d9ce 100644 --- a/src/procrusql/__init__.py +++ b/src/procrusql/__init__.py @@ -1,4 +1,5 @@ import logging +import sys import psycopg2 from psycopg2 import sql @@ -241,3 +242,19 @@ def dump_dot(): for i in range(1, len(in_order)): print(f"\t{in_order[i-1]} -> {in_order[i]} [style=dashed]") print("}") + +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 = procrusql.parser.ParseState(text) + + ps2 = procrusql.parser.parse_ruleset(ps) + + if not ps2: + ps.printerror() + sys.exit(1) + + db = psycopg2.connect(sys.argv[2]) + procrusql.fit(db, ps2.ast) +