From a03a1e96d316a5d4a545b9e1428264e476b2e7cb Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 26 Feb 2022 10:49:24 +0100 Subject: [PATCH] Move entry point to __init__.py I couldn't find a way to include scripts but pip can automatically create them from entry-points. --- src/procrusql-fit | 25 ------------------------- src/procrusql/__init__.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 25 deletions(-) delete mode 100755 src/procrusql-fit 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) +