diff --git a/opt/inject_dbs b/opt/inject_dbs index f948958..09b7fef 100755 --- a/opt/inject_dbs +++ b/opt/inject_dbs @@ -2,7 +2,7 @@ import os import sys from lib2to3 import pygram, pytree -from lib2to3.pgen2 import driver +from lib2to3.pgen2 import driver, parse BIN_DIR = os.path.dirname(__file__) @@ -23,9 +23,17 @@ if __name__ == "__main__": patch = os.path.join(BIN_DIR, "dbs.py.src") drv = driver.Driver(pygram.python_grammar, pytree.convert) - root = drv.parse_file(src) + try: + root = drv.parse_file(src) + except parse.ParseError, e: + print "fatal: could not parse file as Python" + sys.exit(1) node = find(root, pytree.Leaf(1, "DATABASES")) # Find node for DATABASES = { ... } + if not node: + print "fatal: could not find DATABASES = stmt" + sys.exit(1) + end = node.parent.next_sibling # calculate adjacent sibling with open(src) as _src: