better error messages
This commit is contained in:
parent
d211c85788
commit
6c04767006
|
@ -33,17 +33,19 @@ def render_template(template, config):
|
|||
if is_executable(template):
|
||||
return render_executable(template, config)
|
||||
else:
|
||||
return render_moustache(open(template).read(), config)
|
||||
try:
|
||||
return render_moustache(open(template).read(), config)
|
||||
except KeyNotFoundError as e:
|
||||
raise CornfigException("key '%s' does not exist in metadata file '%s'" % (e.key, template))
|
||||
except Exception as e:
|
||||
raise CornfigException("could not render moustache template %s" % template)
|
||||
|
||||
def is_executable(path):
|
||||
return os.path.isfile(path) and os.access(path, os.X_OK)
|
||||
|
||||
def render_moustache(text, config):
|
||||
try:
|
||||
r = pystache.Renderer(missing_tags = 'strict')
|
||||
return r.render(text, config)
|
||||
except KeyNotFoundError as e:
|
||||
raise CornfigException("key '%s' does not exist in metadata file." % e.key)
|
||||
r = pystache.Renderer(missing_tags = 'strict')
|
||||
return r.render(text, config)
|
||||
|
||||
def render_executable(path, config):
|
||||
p = Popen([path], stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
||||
|
|
2
setup.py
2
setup.py
|
@ -9,7 +9,7 @@ config = {
|
|||
'author': 'echohead',
|
||||
'author_email': 'tim.miller.0@gmail.com',
|
||||
'url': 'http://github.com/echohead/cornfig',
|
||||
'version': '0.1',
|
||||
'version': '0.2',
|
||||
'install_requires': ['nose'],
|
||||
'packages': ['cornfig'],
|
||||
'scripts': [],
|
||||
|
|
|
@ -57,7 +57,7 @@ def test_render_template():
|
|||
def test_render_moustache():
|
||||
assert_equals( render_moustache("ab{{x.a}}cd", {"x": {"a": "123"}}), "ab123cd" )
|
||||
|
||||
@raises(CornfigException)
|
||||
@raises(Exception)
|
||||
def test_render_moustache_bad_key():
|
||||
render_moustache("{{badkey}}", {})
|
||||
|
||||
|
|
Loading…
Reference in New Issue