当前位置: 首页>>代码示例>>Python>>正文


Python templating.render方法代码示例

本文整理汇总了Python中charmhelpers.core.templating.render方法的典型用法代码示例。如果您正苦于以下问题:Python templating.render方法的具体用法?Python templating.render怎么用?Python templating.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在charmhelpers.core.templating的用法示例。


在下文中一共展示了templating.render方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

# 需要导入模块: from charmhelpers.core import templating [as 别名]
# 或者: from charmhelpers.core.templating import render [as 别名]
def __call__(self, manager, service_name, event_name):
        pre_checksum = ''
        if self.on_change_action and os.path.isfile(self.target):
            pre_checksum = host.file_hash(self.target)
        service = manager.get_service(service_name)
        context = {'ctx': {}}
        for ctx in service.get('required_data', []):
            context.update(ctx)
            context['ctx'].update(ctx)

        result = templating.render(self.source, self.target, context,
                                   self.owner, self.group, self.perms,
                                   template_loader=self.template_loader)
        if self.on_change_action:
            if pre_checksum == host.file_hash(self.target):
                hookenv.log(
                    'No change detected: {}'.format(self.target),
                    hookenv.DEBUG)
            else:
                self.on_change_action()

        return result


# Convenience aliases for templates 
开发者ID:openstack,项目名称:charm-plumgrid-gateway,代码行数:27,代码来源:helpers.py

示例2: persist_settings

# 需要导入模块: from charmhelpers.core import templating [as 别名]
# 或者: from charmhelpers.core.templating import render [as 别名]
def persist_settings(settings_dict):
    # Write all settings to /etc/hdparm.conf
    """ This will persist the hard drive settings to the /etc/hdparm.conf file

    The settings_dict should be in the form of {"uuid": {"key":"value"}}

    :param settings_dict: dict of settings to save
    """
    if not settings_dict:
        return

    try:
        templating.render(source='hdparm.conf', target=HDPARM_FILE,
                          context=settings_dict)
    except IOError as err:
        log("Unable to open {path} because of error: {error}".format(
            path=HDPARM_FILE, error=err), level=ERROR)
    except Exception as e:
        # The templating.render can raise a jinja2 exception if the
        # template is not found. Rather than polluting the import
        # space of this charm, simply catch Exception
        log('Unable to render {path} due to error: {error}'.format(
            path=HDPARM_FILE, error=e), level=ERROR) 
开发者ID:openstack,项目名称:charm-ceph-osd,代码行数:25,代码来源:utils.py


注:本文中的charmhelpers.core.templating.render方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。