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


Python host.file_hash方法代码示例

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


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

示例1: __call__

# 需要导入模块: from charmhelpers.core import host [as 别名]
# 或者: from charmhelpers.core.host import file_hash [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: contents_match

# 需要导入模块: from charmhelpers.core import host [as 别名]
# 或者: from charmhelpers.core.host import file_hash [as 别名]
def contents_match(self, path):
        """Determines if the file content is the same.

        This is determined by comparing hashsum of the file contents and
        the saved hashsum. If there is no hashsum, then the content cannot
        be sure to be the same so treat them as if they are not the same.
        Otherwise, return True if the hashsums are the same, False if they
        are not the same.

        :param path: the file to check.
        """
        checksum = file_hash(path)

        kv = unitdata.kv()
        stored_checksum = kv.get('hardening:%s' % path)
        if not stored_checksum:
            # If the checksum hasn't been generated, return False to ensure
            # the file is written and the checksum stored.
            log('Checksum for %s has not been calculated.' % path, level=DEBUG)
            return False
        elif stored_checksum != checksum:
            log('Checksum mismatch for %s.' % path, level=DEBUG)
            return False

        return True 
开发者ID:openstack,项目名称:charm-swift-proxy,代码行数:27,代码来源:file.py


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