devstructure/blueprint — Issue #106: blueprint show -S fails for templates without *.blueprint-template.sh
Author: ekoyle
Created: 2011-12-19 17:08:38+00:00
State: open

I'm running the blueprint package from packages.devstructure.com (I have version 3.4.0-1py2.6).

I created a couple of templates and was unable to run blueprint show -S:

root@fwser-pri:~/deleteme# blueprint show -S firewalls
Traceback (most recent call last):
File "/usr/bin/blueprint-show", line 58, in
filename = getattr(b, options.generate)(options.relaxed).dumpf()
File "/usr/lib/python2.6/dist-packages/blueprint/__init__.py", line 476, in sh
return frontend.sh.sh(self, relaxed, server, secret)
File "/usr/lib/python2.6/dist-packages/blueprint/frontend/sh.py", line 186, in sh
service=service)
File "/usr/lib/python2.6/dist-packages/blueprint/__init__.py", line 504, in walk
walk.walk(self, **kwargs)
File "/usr/lib/python2.6/dist-packages/blueprint/walk.py", line 27, in walk
walk_files(b, **kwargs)
File "/usr/lib/python2.6/dist-packages/blueprint/walk.py", line 96, in walk_files
callable(pathname, f)
File "/usr/lib/python2.6/dist-packages/blueprint/frontend/sh.py", line 101, in file
(f['data'].rstrip(),),
KeyError: 'data'
root@fwser-pri:~/deleteme#

It looks like the 'data' key is only populated for a file with *.blueprint-template.mustache temlpate when the corresponding *.blueprint-template.sh file exists.

One fix would to be to only reference the value if it exists (will work for existing templates):
```
--- /usr/lib/python2.6/dist-packages/blueprint/frontend/sh.py.orig 2011-12-19 09:37:15.000000000 -0700
+++ /usr/lib/python2.6/dist-packages/blueprint/frontend/sh.py 2011-12-19 09:55:02.000000000 -0700
@@ -98,7 +98,7 @@
('do',),
('\t. "$F"',),
('done',),
- (f['data'].rstrip(),),
+ ('' if not f.has_key('data') else f['data'].rstrip(),),
(command(*commands,
escape_stdin=True,
stdin=f['template'],
```

Another option would be to always populate it for templates (existing templates would need to be recreated, but probably not a big deal since they don't work anyway):

```
--- /usr/lib/python2.6/dist-packages/blueprint/backend/files.py.orig 2011-12-19 10:00:50.000000000 -0700
+++ /usr/lib/python2.6/dist-packages/blueprint/backend/files.py 2011-12-19 10:02:11.000000000 -0700
@@ -764,6 +764,8 @@
if template:
if data:
kwargs['data'] = data.decode('utf_8')
+ else:
+ kwargs['data'] = ''
kwargs['template'] = template.decode('utf_8')
else:
kwargs['content'] = content.decode('utf_8')
```