def _render(self, target_name, read_path, write_path):
"""Render a given template or directory for the target.
:param target_name: String. Project or App name to render.
:param read_path: String. Path to template or directory to render.
:param write_path: String. Path to write to (or create directory).
"""
if os.path.isdir(read_path):
if os.path.split(read_path)[1] == 'project_name':
write_path = os.path.join(os.path.split(write_path)[0], self.variables['project_name'])
os.mkdir(write_path)
for filename in os.listdir(read_path):
if fnmatch(filename, 'test_*'):
write_filename = filename.replace('test_', f'test_{target_name}_')
else:
write_filename = filename
self._render(target_name, os.path.join(read_path, filename), os.path.join(write_path, write_filename))
else:
tpl = Template(filename=read_path)
with open(os.path.splitext(write_path)[0], 'w') as f:
f.write(tpl.render(**self.variables))
评论列表
文章目录