rua
This commit is contained in:
parent
3b9848fd20
commit
bd88ec8684
2
DR.py
2
DR.py
@ -40,7 +40,7 @@ if __name__ == '__main__':
|
||||
print(hi)
|
||||
|
||||
DEBUGGING = False
|
||||
from Difficult_Rocket.api.Exp import *
|
||||
from Difficult_Rocket.exception import TestError
|
||||
from Difficult_Rocket.crash import crash
|
||||
try:
|
||||
start_time = time.perf_counter_ns()
|
||||
|
@ -15,11 +15,6 @@ gitee: @shenjackyuanjie
|
||||
from .delivery import Delivery
|
||||
|
||||
# lazy之后之前全部导入的(太多了写不动__all__了)
|
||||
from .Exp import *
|
||||
from .calculation import *
|
||||
from .scientific_unit import *
|
||||
|
||||
__all__ = ['TexturesError',
|
||||
'LanguageError',
|
||||
'TestError',
|
||||
'Delivery']
|
||||
|
@ -10,5 +10,3 @@ mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from Difficult_Rocket.api.Exp.main import Error
|
24
Difficult_Rocket/api/exception/command.py
Normal file
24
Difficult_Rocket/api/exception/command.py
Normal file
@ -0,0 +1,24 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021-2022 by shenjackyuanjie 3695888@qq.com
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from Difficult_Rocket.exception.command import *
|
||||
|
||||
__all__ = [
|
||||
"CommandError",
|
||||
"CommandParseError",
|
||||
"CommandQMarkMissing",
|
||||
"CommandQMarkPosError",
|
||||
"CommandQMarkConflict",
|
||||
"CommandQMarkSufMissing",
|
||||
"CommandQMarkPreMissing"
|
||||
]
|
12
Difficult_Rocket/api/exception/logger.py
Normal file
12
Difficult_Rocket/api/exception/logger.py
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021-2022 by shenjackyuanjie 3695888@qq.com
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
from Difficult_Rocket.exception.logger import *
|
||||
|
||||
__all__ = [
|
||||
"LogFileLockTimeOutError"
|
||||
]
|
@ -4,6 +4,8 @@
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
from Difficult_Rocket.api.Exp import Error
|
||||
|
||||
from Difficult_Rocket.exception.threading import *
|
||||
|
||||
__all__ = [
|
||||
"LockTimeOutError"
|
||||
]
|
@ -11,5 +11,12 @@ github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from Difficult_Rocket.api.Exp.main import Error
|
||||
from Difficult_Rocket.exception.unsupport import *
|
||||
|
||||
__all__ = [
|
||||
'NoMoreJson5',
|
||||
'Nope418ImATeapot',
|
||||
'ThinkError',
|
||||
'BrainError',
|
||||
'BigBrainError'
|
||||
]
|
@ -28,7 +28,7 @@ from Difficult_Rocket.utils.translate import tr
|
||||
from Difficult_Rocket.guis.widgets import InputBox
|
||||
# from Difficult_Rocket.client.screen import DRScreen
|
||||
from Difficult_Rocket.utils import tools, translate
|
||||
from Difficult_Rocket.api.Exp.command import CommandError
|
||||
from Difficult_Rocket.exception.command import CommandError
|
||||
from Difficult_Rocket.client.fps.fps_log import FpsLogger
|
||||
|
||||
from libs import pyglet
|
||||
|
@ -17,7 +17,7 @@ import re
|
||||
from typing import Union, Optional, Type, Tuple, List
|
||||
|
||||
# DR
|
||||
from Difficult_Rocket.api.Exp.command import *
|
||||
from Difficult_Rocket.exception.command import *
|
||||
|
||||
search_re = re.compile(r'(?<!\\)"')
|
||||
|
||||
|
@ -5,107 +5,28 @@
|
||||
# -------------------------------
|
||||
|
||||
"""
|
||||
main.py
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
"""基础 Exception"""
|
||||
class BaseError(Exception):
|
||||
"""基本 exp"""
|
||||
|
||||
def __bool__(self):
|
||||
def __bool__(self) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
class TexturesError(Error):
|
||||
"""材质相关 error"""
|
||||
class BaseRuntimeError(RuntimeError):
|
||||
"""基本 runtime exp"""
|
||||
|
||||
def __bool__(self) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
class LanguageError(Error):
|
||||
"""语言相关 error"""
|
||||
class TestError(BaseRuntimeError):
|
||||
"""在 test 啦"""
|
||||
|
||||
|
||||
class TestError(Error):
|
||||
"""就像名字一样 用于测试的 error"""
|
||||
|
||||
|
||||
"""
|
||||
unsupport.py
|
||||
"""
|
||||
|
||||
|
||||
class NoMoreJson5(Error):
|
||||
"""说什么我也不用Json5了!"""
|
||||
|
||||
|
||||
class Nope418ImATeapot(Error):
|
||||
"""我只是个茶壶而已,我不能煮咖啡!"""
|
||||
|
||||
|
||||
class ThinkError(Error):
|
||||
"""进不去,进不去,怎么想都进不去!"""
|
||||
|
||||
|
||||
class BrainError(Error):
|
||||
"""clever brain.png"""
|
||||
|
||||
|
||||
class BigBrainError(BrainError):
|
||||
"""bigbrain.png"""
|
||||
|
||||
|
||||
class BrainTimeoutError(BrainError, ThinkError):
|
||||
"""脑子····超时·······················啦!"""
|
||||
|
||||
|
||||
"""
|
||||
command.py
|
||||
"""
|
||||
|
||||
|
||||
class CommandError(Error):
|
||||
"""命令解析相关 error"""
|
||||
|
||||
|
||||
class CommandParseError(CommandError):
|
||||
"""命令解析时出现错误"""
|
||||
|
||||
|
||||
# QMark -> Quotation marks
|
||||
# Pos -> Position
|
||||
|
||||
class CommandQMarkPosError(CommandParseError):
|
||||
"""命令中,引号位置不正确
|
||||
例如: /command "aabcc "awdawd"""
|
||||
|
||||
|
||||
class CommandQMarkMissing(CommandParseError):
|
||||
"""命令中引号缺失
|
||||
例如: /command "aawwdawda awdaw """
|
||||
|
||||
|
||||
class CommandQMarkConflict(CommandParseError):
|
||||
"""命令中引号位置冲突
|
||||
例如: /command "aaaa "aaaa aaaa"""
|
||||
first_qmark_pos = None
|
||||
conflict_qmark_pos = None
|
||||
|
||||
|
||||
class CommandQMarkPreMissing(CommandQMarkMissing):
|
||||
"""命令中 前面的引号缺失
|
||||
例如: /command aaaa" aaaaaa"""
|
||||
suf_qmark_pos = None
|
||||
|
||||
|
||||
class CommandQMarkSufMissing(CommandQMarkMissing):
|
||||
"""命令中 后面的引号缺失(引号未闭合)
|
||||
例如: /command "aaaawaa some command"""
|
||||
pre_qmark_pos = None
|
||||
|
||||
|
||||
"""
|
||||
threading.py
|
||||
"""
|
||||
|
||||
|
||||
class LockTimeOutError(Error):
|
||||
"""没有特殊指定的 ”某个“ 锁超时了"""
|
||||
|
64
Difficult_Rocket/exception/command.py
Normal file
64
Difficult_Rocket/exception/command.py
Normal file
@ -0,0 +1,64 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021-2022 by shenjackyuanjie 3695888@qq.com
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
from Difficult_Rocket.exception import BaseRuntimeError
|
||||
|
||||
__all__ = [
|
||||
"CommandError",
|
||||
"CommandParseError",
|
||||
"CommandQMarkMissing",
|
||||
"CommandQMarkPosError",
|
||||
"CommandQMarkConflict",
|
||||
"CommandQMarkSufMissing",
|
||||
"CommandQMarkPreMissing"
|
||||
]
|
||||
|
||||
|
||||
class CommandError(BaseRuntimeError):
|
||||
"""命令解析相关 error"""
|
||||
|
||||
|
||||
class CommandParseError(CommandError):
|
||||
"""命令解析时出现错误"""
|
||||
|
||||
|
||||
# QMark -> Quotation marks
|
||||
# Pos -> Position
|
||||
|
||||
class CommandQMarkPosError(CommandParseError):
|
||||
"""命令中,引号位置不正确
|
||||
例如: /command "aabcc "awdawd"""
|
||||
|
||||
|
||||
class CommandQMarkMissing(CommandParseError):
|
||||
"""命令中引号缺失
|
||||
例如: /command "aawwdawda awdaw """
|
||||
|
||||
|
||||
class CommandQMarkConflict(CommandParseError):
|
||||
"""命令中引号位置冲突
|
||||
例如: /command "aaaa "aaaa aaaa"""
|
||||
first_qmark_pos = None
|
||||
conflict_qmark_pos = None
|
||||
|
||||
|
||||
class CommandQMarkPreMissing(CommandQMarkMissing):
|
||||
"""命令中 前面的引号缺失
|
||||
例如: /command aaaa" aaaaaa"""
|
||||
suf_qmark_pos = None
|
||||
|
||||
|
||||
class CommandQMarkSufMissing(CommandQMarkMissing):
|
||||
"""命令中 后面的引号缺失(引号未闭合)
|
||||
例如: /command "aaaawaa some command"""
|
||||
pre_qmark_pos = None
|
||||
|
30
Difficult_Rocket/exception/language.py
Normal file
30
Difficult_Rocket/exception/language.py
Normal file
@ -0,0 +1,30 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021-2022 by shenjackyuanjie 3695888@qq.com
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
from Difficult_Rocket.exception import BaseError, BaseRuntimeError
|
||||
|
||||
|
||||
__all__ = ['LanguageNotFound',
|
||||
'TranslateError',
|
||||
'TranslateKeyNotFound',
|
||||
'TranslateFileNotFound']
|
||||
|
||||
|
||||
class LanguageNotFound(BaseError):
|
||||
"""语言文件缺失"""
|
||||
|
||||
|
||||
class TranslateError(BaseError):
|
||||
"""翻译相关问题"""
|
||||
|
||||
|
||||
class TranslateKeyNotFound(TranslateError):
|
||||
"""语言文件某项缺失"""
|
||||
|
||||
|
||||
class TranslateFileNotFound(TranslateError):
|
||||
"""翻译文件缺失"""
|
||||
|
14
Difficult_Rocket/exception/logger.py
Normal file
14
Difficult_Rocket/exception/logger.py
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021-2022 by shenjackyuanjie 3695888@qq.com
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
from Difficult_Rocket.exception.threading import LockTimeOutError
|
||||
|
||||
__all__ = ["LogFileLockTimeOutError"]
|
||||
|
||||
|
||||
class LogFileLockTimeOutError(LockTimeOutError):
|
||||
"""日志文件写入锁超时"""
|
@ -11,5 +11,3 @@ github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from . import Error
|
||||
|
12
Difficult_Rocket/exception/threading.py
Normal file
12
Difficult_Rocket/exception/threading.py
Normal file
@ -0,0 +1,12 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021-2022 by shenjackyuanjie 3695888@qq.com
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
from exception import BaseRuntimeError
|
||||
|
||||
__all__ = ["LockTimeOutError"]
|
||||
|
||||
|
||||
class LockTimeOutError(BaseRuntimeError):
|
||||
"""没有特殊指定的 ”某个“ 锁超时了"""
|
45
Difficult_Rocket/exception/unsupport.py
Normal file
45
Difficult_Rocket/exception/unsupport.py
Normal file
@ -0,0 +1,45 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021-2022 by shenjackyuanjie 3695888@qq.com
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
from exception import BaseError
|
||||
|
||||
__all__ = [
|
||||
'NoMoreJson5',
|
||||
'Nope418ImATeapot',
|
||||
'ThinkError',
|
||||
'BrainError',
|
||||
'BigBrainError'
|
||||
]
|
||||
|
||||
|
||||
class NoMoreJson5(BaseError):
|
||||
"""说什么我也不用Json5了!"""
|
||||
|
||||
|
||||
class Nope418ImATeapot(BaseError):
|
||||
"""我只是个茶壶而已,我不能煮咖啡!"""
|
||||
|
||||
|
||||
class ThinkError(BaseError):
|
||||
"""进不去,进不去,怎么想都进不去!"""
|
||||
|
||||
|
||||
class BrainError(BaseError):
|
||||
"""clever brain.png"""
|
||||
|
||||
|
||||
class BigBrainError(BrainError):
|
||||
"""bigbrain.png"""
|
||||
|
||||
|
||||
class BrainTimeoutError(BrainError, ThinkError):
|
||||
"""脑子····超时·······················啦!"""
|
@ -22,7 +22,7 @@ from xml.dom.minidom import parse
|
||||
|
||||
from libs import toml
|
||||
|
||||
from Difficult_Rocket.api.Exp import NoMoreJson5
|
||||
from Difficult_Rocket.exception.unsupport import NoMoreJson5
|
||||
|
||||
# logger
|
||||
tools_logger = logging.getLogger('part-tools')
|
||||
|
@ -13,7 +13,7 @@ gitee: @shenjackyuanjie
|
||||
|
||||
from typing import Union
|
||||
|
||||
from Difficult_Rocket.api.Exp import *
|
||||
from Difficult_Rocket.exception.language import *
|
||||
from Difficult_Rocket.utils import tools
|
||||
|
||||
"""
|
||||
@ -51,7 +51,7 @@ class Lang:
|
||||
try:
|
||||
return self.默认翻译[item]
|
||||
except KeyError:
|
||||
raise LanguageError(f'there\'s no key {item} in both {self.语言} and zh-CN')
|
||||
raise TranslateKeyNotFound(f'there\'s no key {item} in both {self.语言} and zh-CN')
|
||||
|
||||
def __setitem__(self, key, value) -> None:
|
||||
if key == 'language' or key == 'lang':
|
||||
@ -61,7 +61,7 @@ class Lang:
|
||||
except FileNotFoundError:
|
||||
if self.直接返回原始数据:
|
||||
return None
|
||||
raise LanguageError(f'{value}\'s language toml file not found')
|
||||
raise TranslateKeyNotFound(f'{value}\'s language toml file not found')
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
@ -70,7 +70,7 @@ class Lang:
|
||||
self.翻译结果 = tools.load_file(f'configs/lang/{language}.toml')
|
||||
self.语言 = language
|
||||
except FileNotFoundError:
|
||||
raise LanguageError(f'{language}\'s language toml file not found')
|
||||
raise TranslateKeyNotFoundError(f'{language}\'s language toml file not found')
|
||||
|
||||
def lang(self, *args) -> Union[int, str, list, dict]:
|
||||
try:
|
||||
@ -87,7 +87,7 @@ class Lang:
|
||||
except KeyError:
|
||||
if self.直接返回原始数据:
|
||||
return args
|
||||
raise LanguageError(f'there\'s no key {args} in both {self.语言} and zh-CN')
|
||||
raise TranslateKeyNotFoundError(f'there\'s no key {args} in both {self.语言} and zh-CN')
|
||||
|
||||
def 翻译(self, *args) -> Union[int, str, list, dict]:
|
||||
return self.lang(args)
|
||||
|
@ -15,6 +15,8 @@
|
||||
- [![Readme-gitee](https://img.shields.io/badge/Readme-中文(点我!)-blue.svg?style=flat-square)](README-cn.md)
|
||||
- Using [SemVer 2.0.0](https://semver.org/) to manage version
|
||||
|
||||
## 20220627
|
||||
|
||||
## 20220511 V 0.6.3
|
||||
|
||||
- 咕了好久的 update log 了
|
||||
|
@ -3,7 +3,7 @@ import threading
|
||||
from time import strftime
|
||||
from typing import Optional
|
||||
|
||||
from Difficult_Rocket.api.Exp.threading import
|
||||
from Difficult_Rocket.exception import
|
||||
|
||||
color_reset_suffix = "\033[0m"
|
||||
|
||||
@ -19,7 +19,7 @@ class LogFileCache:
|
||||
# 写入缓存数
|
||||
self.cache_count = 0
|
||||
# 日志缓存表
|
||||
self.log_caches = []
|
||||
self.logs_cache = []
|
||||
# 同步锁
|
||||
self.thread_lock = threading.Lock()
|
||||
|
||||
@ -29,6 +29,8 @@ class LogFileCache:
|
||||
|
||||
@logfile_name.setter
|
||||
def logfile_name(self, value: str) -> None:
|
||||
with self.thread_lock.acquire(timeout=1/60):
|
||||
...
|
||||
self.thread_lock.acquire(timeout=1/60)
|
||||
if not self.thread_lock.locked():
|
||||
...
|
||||
@ -39,10 +41,10 @@ class LogFileCache:
|
||||
return None
|
||||
...
|
||||
|
||||
def make_log(self, string: str, wait_for_cache: bool = True) -> None:
|
||||
def write_logs(self, string: str, wait_for_cache: bool = True) -> None:
|
||||
if wait_for_cache:
|
||||
with open(file=self.logfile_name, encoding='utf-8', mode='a') as log_file:
|
||||
log_file.writelines(self.log_caches)
|
||||
log_file.writelines(self.logs_cache)
|
||||
log_file.write(string)
|
||||
...
|
||||
else:
|
||||
@ -59,7 +61,7 @@ class Logger:
|
||||
self.config = config
|
||||
|
||||
|
||||
class GetLogger:
|
||||
class LoggerManager:
|
||||
"""shenjack牌logger"""
|
||||
|
||||
def __init__(self):
|
||||
@ -69,5 +71,12 @@ class GetLogger:
|
||||
self.configs[name] = config
|
||||
return self.configs
|
||||
|
||||
def logger(self, name: str = 'root') -> Logger:
|
||||
def get_logger(self, name: str = 'root', config: dict = None) -> Logger:
|
||||
"""相当于 logging.getLogger(name='root')"""
|
||||
if not config is None:
|
||||
self.add_config(name, config)
|
||||
return Logger(config=self.configs)
|
||||
|
||||
logger_manager = LoggerManager()
|
||||
get_logger = logger_manager.get_logger
|
||||
# shenjack.get_logger()
|
||||
|
Loading…
Reference in New Issue
Block a user