def create_file_from_template (self, relpath, unique=False, template_name=None, append_data=None, subst=True, pathtype='temp'):
""" Create file from app template using app's conf dict.
If subst=False no template operations will be performed and the file is copied verbatim. """
if not template_name:
tname = template_name = os.path.basename(relpath)
else:
tname = template_name
# Try pkgutil resource locator
tpath = os.path.join('apps', self.__class__.__name__,
tname + '.template')
filedata = pkgutil.get_data('trivup', tpath)
if filedata is None:
raise FileNotFoundError('Class %s resource %s not found' %
('trivup', tpath))
if subst:
rendered = Template(filedata.decode('ascii')).substitute(self.conf)
else:
rendered = filedata.decode('ascii')
if append_data is not None:
rendered += '\n' + append_data
return self.create_file(relpath, unique, data=rendered, pathtype=pathtype)
评论列表
文章目录