add some typing write sysinfo to logs
This commit is contained in:
parent
8e2d907145
commit
21b67c364c
@ -11,11 +11,11 @@ github: @shenjackyuanjie
|
|||||||
gitee: @shenjackyuanjie
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import contextlib
|
|
||||||
# import ctypes
|
# import ctypes
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
import traceback
|
import traceback
|
||||||
|
import contextlib
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from Difficult_Rocket.api.types import Options
|
from Difficult_Rocket.api.types import Options
|
||||||
@ -70,7 +70,7 @@ class _DR_option(Options):
|
|||||||
# tests
|
# tests
|
||||||
playing: bool = False
|
playing: bool = False
|
||||||
debugging: bool = False
|
debugging: bool = False
|
||||||
crash_report_test: bool = False
|
crash_report_test: bool = True
|
||||||
pyglet_macosx_dev_test: bool = True
|
pyglet_macosx_dev_test: bool = True
|
||||||
|
|
||||||
# window option
|
# window option
|
||||||
|
@ -92,8 +92,8 @@ class Client:
|
|||||||
self.use_time = end_time - start_time
|
self.use_time = end_time - start_time
|
||||||
if DR_option.use_DR_rust:
|
if DR_option.use_DR_rust:
|
||||||
from libs.Difficult_Rocket_rs import read_ship_test, part_list_read_test
|
from libs.Difficult_Rocket_rs import read_ship_test, part_list_read_test
|
||||||
part_list_read_test()
|
# part_list_read_test()
|
||||||
read_ship_test()
|
# read_ship_test()
|
||||||
|
|
||||||
self.logger.info(tr().client.setup.use_time().format(Decimal(self.use_time) / 1000000000))
|
self.logger.info(tr().client.setup.use_time().format(Decimal(self.use_time) / 1000000000))
|
||||||
self.logger.debug(tr().client.setup.use_time_ns().format(self.use_time))
|
self.logger.debug(tr().client.setup.use_time_ns().format(self.use_time))
|
||||||
|
@ -19,7 +19,7 @@ import traceback
|
|||||||
import threading
|
import threading
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, TextIO
|
from typing import Optional, Union, TextIO
|
||||||
|
|
||||||
# import psutil
|
# import psutil
|
||||||
# for more system info
|
# for more system info
|
||||||
@ -52,7 +52,7 @@ all_thread = [threading.main_thread()]
|
|||||||
all_process = [multiprocessing.current_process()]
|
all_process = [multiprocessing.current_process()]
|
||||||
|
|
||||||
|
|
||||||
def crash_info_handler(info: str = None) -> str:
|
def crash_info_handler(info: Optional[str] = None) -> str:
|
||||||
if not info:
|
if not info:
|
||||||
info = traceback.format_exc().replace('<', '< ')
|
info = traceback.format_exc().replace('<', '< ')
|
||||||
format_info = f"<pre>\n{info}</pre>\n"
|
format_info = f"<pre>\n{info}</pre>\n"
|
||||||
@ -60,7 +60,7 @@ def crash_info_handler(info: str = None) -> str:
|
|||||||
return format_info
|
return format_info
|
||||||
|
|
||||||
|
|
||||||
def markdown_line_handler(string: Optional[str or bool or int or float], code: bool = False, level: int = 1,
|
def markdown_line_handler(string: Optional[Union[str, bool, int, float]], code: bool = False, level: int = 1,
|
||||||
end: str = '\n') -> str:
|
end: str = '\n') -> str:
|
||||||
lvl = '- ' * level
|
lvl = '- ' * level
|
||||||
f_string = string
|
f_string = string
|
||||||
@ -85,7 +85,7 @@ def write_markdown_tablet(crash_file: TextIO, tablet: list) -> None:
|
|||||||
f'| `{a}`{" " * (a_len - len(a))} | `{b}`{" " * (b_len - len(b))} | `{c}`{" " * (c_len - len(c))} |\n')
|
f'| `{a}`{" " * (a_len - len(a))} | `{b}`{" " * (b_len - len(b))} | `{c}`{" " * (c_len - len(c))} |\n')
|
||||||
|
|
||||||
|
|
||||||
def create_crash_report(info: str = None) -> None:
|
def create_crash_report(info: Optional[str] = None) -> None:
|
||||||
crash_info = crash_info_handler(info)
|
crash_info = crash_info_handler(info)
|
||||||
if 'crash_report' not in os.listdir('./'):
|
if 'crash_report' not in os.listdir('./'):
|
||||||
os.mkdir('./crash_report')
|
os.mkdir('./crash_report')
|
||||||
@ -94,6 +94,7 @@ def create_crash_report(info: str = None) -> None:
|
|||||||
cache_stream = io.StringIO()
|
cache_stream = io.StringIO()
|
||||||
try:
|
try:
|
||||||
write_cache(cache_stream, crash_info)
|
write_cache(cache_stream, crash_info)
|
||||||
|
write_info_to_cache(cache_stream)
|
||||||
finally:
|
finally:
|
||||||
get_cache = cache_stream.getvalue()
|
get_cache = cache_stream.getvalue()
|
||||||
cache_stream.close()
|
cache_stream.close()
|
||||||
@ -106,6 +107,9 @@ def write_cache(cache_stream, crash_info):
|
|||||||
cache_stream.write(Head_message.format(now_time=time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(time.time()))))
|
cache_stream.write(Head_message.format(now_time=time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(time.time()))))
|
||||||
# 崩溃信息
|
# 崩溃信息
|
||||||
cache_stream.write(crash_info)
|
cache_stream.write(crash_info)
|
||||||
|
|
||||||
|
|
||||||
|
def write_info_to_cache(cache_stream):
|
||||||
# 运行状态信息
|
# 运行状态信息
|
||||||
from Difficult_Rocket import DR_option, DR_runtime
|
from Difficult_Rocket import DR_option, DR_runtime
|
||||||
cache_stream.write(Run_message)
|
cache_stream.write(Run_message)
|
||||||
|
@ -18,12 +18,15 @@ import logging
|
|||||||
import logging.config
|
import logging.config
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
if __name__ == '__main__': # been start will not run this
|
if __name__ == '__main__': # been start will not run this
|
||||||
sys.path.append('/bin/libs')
|
sys.path.append('/bin/libs')
|
||||||
sys.path.append('/bin')
|
sys.path.append('/bin')
|
||||||
|
|
||||||
from Difficult_Rocket import client, server, DR_option
|
from Difficult_Rocket import client, server, DR_option
|
||||||
|
|
||||||
|
from Difficult_Rocket.crash import write_info_to_cache
|
||||||
from Difficult_Rocket.utils import tools
|
from Difficult_Rocket.utils import tools
|
||||||
from Difficult_Rocket.utils.translate import tr
|
from Difficult_Rocket.utils.translate import tr
|
||||||
|
|
||||||
@ -53,9 +56,16 @@ class Game:
|
|||||||
self.logger.info(tr().language_set_to())
|
self.logger.info(tr().language_set_to())
|
||||||
self.logger.info(tr().main.logger.created())
|
self.logger.info(tr().main.logger.created())
|
||||||
# version check
|
# version check
|
||||||
|
self.log_env()
|
||||||
self.python_version_check()
|
self.python_version_check()
|
||||||
self.setup()
|
self.setup()
|
||||||
|
|
||||||
|
def log_env(self) -> None:
|
||||||
|
cache_steam = StringIO()
|
||||||
|
write_info_to_cache(cache_steam)
|
||||||
|
text = cache_steam.getvalue()
|
||||||
|
self.logger.info(text)
|
||||||
|
|
||||||
def setup(self) -> None:
|
def setup(self) -> None:
|
||||||
self.client = client.Client(net_mode='local')
|
self.client = client.Client(net_mode='local')
|
||||||
self.server = server.Server(net_mode='local')
|
self.server = server.Server(net_mode='local')
|
||||||
|
@ -3,6 +3,11 @@ language_set_to = "Language set to: English"
|
|||||||
language_available = "Available languages list: {}"
|
language_available = "Available languages list: {}"
|
||||||
|
|
||||||
[main]
|
[main]
|
||||||
|
env.version.python = "Python version: {}"
|
||||||
|
env.version.DR = "Difficult_Rocket version: {}"
|
||||||
|
env.version.DR_rs = "Difficult_Rocket_rs version: {}"
|
||||||
|
env.version.pyglet = "pyglet version: {}"
|
||||||
|
env.version.pyglet_rs = "pyglet_rs version: {}"
|
||||||
version.now_on = "Difficult Rocket is running on Python Vision"
|
version.now_on = "Difficult Rocket is running on Python Vision"
|
||||||
version.need3p = "Difficult Rocket depends on Python vision 3.0+"
|
version.need3p = "Difficult Rocket depends on Python vision 3.0+"
|
||||||
version.best38p = "Difficult Rocket is writen in Python {write_py_v}, and now is running on Python {py_v} may cause BUG"
|
version.best38p = "Difficult Rocket is writen in Python {write_py_v}, and now is running on Python {py_v} may cause BUG"
|
||||||
|
@ -3,10 +3,15 @@ language_set_to = "语言已经设置为:简体中文"
|
|||||||
language_available = "可用语言列表: {}"
|
language_available = "可用语言列表: {}"
|
||||||
|
|
||||||
[main]
|
[main]
|
||||||
|
env.version.python = "Python 版本: {}"
|
||||||
|
env.version.DR = "Difficult_Rocket 版本: {}"
|
||||||
|
env.version.DR_rs = "Difficult_Rocket_rs 版本: {}"
|
||||||
|
env.version.pyglet = "pyglet 版本: {}"
|
||||||
|
env.version.pyglet_rs = "pyglet_rs 版本: {}"
|
||||||
version.now_on = "困难火箭的运行 Python 环境为"
|
version.now_on = "困难火箭的运行 Python 环境为"
|
||||||
version.need3p = "困难火箭需要 Python3.0+ 的环境"
|
version.need3p = "困难火箭需要 Python3.0+ 的环境"
|
||||||
version.best38p = "困难火箭是在 Python {write_py_v} 的环境下编写的,目前正在运行在Python {py_v}的环境下,可能产生BUG"
|
version.best38p = "困难火箭是在 Python {write_py_v} 的环境下编写的,目前正在运行在Python {py_v}的环境下,可能产生BUG"
|
||||||
lang.language = "简 体 中 文 (zh-cn)"
|
lang.language = "简 体 中 文 (zh-cn)"
|
||||||
logger.language = "日志记录语言为:"
|
logger.language = "日志记录语言为:"
|
||||||
logger.created = "日志处理器创建完成"
|
logger.created = "日志处理器创建完成"
|
||||||
logger.mkdir = "logs/ 文件夹不存在,已经新建文件夹"
|
logger.mkdir = "logs/ 文件夹不存在,已经新建文件夹"
|
||||||
|
Loading…
Reference in New Issue
Block a user