26 if sys.version_info[0] == 3:
32 """Transformation for template to code. 34 def __init__(self, template_file, dest_file_template_str, overwrite=True):
37 @param template_file: Filename of the mustache template. 38 @param dest_file_template_str: Destination file name. This is a 39 mustache template, so each resource can write to a unique file. 40 @param overwrite: If True, destination file is ovewritten if it exists. 42 template_str =
unicode(open(template_file,
"r").read()) 44 dest_file_template_str = unicode(dest_file_template_str) 48 def render(self, renderer, model, dest_dir):
49 """Render a model according to this transformation. 51 @param render: Pystache renderer. 52 @param model: Model object to render. 53 @param dest_dir: Destination directory to write generated code. 56 dest_file = os.path.join(dest_dir, dest_file)
57 dest_exists = os.path.exists(dest_file)
60 with tempfile.NamedTemporaryFile(mode=
'w+')
as out:
61 out.write(renderer.render(self.
template, model))
64 if not dest_exists
or not filecmp.cmp(out.name, dest_file):
65 print(
"Writing %s" % dest_file)
66 shutil.copyfile(out.name, dest_file)