我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用charmhelpers.core.hookenv.log()。
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
def pip_install_requirements(requirements, constraints=None, **options): """Install a requirements file. :param constraints: Path to pip constraints file. http://pip.readthedocs.org/en/stable/user_guide/#constraints-files """ command = ["install"] available_options = ('proxy', 'src', 'log', ) for option in parse_options(options, available_options): command.append(option) command.append("-r {0}".format(requirements)) if constraints: command.append("-c {0}".format(constraints)) log("Installing from file: {} with constraints {} " "and options: {}".format(requirements, constraints, command)) else: log("Installing from file: {} with options: {}".format(requirements, command)) pip_execute(command)
def pip_uninstall(package, **options): """Uninstall a python package""" command = ["uninstall", "-q", "-y"] available_options = ('proxy', 'log', ) for option in parse_options(options, available_options): command.append(option) if isinstance(package, list): command.extend(package) else: command.append(package) log("Uninstalling {} package with options: {}".format(package, command)) pip_execute(command)
def disable(): """ Disable ufw :returns: True if ufw is successfully disabled """ if not is_enabled(): return True output = subprocess.check_output(['ufw', 'disable'], universal_newlines=True, env={'LANG': 'en_US', 'PATH': os.environ['PATH']}) m = re.findall(r'^Firewall stopped and disabled on system startup\n', output, re.M) hookenv.log(output, level='DEBUG') if len(m) == 0: hookenv.log("ufw couldn't be disabled", level='WARN') return False else: hookenv.log("ufw disabled", level='INFO') return True
def lookup_device_name(major_number, minor_number): """ :param major_number: int. The major device number :param minor_number: int. The minor device number :return: string. The name of the device. Example: /dev/sda. Returns None on error. """ diskstats = get_disk_stats() for line in diskstats: parts = line.split() if not len(parts) > 3: # Skip bogus lines continue try: if int(parts[0]) is major_number and int(parts[1]) is \ minor_number: # Found our device. Return its name return parts[2] except ValueError as value_err: hookenv.log('Could not convert {} or {} into an integer. Error: {}' .format(parts[0], parts[1], str(value_err))) continue return None