mirror of
https://github.com/kennethreitz/heroku-buildpack-python.git
synced 2026-06-05 23:10:16 +00:00
basic error handling
This commit is contained in:
+10
-2
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user