base.py 文件源码

python
阅读 15 收藏 0 点赞 0 评论 0

项目:jawaf 作者: danpozmanter 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号