Skip to content
Open

дз #16

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions Src/Logics/Services/console_log_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from Src.Logics.Services.service import service
from Src.Models.event_type import event_type
from Src.Storage.storage import storage
from Src.errors import error_proxy
from Src.exceptions import exception_proxy
from Src.Logics.convert_factory import convert_factory
from Src.Logics.storage_observer import storage_observer

import os
import json
from datetime import datetime

#
# Сервис логирования
#
class console_log_service(service):

__storage: storage = None
__item:error_proxy = None

def __init__(self, data: list = None) -> None:
super().__init__(data)
self.__storage = storage()
self.__data = []
storage_observer.append(self)

@property
def item(self) -> error_proxy:
return self.__item

@item.setter
def item(self, value: error_proxy):
exception_proxy.validate(value, error_proxy)
self.__item = value

def __observe_print_log(self):
"""
Вывести лог в консоль
"""
data = self.__data
period = datetime.now().strftime('%Y-%m-%d')
factory = convert_factory()
data = factory.serialize( data )
json_text = json.dumps(data, sort_keys = True, indent = 4, ensure_ascii = False)
print(f"{period}: {json_text}")





def handle_event(self, handle_type: str ):
"""
Обработать событие
Args:
handle_type (str): Ключ
"""
super().handle_event(handle_type)

# Добавить запись в лог
if handle_type == event_type.write_log() and self.__item is not None:
self.__data.append(self.__item)

# Вывести лог в консоль
if handle_type == event_type.save_log():
self.__observe_print_log()
2 changes: 2 additions & 0 deletions Src/Logics/start_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from Src.Storage.storage import storage
from Src.exceptions import exception_proxy, operation_exception, argument_exception
from Src.Logics.Services.log_service import log_service
from Src.Logics.Services.console_log_service import console_log_service

#
# Класс для обработки данных. Начало работы приложения
Expand All @@ -27,6 +28,7 @@ def __init__(self, _options: settings,
self.__oprions = _options
self.__storage = _storage
log_service()
console_log_service

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут не корректно. console_log_service у Вас класс ,а не переменна. Тогда уж:

console_log_service()

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здравствуйте, с докером все получилось, мы с Кириллом Попвым на моем компьютере на убунту разобрались со всем.
Screenshot from 2024-05-20 14-59-45
Screenshot from 2024-05-20 15-01-38
Screenshot from 2024-05-20 15-02-06
Screenshot from 2024-05-20 15-05-35
Screenshot from 2024-05-20 15-05-47
Screenshot from 2024-05-20 15-07-48




Expand Down
4 changes: 4 additions & 0 deletions Src/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,15 @@ def write_log(message: str, log_type:str = "INFO" ):
Сформировать сообщение для записи лога
"""
observer_item = storage_observer.get( storage_observer .log_service_key() )
observer_item_console = storage_observer.get( storage_observer .console_log_service_key() )

if observer_item is not None:
item = error_proxy()
item.error = message
item.log_type = log_type

observer_item.item = item
if observer_item_console is not None:
observer_item_console.item = item

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да. Верно.

storage_observer.raise_event( "write_log" )

2 changes: 2 additions & 0 deletions Tst/convert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from Src.Storage.storage import storage
from Src.settings_manager import settings_manager
from Src.Logics.Services.log_service import log_service
from Src.Logics.Services.console_log_service import console_log_service

import unittest
import json
Expand All @@ -14,6 +15,7 @@ class convert_test(unittest.TestCase):
def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)
log_service()
console_log_service()

#
# Проверить загрузку одного элемента номенклатуры в объект
Expand Down
1 change: 1 addition & 0 deletions Tst/error_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from Src.errors import error_proxy
from Src.Logics.Services.log_service import log_service
from Src.Logics.Services.console_log_service import console_log_service

import unittest

Expand Down
2 changes: 2 additions & 0 deletions Tst/factory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from Src.Logics.Services.log_service import log_service

import unittest
from Src.Logics.Services.console_log_service import console_log_service

#
# Набор автотестов для проверки работы фабричного метода
Expand All @@ -14,6 +15,7 @@ class factory_test(unittest.TestCase):
def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)
log_service()
console_log_service()

#
# Проверить метод storage_keys в хранилище
Expand Down
2 changes: 2 additions & 0 deletions Tst/nomenclature_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from Src.Models.unit_model import unit_model
from Src.exceptions import argument_exception
from Src.Logics.Services.log_service import log_service
from Src.Logics.Services.console_log_service import console_log_service

import unittest

Expand All @@ -14,6 +15,7 @@ class nomenclature_test(unittest.TestCase):
def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)
log_service()
console_log_service()

#
# Проверить создание новой карточки номенклатуры
Expand Down
3 changes: 3 additions & 0 deletions Tst/processing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from Src.Models.storage_model import storage_model
from Src.Models.unit_model import unit_model
from Src.Logics.Services.log_service import log_service
from Src.Logics.Services.console_log_service import console_log_service

#
# Набор содульных тестов для проверки процессов обработки данных
Expand All @@ -17,6 +18,8 @@ class processing_test(unittest.TestCase):
def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)
log_service()
console_log_service()


#
# Проверить работу фабрики процессов
Expand Down
2 changes: 2 additions & 0 deletions Tst/prototype_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

from datetime import datetime
import unittest
from Src.Logics.Services.console_log_service import console_log_service

class prototype_test(unittest.TestCase):

def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)
log_service()
console_log_service()

#
# Проверить метод filter_by_period
Expand Down
2 changes: 2 additions & 0 deletions Tst/reporting_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
from Src.Logics.start_factory import start_factory
from Src.settings import settings
from Src.Logics.Services.log_service import log_service
from Src.Logics.Services.console_log_service import console_log_service


class reporting_test(unittest.TestCase):

def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)
log_service()
console_log_service()

def test_check_json_reporting_build(self):
# Подготовка
Expand Down
2 changes: 2 additions & 0 deletions Tst/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
from datetime import datetime
import unittest
import uuid
from Src.Logics.Services.console_log_service import console_log_service

class service_test(unittest.TestCase):

def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)
log_service()
console_log_service()

#
# Тест на удаление номенклатуры
Expand Down
2 changes: 2 additions & 0 deletions Tst/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import unittest
from datetime import datetime
from Src.Logics.Services.console_log_service import console_log_service


#
Expand All @@ -16,6 +17,7 @@ class settings_test(unittest.TestCase):
def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)
log_service()
console_log_service()

#
# Проверить действие наблюдателя при изменении даты блокировки
Expand Down
2 changes: 2 additions & 0 deletions Tst/storage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
from Src.settings_manager import settings_manager
from Src.Logics.start_factory import start_factory
from Src.Logics.Services.log_service import log_service
from Src.Logics.Services.console_log_service import console_log_service

class storage_test(unittest.TestCase):

def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)
log_service()
console_log_service()

#
# Проверить сохранение данных
Expand Down