def on_complete( command_response: environ.Response, project_data: SharedCache = None, message: str = None ) -> ExecutionResult: environ.modes.remove(environ.modes.SINGLE_RUN) if message: logger.log(message) logger.remove_output_path(log_path) return ExecutionResult( command_response=command_response, project_data=project_data or SharedCache() )
def end(code: int): """ Ends the application with the specified error code, adding whitespace to the end of the console log output for clarity :param code: The integer status code to apply on exit. If the value is non-zero, indicating an error, a message will be printed to the console to inform the user that the application exited in error """ print('\n') if code != 0: log('Failed with status code: {}'.format(code), whitespace=1) sys.exit(code)
def load(self, source_path: str = None): """ :return: """ if self.persistent is not None: return self path = source_path if source_path else self._source_path if not os.path.exists(path): self._persistent = {} return self try: with open(path, 'r') as f: contents = f.read() if contents: self._persistent = json.loads(contents) except json_decoder.JSONDecodeError as err: if self._persistent == self.NO_VALUE: return self self._persistent = self.NO_VALUE log( """ [ERROR]: Failed to decode json file PATH: {path} INFO: {msg} LINE: {line} CHAR: {char} """.format( path=path, msg=err.msg, line=err.lineno, char=err.colno ) ) return self
def console(self, message: typing.Union[str, typing.List[str]] = None, whitespace: int = 0, whitespace_top: int = 0, whitespace_bottom: int = 0, indent_by: int = 0, trace: bool = True, file_path: str = None, append_to_file: bool = True, **kwargs) -> 'ResponseMessage': """ :param message: :param whitespace: :param whitespace_top: :param whitespace_bottom: :param indent_by: :param trace: :param file_path: :param append_to_file: :param kwargs: :return: """ if not message and self.message: message = '[{}]: {}'.format(self.kind, cli.reformat(self.message)) self.log += logger.log(message=message, whitespace=whitespace, whitespace_top=whitespace_top, whitespace_bottom=whitespace_bottom, indent_by=indent_by, trace=trace, file_path=file_path, append_to_file=append_to_file, **kwargs) return self
def on_complete(message: str = None) -> environ.Response: environ.modes.remove(environ.modes.SINGLE_RUN) if message: logger.log(message) logger.remove_output_path(log_path) return response
def test_log_with_kwargs(raw: MagicMock): """Should include kwargs in log output""" message = logger.log('test', foo=42) assert 1 == raw.call_count assert 0 < message.find('foo: 42'), """