def show(self): name = 'unknown error' if isinstance(self, HookError): name = 'hook error' elif isinstance(self, PyinfraError): name = 'pyinfra error' elif isinstance(self, IOError): name = 'local IO error' if pseudo_host.isset(): # Get any operation meta + name op_name = None current_op_hash = pseudo_state.current_op_hash current_op_meta = pseudo_state.op_meta.get(current_op_hash) if current_op_meta: op_name = ', '.join(current_op_meta['names']) sys.stderr.write('--> {0}{1}{2}: '.format( pseudo_host.print_prefix, click.style(name, 'red', bold=True), ' (operation={0})'.format(op_name) if op_name else '', )) else: sys.stderr.write( '--> {0}: '.format(click.style(name, 'red', bold=True)), ) logger.warning(self) print()
def test_pseudo_host_class_attr(self): host = _create_host() pseudo_host.set(host) assert pseudo_host.isset() is True with self.assertRaises(AttributeError): host.hello setattr(Host, 'hello', 'class_world') setattr(host, 'hello', 'instance_world') assert pseudo_host.hello == host.hello # Reset and check fallback to class variable pseudo_host.reset() assert pseudo_host.isset() is False assert pseudo_host.hello == 'class_world'
def _exception(name, e, always_dump=False): print() if pseudo_host.isset(): sys.stderr.write('--> [{0}]: {1}: '.format( colored(pseudo_host.name, attrs=['bold']), colored(name, 'red', attrs=['bold']) )) else: sys.stderr.write('--> {0}: '.format(colored(name, 'red', attrs=['bold']))) if e: logger.warning(e) if arguments.get('debug') or always_dump: dump_trace(sys.exc_info()) _exit(1)
def show(self): name = 'unknown error' if isinstance(self, HookError): name = 'hook error' elif isinstance(self, PyinfraError): name = 'pyinfra error' elif isinstance(self, IOError): name = 'local IO error' if pseudo_host.isset(): sys.stderr.write('--> [{0}]: {1}: '.format( click.style(six.text_type(pseudo_host.name), bold=True), click.style(name, 'red', bold=True), )) else: sys.stderr.write( '--> {0}: '.format(click.style(name, 'red', bold=True)), ) logger.warning(self) print()