Beispiel #1
0
 def __check_message(message: SyncOutMsg, /) -> None:
     if message.status < 0 or message.status > 100:
         raise SyncStdoutError(
             "Status values for the SyncOutMsg type must be floats between 0 and 100!"
         )
     if not message.s_id:
         raise SyncStdoutError("Message id ca not be empty!")
Beispiel #2
0
 def __check_object_status(message: SyncOutMsg, to_check: _SyncOutSt,
                           /) -> None:
     if message.done and to_check[1]:
         SyncStdoutError("The messaging object was already closed!")
     if message.status < to_check[0]:
         SyncStdoutError(
             "The messaging object had a higher progress value than stated in the message!"
         )
Beispiel #3
0
    def save_stats(self, object_name: str, stats_to_merge: Dict, /) -> None:
        if self._check_closed():
            raise SyncStdoutError("The logger was already closed!")
        if not object_name:
            raise SyncStdoutError("object_name should not be empty!")

        with self.__stats_lock:
            puf = self.__stats.managed_dict.get(
                object_name, JsonStatsContainerIntFloatList())
            puf.merge_stats_dict(stats_to_merge)
            self.__stats.managed_dict[object_name] = puf
Beispiel #4
0
    def print_to_console(self, message: SyncOutMsg,
                         format_func: Callable[[str], List[str]], /) -> None:

        with self.__log_manager.manager_lock:
            term_size = shutil.get_terminal_size(fallback=(80, 15))
            if term_size.lines < 10 or term_size.columns < 10:
                raise SyncStdoutError("Terminal size is to small!")
            if not self.__log_manager.manager_counter.first_print.value:
                self.__log_manager.manager_counter.first_print.value = 1
                sys.__stdout__.write("\u001b[2J\u001b[{0};1H\u001b[s".format(
                    term_size.lines))
                sys.__stdout__.flush()

            self.__check_message(message)
            new_act_object = self.__log_manager.sync_object_manager.managed_dict.get(
                message.s_id)
            if new_act_object is not None:
                self.__check_object_status(message, new_act_object)

            new_act_object = (message.status, message.done)
            if message.done:
                self.__log_manager.manager_counter.done_object_counter.value += 1

            self.__log_manager.sync_object_manager.managed_dict[
                message.s_id] = new_act_object

            self.__print_to_stdout(message.msg, term_size.lines,
                                   term_size.columns, format_func)
            self.__print_status(0, term_size.columns)
Beispiel #5
0
    def print_logger(self, message: str, log_level: int, /) -> None:
        if self._check_closed():
            raise SyncStdoutError("The logger was already closed!")

        self.__logger_data.queue.put(_LoggerMsg(msg=message, level=log_level))

        with self.__stats_lock:
            self._logger_switch.get(log_level,
                                    _increase_other)(self.__logging_stats)
Beispiel #6
0
 def print_message_simple(self, message: str, /) -> None:
     if self._check_closed():
         raise SyncStdoutError("The logger was already closed!")
     if self.__general.global_manager.manager_error:
         _increase_error(self.__logging_stats)
         sys.__stdout__.write(
             "ERROR occurred in output process (printing message simple)!")
         sys.__stdout__.flush()
     else:
         self.__general.global_manager.writer_to_queue(
             (SyncOutMsg(s_id="SyncStdout_{0}".format(self.__general.g_id),
                         msg=message,
                         status=0.0,
                         done=False), _simple_formatter))
Beispiel #7
0
    def print_message(self, message: SyncOutMsg,
                      format_func: Callable[[str], List[str]], /) -> None:
        if self._check_closed():
            raise SyncStdoutError("The logger was already closed!")

        message.s_id = "SyncStdout_{0}_{1}".format(self.__general.g_id,
                                                   message.s_id)
        if self.__general.global_manager.manager_error:
            _increase_error(self.__logging_stats)
            sys.__stdout__.write(
                "ERROR occurred in output process (printing message)!")
            sys.__stdout__.flush()
        else:
            self.__general.global_manager.writer_to_queue(
                (message, format_func))
Beispiel #8
0
 def run_with_update(self, run_par: bool, /) -> bool:
     start_pr = False
     with self.__manager_lock:
         if run_par:
             if not self.__wa_process_attributes.status.value:
                 self.__wa_process_attributes.status.value = 1
                 start_pr = True
                 self.__wa_process_attributes.id_cnt.value += 1
             self.__wa_process_attributes.logger_cnt.value += 1
             self.__wa_process_attributes.run.value += 1
         else:
             if self.__wa_process_attributes.run.value <= 0:
                 raise SyncStdoutError("No logger was started!")
             self.__wa_process_attributes.run.value -= 1
     return start_pr