From d77a897e08c85bf796b9fdc2785073b62bc31cb1 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" <robin.mueller.m@gmail.com> Date: Sun, 26 Apr 2020 20:37:48 +0200 Subject: [PATCH] some more refactoring --- obsw_tmtc_client.py | 1 + sendreceive/obsw_command_sender_receiver.py | 3 ++- utility/obsw_tmtc_printer.py | 25 ++++++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/obsw_tmtc_client.py b/obsw_tmtc_client.py index f497446..d4c97f1 100644 --- a/obsw_tmtc_client.py +++ b/obsw_tmtc_client.py @@ -168,6 +168,7 @@ class TmTcHandler: com_interface=communication_interface, tmtc_printer=tmtc_printer, tc_queue=all_tc_queue, tm_listener=tm_listener) sender_and_receiver.send_queue_tc_and_receive_tm_sequentially() + tmtc_printer.print_file_buffer_list_to_file("log/tmtc_log.txt", True) elif self.mode == g.ModeList.UnitTest: # Set up test suite and run it with runner. Verbosity specifies detail level diff --git a/sendreceive/obsw_command_sender_receiver.py b/sendreceive/obsw_command_sender_receiver.py index 8824782..f30e18c 100644 --- a/sendreceive/obsw_command_sender_receiver.py +++ b/sendreceive/obsw_command_sender_receiver.py @@ -121,7 +121,8 @@ class CommandSenderReceiver: self._tmtc_printer.print_string(print_string) elif queue_entry_first == "export": export_name = queue_entry_second - self._tmtc_printer.print_to_file(export_name, False) + self._tmtc_printer.add_print_buffer_to_buffer_list() + self._tmtc_printer.print_to_file(export_name, True) elif queue_entry_first == "timeout": self._tm_timeout = queue_entry_second else: diff --git a/utility/obsw_tmtc_printer.py b/utility/obsw_tmtc_printer.py index 9645c2f..3beaff4 100644 --- a/utility/obsw_tmtc_printer.py +++ b/utility/obsw_tmtc_printer.py @@ -238,7 +238,7 @@ class TmTcPrinter: if self.do_print_to_file: self.__file_buffer = self.__file_buffer + self.__print_buffer + "\r\n" - def store_file_buffer_into_buffer_list(self): + def add_print_buffer_to_buffer_list(self): self.file_buffer_list.append(self.__file_buffer) def clear_file_buffer(self): @@ -262,6 +262,29 @@ class TmTcPrinter: logger.info("Log file written to " + log_name) file.close() + def print_file_buffer_list_to_file(self, log_name: str = "log/tmtc_log.txt", + clear_list: bool = True): + """ + Joins the string list and prints it to an output file. + :param log_name: + :param clear_list: + :return: + """ + try: + file = open(log_name, 'w') + except FileNotFoundError: + logger.info("Log directory does not exists, creating log folder.") + os.mkdir('log') + file = open(log_name, 'w') + file_buffer = ''.join(self.file_buffer_list) + file.write(file_buffer) + if clear_list: + self.file_buffer_list = [] + logger.info("Log file written to " + log_name) + file.close() + + + @staticmethod def bit_extractor(byte: int, position: int): """ -- GitLab