👍️[Update] All : 不要なprintLogを削除 / なるべくtry exceptした場合にはerrorLogを保存するように変更
This commit is contained in:
@@ -11,6 +11,7 @@ from models.translation.translation_languages import translation_lang
|
|||||||
from models.translation.translation_utils import ctranslate2_weights
|
from models.translation.translation_utils import ctranslate2_weights
|
||||||
from models.transcription.transcription_languages import transcription_lang
|
from models.transcription.transcription_languages import transcription_lang
|
||||||
from models.transcription.transcription_whisper import _MODELS as whisper_models
|
from models.transcription.transcription_whisper import _MODELS as whisper_models
|
||||||
|
from utils import errorLogging
|
||||||
|
|
||||||
json_serializable_vars = {}
|
json_serializable_vars = {}
|
||||||
def json_serializable(var_name):
|
def json_serializable(var_name):
|
||||||
@@ -1081,9 +1082,8 @@ class Config:
|
|||||||
for key, value in self._config_data.items():
|
for key, value in self._config_data.items():
|
||||||
try:
|
try:
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
from utils import errorLogging
|
errorLogging()
|
||||||
errorLogging(e)
|
|
||||||
|
|
||||||
with open(self.PATH_CONFIG, 'w', encoding="utf-8") as fp:
|
with open(self.PATH_CONFIG, 'w', encoding="utf-8") as fp:
|
||||||
for var_name, var_func in json_serializable_vars.items():
|
for var_name, var_func in json_serializable_vars.items():
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import comtypes
|
|||||||
from pyaudiowpatch import PyAudio, paWASAPI
|
from pyaudiowpatch import PyAudio, paWASAPI
|
||||||
from pycaw.callbacks import MMNotificationClient
|
from pycaw.callbacks import MMNotificationClient
|
||||||
from pycaw.utils import AudioUtilities
|
from pycaw.utils import AudioUtilities
|
||||||
from utils import printLog
|
from utils import errorLogging
|
||||||
|
|
||||||
class Client(MMNotificationClient):
|
class Client(MMNotificationClient):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -187,12 +187,12 @@ class DeviceManager:
|
|||||||
sleep(2)
|
sleep(2)
|
||||||
self.noticeUpdateDevices()
|
self.noticeUpdateDevices()
|
||||||
self.runProcessAfterUpdateDevices()
|
self.runProcessAfterUpdateDevices()
|
||||||
except Exception as e:
|
except Exception:
|
||||||
printLog("Device Monitoring: ", e)
|
errorLogging()
|
||||||
finally:
|
finally:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception:
|
||||||
printLog("Device Monitoring End Exception: ", e)
|
errorLogging()
|
||||||
|
|
||||||
def startMonitoring(self):
|
def startMonitoring(self):
|
||||||
self.monitoring_flag = True
|
self.monitoring_flag = True
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ from models.transcription.transcription_whisper import checkWhisperWeight, downl
|
|||||||
from models.overlay.overlay import Overlay
|
from models.overlay.overlay import Overlay
|
||||||
from models.overlay.overlay_image import OverlayImage
|
from models.overlay.overlay_image import OverlayImage
|
||||||
from models.watchdog.watchdog import Watchdog
|
from models.watchdog.watchdog import Watchdog
|
||||||
|
from utils import errorLogging
|
||||||
|
|
||||||
class threadFnc(Thread):
|
class threadFnc(Thread):
|
||||||
def __init__(self, fnc, end_fnc=None, daemon=True, *args, **kwargs):
|
def __init__(self, fnc, end_fnc=None, daemon=True, *args, **kwargs):
|
||||||
@@ -328,9 +329,8 @@ class Model:
|
|||||||
current_version = parse(config.VERSION)
|
current_version = parse(config.VERSION)
|
||||||
if new_version > current_version:
|
if new_version > current_version:
|
||||||
update_flag = True
|
update_flag = True
|
||||||
except Exception as e:
|
except Exception:
|
||||||
from utils import errorLogging
|
errorLogging()
|
||||||
errorLogging(e)
|
|
||||||
return update_flag
|
return update_flag
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -348,9 +348,8 @@ class Model:
|
|||||||
for chunk in res.iter_content(chunk_size=1024*5):
|
for chunk in res.iter_content(chunk_size=1024*5):
|
||||||
file.write(chunk)
|
file.write(chunk)
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception:
|
||||||
from utils import errorLogging
|
errorLogging()
|
||||||
errorLogging(e)
|
|
||||||
# run updater
|
# run updater
|
||||||
Popen(program_name, cwd=current_directory)
|
Popen(program_name, cwd=current_directory)
|
||||||
|
|
||||||
@@ -369,9 +368,8 @@ class Model:
|
|||||||
for chunk in res.iter_content(chunk_size=1024*5):
|
for chunk in res.iter_content(chunk_size=1024*5):
|
||||||
file.write(chunk)
|
file.write(chunk)
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception:
|
||||||
from utils import errorLogging
|
errorLogging()
|
||||||
errorLogging(e)
|
|
||||||
# run updater
|
# run updater
|
||||||
Popen([program_name, "--cuda"], cwd=current_directory)
|
Popen([program_name, "--cuda"], cwd=current_directory)
|
||||||
|
|
||||||
@@ -442,7 +440,7 @@ class Model:
|
|||||||
message = self.mic_transcriber.getTranscript()
|
message = self.mic_transcriber.getTranscript()
|
||||||
fnc(message)
|
fnc(message)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
errorLogging()
|
||||||
|
|
||||||
def endMicTranscript():
|
def endMicTranscript():
|
||||||
while not self.mic_audio_queue.empty():
|
while not self.mic_audio_queue.empty():
|
||||||
@@ -538,7 +536,7 @@ class Model:
|
|||||||
try:
|
try:
|
||||||
self.check_mic_energy_fnc(energy)
|
self.check_mic_energy_fnc(energy)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
errorLogging()
|
||||||
sleep(0.01)
|
sleep(0.01)
|
||||||
|
|
||||||
mic_energy_queue = Queue()
|
mic_energy_queue = Queue()
|
||||||
@@ -606,7 +604,7 @@ class Model:
|
|||||||
message = self.speaker_transcriber.getTranscript()
|
message = self.speaker_transcriber.getTranscript()
|
||||||
fnc(message)
|
fnc(message)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
errorLogging()
|
||||||
|
|
||||||
def endSpeakerTranscript():
|
def endSpeakerTranscript():
|
||||||
speaker_audio_queue.queue.clear()
|
speaker_audio_queue.queue.clear()
|
||||||
@@ -660,7 +658,7 @@ class Model:
|
|||||||
try:
|
try:
|
||||||
self.check_speaker_energy_fnc(energy)
|
self.check_speaker_energy_fnc(energy)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
errorLogging()
|
||||||
sleep(0.01)
|
sleep(0.01)
|
||||||
|
|
||||||
speaker_energy_queue = Queue()
|
speaker_energy_queue = Queue()
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from tinyoscquery.queryservice import OSCQueryService
|
|||||||
from tinyoscquery.query import OSCQueryBrowser, OSCQueryClient
|
from tinyoscquery.query import OSCQueryBrowser, OSCQueryClient
|
||||||
from tinyoscquery.utility import get_open_udp_port, get_open_tcp_port
|
from tinyoscquery.utility import get_open_udp_port, get_open_tcp_port
|
||||||
from tinyoscquery.shared.node import OSCAccess
|
from tinyoscquery.shared.node import OSCAccess
|
||||||
|
from utils import errorLogging
|
||||||
|
|
||||||
class OSCHandler:
|
class OSCHandler:
|
||||||
def __init__(self, ip_address="127.0.0.1", port=9000) -> None:
|
def __init__(self, ip_address="127.0.0.1", port=9000) -> None:
|
||||||
@@ -55,7 +56,7 @@ class OSCHandler:
|
|||||||
browser.browser.cancel()
|
browser.browser.cancel()
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
errorLogging()
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def getOSCParameterMuteSelf(self) -> bool:
|
def getOSCParameterMuteSelf(self) -> bool:
|
||||||
@@ -77,6 +78,7 @@ class OSCHandler:
|
|||||||
self.osc_query_service.advertise_endpoint(filter, access=OSCAccess.READWRITE_VALUE)
|
self.osc_query_service.advertise_endpoint(filter, access=OSCAccess.READWRITE_VALUE)
|
||||||
break
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
|
errorLogging()
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
||||||
def oscServerServe(self) -> None:
|
def oscServerServe(self) -> None:
|
||||||
|
|||||||
@@ -10,11 +10,7 @@ try:
|
|||||||
from . import overlay_utils as utils
|
from . import overlay_utils as utils
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import overlay_utils as utils
|
import overlay_utils as utils
|
||||||
try:
|
from utils import errorLogging
|
||||||
from utils import printLog
|
|
||||||
except ImportError:
|
|
||||||
def printLog(*args):
|
|
||||||
print(*args)
|
|
||||||
|
|
||||||
def mat34Id(array):
|
def mat34Id(array):
|
||||||
arr = openvr.HmdMatrix34_t()
|
arr = openvr.HmdMatrix34_t()
|
||||||
@@ -114,8 +110,8 @@ class Overlay:
|
|||||||
self.updateFadeoutDuration(self.settings[size]["fadeout_duration"], size)
|
self.updateFadeoutDuration(self.settings[size]["fadeout_duration"], size)
|
||||||
self.init_process = False
|
self.init_process = False
|
||||||
|
|
||||||
except Exception as e:
|
except Exception:
|
||||||
printLog("error:Could not initialise OpenVR", e)
|
errorLogging()
|
||||||
|
|
||||||
def updateImage(self, img, size):
|
def updateImage(self, img, size):
|
||||||
if self.initialized is True:
|
if self.initialized is True:
|
||||||
@@ -125,8 +121,8 @@ class Overlay:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self.overlay.setOverlayRaw(self.handle[size], img, width, height, 4)
|
self.overlay.setOverlayRaw(self.handle[size], img, width, height, 4)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
printLog("error:Could not update image", e)
|
errorLogging()
|
||||||
self.initialized = False
|
self.initialized = False
|
||||||
self.reStartOverlay()
|
self.reStartOverlay()
|
||||||
while self.initialized is False:
|
while self.initialized is False:
|
||||||
@@ -217,8 +213,8 @@ class Overlay:
|
|||||||
if new_event.eventType == openvr.VREvent_Quit:
|
if new_event.eventType == openvr.VREvent_Quit:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception:
|
||||||
printLog("error:Could not check SteamVR running", e)
|
errorLogging()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def evaluateOpacityFade(self, size):
|
def evaluateOpacityFade(self, size):
|
||||||
@@ -344,9 +340,11 @@ if __name__ == "__main__":
|
|||||||
overlay.updateImage(img, "small")
|
overlay.updateImage(img, "small")
|
||||||
time.sleep(15)
|
time.sleep(15)
|
||||||
except openvr.error_code.OverlayError_InvalidParameter as e:
|
except openvr.error_code.OverlayError_InvalidParameter as e:
|
||||||
|
errorLogging()
|
||||||
logging.error(f"OverlayError_InvalidParameter: {e}")
|
logging.error(f"OverlayError_InvalidParameter: {e}")
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
errorLogging()
|
||||||
logging.error(f"Unexpected error: {e}")
|
logging.error(f"Unexpected error: {e}")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from os import path as os_path
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
from utils import errorLogging
|
||||||
|
|
||||||
class OverlayImage:
|
class OverlayImage:
|
||||||
LANGUAGES = {
|
LANGUAGES = {
|
||||||
@@ -56,6 +57,7 @@ class OverlayImage:
|
|||||||
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf")
|
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf")
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
errorLogging()
|
||||||
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
|
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
|
||||||
@@ -133,6 +135,7 @@ class OverlayImage:
|
|||||||
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf")
|
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf")
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
errorLogging()
|
||||||
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
|
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
|
||||||
@@ -167,6 +170,7 @@ class OverlayImage:
|
|||||||
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", "NotoSansJP-Regular.ttf")
|
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", "NotoSansJP-Regular.ttf")
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
errorLogging()
|
||||||
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", "NotoSansJP-Regular.ttf")
|
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", "NotoSansJP-Regular.ttf")
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from io import BytesIO
|
|||||||
from threading import Event
|
from threading import Event
|
||||||
import wave
|
import wave
|
||||||
from speech_recognition import Recognizer, AudioData, AudioFile
|
from speech_recognition import Recognizer, AudioData, AudioFile
|
||||||
|
from speech_recognition.exceptions import UnknownValueError
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from pyaudiowpatch import get_sample_size, paInt16
|
from pyaudiowpatch import get_sample_size, paInt16
|
||||||
from .transcription_languages import transcription_lang
|
from .transcription_languages import transcription_lang
|
||||||
@@ -11,6 +12,8 @@ from .transcription_whisper import getWhisperModel, checkWhisperWeight
|
|||||||
import torch
|
import torch
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from pydub import AudioSegment
|
from pydub import AudioSegment
|
||||||
|
from utils import errorLogging
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
warnings.simplefilter('ignore', RuntimeWarning)
|
warnings.simplefilter('ignore', RuntimeWarning)
|
||||||
|
|
||||||
@@ -74,9 +77,10 @@ class AudioTranscriber:
|
|||||||
if s.avg_logprob < avg_logprob or s.no_speech_prob > no_speech_prob:
|
if s.avg_logprob < avg_logprob or s.no_speech_prob > no_speech_prob:
|
||||||
continue
|
continue
|
||||||
text += s.text
|
text += s.text
|
||||||
|
except UnknownValueError:
|
||||||
except Exception:
|
|
||||||
pass
|
pass
|
||||||
|
except Exception:
|
||||||
|
errorLogging()
|
||||||
finally:
|
finally:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ from typing import Callable
|
|||||||
import huggingface_hub
|
import huggingface_hub
|
||||||
from faster_whisper import WhisperModel
|
from faster_whisper import WhisperModel
|
||||||
import logging
|
import logging
|
||||||
from utils import printLog
|
|
||||||
|
|
||||||
logger = logging.getLogger('faster_whisper')
|
logger = logging.getLogger('faster_whisper')
|
||||||
logger.setLevel(logging.CRITICAL)
|
logger.setLevel(logging.CRITICAL)
|
||||||
@@ -40,10 +39,8 @@ def downloadFile(url, path, func=None):
|
|||||||
if isinstance(func, Callable):
|
if isinstance(func, Callable):
|
||||||
total_chunk += len(chunk)
|
total_chunk += len(chunk)
|
||||||
func(total_chunk/file_size)
|
func(total_chunk/file_size)
|
||||||
printLog(f"Downloading Whisper Model: {total_chunk/file_size:.0%}")
|
except Exception:
|
||||||
|
pass
|
||||||
except Exception as e:
|
|
||||||
printLog("warning:downloadFile()", e)
|
|
||||||
|
|
||||||
def checkWhisperWeight(root, weight_type):
|
def checkWhisperWeight(root, weight_type):
|
||||||
path = os_path.join(root, "weights", "whisper", weight_type)
|
path = os_path.join(root, "weights", "whisper", weight_type)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from .translation_utils import ctranslate2_weights
|
|||||||
|
|
||||||
import ctranslate2
|
import ctranslate2
|
||||||
import transformers
|
import transformers
|
||||||
from utils import printLog
|
from utils import errorLogging
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
warnings.filterwarnings("ignore")
|
warnings.filterwarnings("ignore")
|
||||||
@@ -25,6 +25,7 @@ class Translator():
|
|||||||
self.deepl_client = deepl_Translator(authkey)
|
self.deepl_client = deepl_Translator(authkey)
|
||||||
self.deepl_client.translate_text(" ", target_lang="EN-US")
|
self.deepl_client.translate_text(" ", target_lang="EN-US")
|
||||||
except Exception:
|
except Exception:
|
||||||
|
errorLogging()
|
||||||
self.deepl_client = None
|
self.deepl_client = None
|
||||||
result = False
|
result = False
|
||||||
return result
|
return result
|
||||||
@@ -47,8 +48,8 @@ class Translator():
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
self.ctranslate2_tokenizer = transformers.AutoTokenizer.from_pretrained(tokenizer, cache_dir=tokenizer_path)
|
self.ctranslate2_tokenizer = transformers.AutoTokenizer.from_pretrained(tokenizer, cache_dir=tokenizer_path)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
printLog("error:changeCTranslate2Model()", e)
|
errorLogging()
|
||||||
tokenizer_path = os_path.join("./weights", "ctranslate2", directory_name, "tokenizer")
|
tokenizer_path = os_path.join("./weights", "ctranslate2", directory_name, "tokenizer")
|
||||||
self.ctranslate2_tokenizer = transformers.AutoTokenizer.from_pretrained(tokenizer, cache_dir=tokenizer_path)
|
self.ctranslate2_tokenizer = transformers.AutoTokenizer.from_pretrained(tokenizer, cache_dir=tokenizer_path)
|
||||||
self.is_loaded_ctranslate2_model = True
|
self.is_loaded_ctranslate2_model = True
|
||||||
@@ -67,7 +68,7 @@ class Translator():
|
|||||||
target = results[0].hypotheses[0][1:]
|
target = results[0].hypotheses[0][1:]
|
||||||
result = self.ctranslate2_tokenizer.decode(self.ctranslate2_tokenizer.convert_tokens_to_ids(target))
|
result = self.ctranslate2_tokenizer.decode(self.ctranslate2_tokenizer.convert_tokens_to_ids(target))
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
errorLogging()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -138,8 +139,7 @@ class Translator():
|
|||||||
source_language=source_language,
|
source_language=source_language,
|
||||||
target_language=target_language,
|
target_language=target_language,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
from utils import errorLogging
|
errorLogging()
|
||||||
errorLogging(e)
|
|
||||||
result = False
|
result = False
|
||||||
return result
|
return result
|
||||||
@@ -5,7 +5,7 @@ from os import makedirs as os_makedirs
|
|||||||
from requests import get as requests_get
|
from requests import get as requests_get
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
import hashlib
|
import hashlib
|
||||||
from utils import printLog
|
from utils import errorLogging
|
||||||
|
|
||||||
ctranslate2_weights = {
|
ctranslate2_weights = {
|
||||||
"small": { # M2M-100 418M-parameter model
|
"small": { # M2M-100 418M-parameter model
|
||||||
@@ -79,12 +79,11 @@ def downloadCTranslate2Weight(root, weight_type="small", callback=None, end_call
|
|||||||
if isinstance(callback, Callable):
|
if isinstance(callback, Callable):
|
||||||
total_chunk += len(chunk)
|
total_chunk += len(chunk)
|
||||||
callback(total_chunk/file_size)
|
callback(total_chunk/file_size)
|
||||||
printLog(f"Downloading CTranslate Model: {total_chunk/file_size:.0%}")
|
|
||||||
|
|
||||||
with ZipFile(os_path.join(tmp_path, filename)) as zf:
|
with ZipFile(os_path.join(tmp_path, filename)) as zf:
|
||||||
zf.extractall(path)
|
zf.extractall(path)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
printLog("warning:downloadCTranslate2Weight()", e)
|
errorLogging()
|
||||||
|
|
||||||
if isinstance(end_callback, Callable):
|
if isinstance(end_callback, Callable):
|
||||||
end_callback()
|
end_callback()
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
from typing import Callable
|
from typing import Callable
|
||||||
import time
|
import time
|
||||||
from utils import printLog
|
|
||||||
|
|
||||||
class Watchdog:
|
class Watchdog:
|
||||||
def __init__(self, timeout:int=60, interval:int=20):
|
def __init__(self, timeout:int=60, interval:int=20):
|
||||||
@@ -16,7 +15,6 @@ class Watchdog:
|
|||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
if time.time() - self.last_feed_time > self.timeout:
|
if time.time() - self.last_feed_time > self.timeout:
|
||||||
printLog("Watchdog timeout! Shutting down...")
|
|
||||||
if isinstance(self.callback, Callable):
|
if isinstance(self.callback, Callable):
|
||||||
self.callback()
|
self.callback()
|
||||||
time.sleep(self.interval)
|
time.sleep(self.interval)
|
||||||
@@ -96,7 +96,6 @@ def printResponse(status:int, endpoint:str, result:Any=None) -> None:
|
|||||||
response = json.dumps(response)
|
response = json.dumps(response)
|
||||||
print(response, flush=True)
|
print(response, flush=True)
|
||||||
|
|
||||||
def errorLogging(error:Exception) -> None:
|
def errorLogging() -> None:
|
||||||
with open('error.log', 'a') as f:
|
with open('error.log', 'a') as f:
|
||||||
f.write(f"error: {error}\n")
|
|
||||||
traceback.print_exc(file=f)
|
traceback.print_exc(file=f)
|
||||||
@@ -6,7 +6,7 @@ import re
|
|||||||
from device_manager import device_manager
|
from device_manager import device_manager
|
||||||
from config import config
|
from config import config
|
||||||
from model import model
|
from model import model
|
||||||
from utils import removeLog, printLog
|
from utils import removeLog, printLog, errorLogging
|
||||||
|
|
||||||
class Controller:
|
class Controller:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
@@ -706,6 +706,7 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
errorLogging()
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -745,6 +746,7 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
errorLogging()
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -769,6 +771,7 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
errorLogging()
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -793,6 +796,7 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
errorLogging()
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -879,6 +883,7 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
errorLogging()
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -917,6 +922,7 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
errorLogging()
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -941,6 +947,7 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
errorLogging()
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -966,6 +973,7 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
errorLogging()
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -1049,13 +1057,14 @@ class Controller:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
response = {
|
errorLogging()
|
||||||
"status":400,
|
response = {
|
||||||
"result":{
|
"status":400,
|
||||||
"message":f"Error {e}",
|
"result":{
|
||||||
"data": config.AUTH_KEYS["DeepL_API"]
|
"message":f"Error {e}",
|
||||||
}
|
"data": config.AUTH_KEYS["DeepL_API"]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def delDeeplAuthKey(self, *args, **kwargs) -> dict:
|
def delDeeplAuthKey(self, *args, **kwargs) -> dict:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from typing import Any
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from webui_controller import Controller
|
from webui_controller import Controller
|
||||||
from utils import printLog, printResponse, encodeBase64
|
from utils import printLog, printResponse, errorLogging, encodeBase64
|
||||||
|
|
||||||
controller = Controller()
|
controller = Controller()
|
||||||
|
|
||||||
@@ -334,8 +334,7 @@ class Main:
|
|||||||
status = response.get("status", None)
|
status = response.get("status", None)
|
||||||
result = response.get("result", None)
|
result = response.get("result", None)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
from utils import errorLogging
|
errorLogging()
|
||||||
errorLogging(e)
|
|
||||||
result = str(e)
|
result = str(e)
|
||||||
status = 500
|
status = 500
|
||||||
return result, status
|
return result, status
|
||||||
@@ -347,8 +346,7 @@ class Main:
|
|||||||
endpoint, data = self.queue.get()
|
endpoint, data = self.queue.get()
|
||||||
result, status = self.handleRequest(endpoint, data)
|
result, status = self.handleRequest(endpoint, data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
from utils import errorLogging
|
errorLogging()
|
||||||
errorLogging(e)
|
|
||||||
result = str(e)
|
result = str(e)
|
||||||
status = 500
|
status = 500
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user