templating.py 文件源码

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

项目:charm-nova-cloud-controller 作者: openstack 项目源码 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号