Commit 58c7c54f authored by Noah Zoschke's avatar Noah Zoschke

basic error handling

parent d43f1d6a
......@@ -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)
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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment