basic error handling

This commit is contained in:
Noah Zoschke
2011-05-18 16:16:46 -07:00
parent d43f1d6a3b
commit 58c7c54f9e
+10 -2
View File
@@ -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: