Fix encoding bug when uploading mako template

at least it seems like that was a bug.  hopefully i didn't just break other things
This commit is contained in:
Lance Edgar 2018-03-11 13:36:06 -05:00
parent 11db1579c4
commit 38b99cd817

View file

@ -126,7 +126,7 @@ def upload_template(local_path, remote_path, owner='root:root', **kwargs):
sudo('chown {0} {1}'.format(owner, remote_path))
def upload_mako_template(local_path, remote_path, context={}, **kwargs):
def upload_mako_template(local_path, remote_path, context={}, encoding='utf_8', **kwargs):
"""
Render a local file as a Mako template, and upload the result to the server.
"""
@ -135,7 +135,8 @@ def upload_mako_template(local_path, remote_path, context={}, **kwargs):
temp_dir = tempfile.mkdtemp(prefix='rattail-fabric.')
temp_path = os.path.join(temp_dir, os.path.basename(local_path))
with open(temp_path, 'wb') as f:
f.write(template.render(env=env, **context))
text = template.render(env=env, **context)
f.write(text.encode(encoding))
os.chmod(temp_path, os.stat(local_path).st_mode)
put(temp_path, remote_path, **kwargs)