byzh-core 0.0.2.8__py3-none-any.whl → 0.0.2.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- byzh_core/Bbasic/text_style.py +4 -3
- byzh_core/Bwriter/__init__.py +4 -2
- byzh_core/Bwriter/writer.py +34 -65
- byzh_core/__init__.py +1 -1
- {byzh_core-0.0.2.8.dist-info → byzh_core-0.0.2.10.dist-info}/METADATA +1 -1
- {byzh_core-0.0.2.8.dist-info → byzh_core-0.0.2.10.dist-info}/RECORD +9 -9
- {byzh_core-0.0.2.8.dist-info → byzh_core-0.0.2.10.dist-info}/LICENSE +0 -0
- {byzh_core-0.0.2.8.dist-info → byzh_core-0.0.2.10.dist-info}/WHEEL +0 -0
- {byzh_core-0.0.2.8.dist-info → byzh_core-0.0.2.10.dist-info}/top_level.txt +0 -0
byzh_core/Bbasic/text_style.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
from enum import Enum
|
1
2
|
# 字体颜色
|
2
|
-
class B_Color:
|
3
|
+
class B_Color(Enum):
|
3
4
|
RESET = "\033[0m"
|
4
5
|
|
5
6
|
BLACK = "\033[30m" # 黑
|
@@ -12,7 +13,7 @@ class B_Color:
|
|
12
13
|
SILVER = "\033[37m" # 灰/银
|
13
14
|
|
14
15
|
# 背景颜色
|
15
|
-
class B_Background:
|
16
|
+
class B_Background(Enum):
|
16
17
|
RESET = "\033[0m"
|
17
18
|
|
18
19
|
BLACK = "\033[40m" # 黑
|
@@ -25,7 +26,7 @@ class B_Background:
|
|
25
26
|
SILVER = "\033[47m" # 灰/银
|
26
27
|
|
27
28
|
# 效果
|
28
|
-
class B_Appearance:
|
29
|
+
class B_Appearance(Enum):
|
29
30
|
RESET = "\033[0m"
|
30
31
|
|
31
32
|
HIGHLIGHT = "\033[1m" # 高亮
|
byzh_core/Bwriter/__init__.py
CHANGED
byzh_core/Bwriter/writer.py
CHANGED
@@ -5,44 +5,29 @@ import os
|
|
5
5
|
|
6
6
|
from ..Bbasic import B_Color
|
7
7
|
|
8
|
-
COLOR_DICT = {
|
9
|
-
"default": B_Color.RESET,
|
10
|
-
|
11
|
-
"black": B_Color.BLACK,
|
12
|
-
"red": B_Color.RED,
|
13
|
-
"green": B_Color.GREEN,
|
14
|
-
"yellow": B_Color.YELLOW,
|
15
|
-
"blue": B_Color.BLUE,
|
16
|
-
"purple": B_Color.PURPLE,
|
17
|
-
"cyan": B_Color.CYAN,
|
18
|
-
"silver": B_Color.SILVER
|
19
|
-
}
|
20
|
-
Color_Literal = Literal["default", "black", "red", "green", "yellow", "blue", "purple", "cyan", "silver"]
|
21
|
-
|
22
8
|
class B_Writer:
|
23
9
|
def __init__(
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
10
|
+
self,
|
11
|
+
path:Path,
|
12
|
+
mode:Literal["w", "a"] = "w",
|
13
|
+
time_file:bool = False,
|
14
|
+
color:B_Color = B_Color.RESET,
|
28
15
|
):
|
29
16
|
'''
|
30
17
|
:param path: 日志保存路径
|
31
|
-
:param
|
18
|
+
:param time_file: 是否输出时间
|
32
19
|
'''
|
33
20
|
super().__init__()
|
34
21
|
self.path = Path(path)
|
35
|
-
self.
|
36
|
-
self.
|
37
|
-
self.toWant_cmd = False
|
22
|
+
self.mode = mode
|
23
|
+
self.time_file = time_file
|
38
24
|
|
39
|
-
self.
|
40
|
-
self.color = color
|
25
|
+
self.color = color.value
|
41
26
|
|
42
27
|
self.f = None
|
43
|
-
self.setFile(self.path, self.
|
28
|
+
self.setFile(self.path, self.mode, self.time_file)
|
44
29
|
|
45
|
-
def setFile(self, file: Path, ifTime=False):
|
30
|
+
def setFile(self, file: Path, mode: Literal["w", "a"] = "w", ifTime=False):
|
46
31
|
'''
|
47
32
|
设置 file的path 以及 writer的ifTime
|
48
33
|
:param file: 设置log路径
|
@@ -52,9 +37,9 @@ class B_Writer:
|
|
52
37
|
if self.f is not None:
|
53
38
|
self.f.close()
|
54
39
|
self.path = Path(file)
|
55
|
-
self.
|
40
|
+
self.time_file = ifTime
|
56
41
|
self.__createDir(self.path)
|
57
|
-
self.f = open(self.path,
|
42
|
+
self.f = open(self.path, mode, encoding="utf-8")
|
58
43
|
|
59
44
|
def clearFile(self):
|
60
45
|
'''
|
@@ -72,67 +57,51 @@ class B_Writer:
|
|
72
57
|
self.f.close()
|
73
58
|
self.f = None
|
74
59
|
|
75
|
-
def toCmd(self, string, color:
|
60
|
+
def toCmd(self, string:str, ifTime:bool=False, color:B_Color = None):
|
76
61
|
'''
|
77
62
|
打印到terminal
|
78
63
|
'''
|
79
|
-
|
64
|
+
t = ''
|
65
|
+
if ifTime:
|
66
|
+
t = time.strftime("%Y-%m-%d %H:%M:%S ##### ", time.localtime())
|
67
|
+
|
80
68
|
if color is None:
|
81
|
-
print(
|
69
|
+
print(self.color + t + str(string) + B_Color.RESET.value)
|
82
70
|
else:
|
83
|
-
|
84
|
-
print(COLOR_DICT.get(color) + str(string) + B_Color.RESET)
|
71
|
+
print(color.value + t + str(string) + B_Color.RESET.value)
|
85
72
|
|
86
|
-
def toFile(self, string, ifTime:bool=None):
|
73
|
+
def toFile(self, string:str, ifTime:bool=None):
|
87
74
|
'''
|
88
75
|
写入到文件内
|
89
76
|
'''
|
90
77
|
assert self.f is not None, "请先调用setFile方法"
|
91
78
|
|
92
|
-
|
79
|
+
t = ''
|
80
|
+
if ifTime == False: # 为了使False时不管self.time_file
|
93
81
|
pass
|
94
|
-
elif ifTime==True or self.
|
82
|
+
elif ifTime==True or self.time_file==True:
|
95
83
|
t = time.strftime("%Y-%m-%d %H:%M:%S ##### ", time.localtime())
|
96
|
-
self.f.write(t)
|
97
84
|
|
98
|
-
self.f.write(str(string))
|
85
|
+
self.f.write(str(string+t))
|
99
86
|
self.f.write("\n")
|
100
87
|
self.f.flush()
|
101
88
|
|
102
|
-
def toBoth(self, string,
|
89
|
+
def toBoth(self, string:str, file_time:bool=None, cmd_time:bool=False, color:B_Color = None):
|
103
90
|
'''
|
104
91
|
同时写入到文件和terminal
|
105
92
|
:param string:
|
106
93
|
:param color:
|
107
94
|
:return:
|
108
95
|
'''
|
109
|
-
self.toFile(str(string),
|
110
|
-
self.toCmd(str(string), color)
|
111
|
-
|
112
|
-
|
113
|
-
'''
|
114
|
-
toWant的全局选项设置
|
115
|
-
'''
|
116
|
-
self.toWant_cmd = toCmd
|
117
|
-
self.toWant_file = toFile
|
118
|
-
|
119
|
-
def toWant(self, string, ifTime:bool=None, color: Color_Literal = None):
|
120
|
-
'''
|
121
|
-
使用前先调用setWant方法
|
122
|
-
'''
|
123
|
-
if self.toWant_cmd and self.toWant_file:
|
124
|
-
self.toBoth(string, ifTime, color)
|
125
|
-
elif self.toWant_cmd:
|
126
|
-
self.toCmd(string, color)
|
127
|
-
elif self.toWant_file:
|
128
|
-
self.toFile(string, ifTime)
|
129
|
-
else:
|
130
|
-
raise Exception("请先调用setWant方法, 设置toCmd或toFile为True")
|
131
|
-
|
132
|
-
def __checkColor(self, color):
|
133
|
-
assert color in COLOR_DICT, f"color参数错误,请输入{list(COLOR_DICT.keys())}"
|
96
|
+
self.toFile(str(string), file_time)
|
97
|
+
self.toCmd(str(string), cmd_time, color)
|
98
|
+
def __call__(self, string:str, file_time:bool=None, cmd_time:bool=False, color:B_Color = None):
|
99
|
+
self.toBoth(string, file_time, cmd_time, color)
|
134
100
|
|
135
101
|
def __createDir(self, path):
|
136
102
|
# 获取到该文件的文件夹
|
137
103
|
dir = path.parents[0]
|
138
|
-
os.makedirs(dir, exist_ok=True)
|
104
|
+
os.makedirs(dir, exist_ok=True)
|
105
|
+
|
106
|
+
def __exit__(self):
|
107
|
+
self.closeFile()
|
byzh_core/__init__.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
byzh_core/B_os.py,sha256=-6KjK2NzEeF8GiQno0BmbVDei9DDxOaXdaKGqFeL_eY,2372
|
2
|
-
byzh_core/__init__.py,sha256=
|
2
|
+
byzh_core/__init__.py,sha256=_eON-uVsiKSG-pshFUM-Wh8LwmNJmJp00Eq8Re69fho,111
|
3
3
|
byzh_core/Barchive/__init__.py,sha256=wUdz646VS0Uhq9lwMkd3YQHCvQhLDqgADoDjFGMqIn0,65
|
4
4
|
byzh_core/Barchive/archive.py,sha256=6uMoOs-lmdcezdOgXr4s9NmjHVRDvG4v_YGQhaPPyGo,2681
|
5
5
|
byzh_core/Bbasic/__init__.py,sha256=wr7Y7YJINhgpV5X6BT5DaGJKcHUOZYNerCGXoi2Egac,116
|
6
|
-
byzh_core/Bbasic/text_style.py,sha256=
|
6
|
+
byzh_core/Bbasic/text_style.py,sha256=waaj_DKg6eBEyM3kcdpPJtghLPIR171opIjx4rXrUus,3202
|
7
7
|
byzh_core/Bmath/__init__.py,sha256=G3AQug6izkEX3UfzO_mqUNJW88ZKlmYb4Q8CAactK4w,105
|
8
8
|
byzh_core/Bmath/divides.py,sha256=dr85IqGSE9NvugQu7az29GLcjRiLjXU_hZTwtNifIXg,1132
|
9
9
|
byzh_core/Bmath/get_norm.py,sha256=y1QsCTo7qhtGTXIxpc6JtamLWloC7ENRuVdNtK5yi58,596
|
@@ -13,16 +13,16 @@ byzh_core/Bterminal/__init__.py,sha256=B6p6mHVhi5LAHKlvqfrv20E6XNqUsfU2xD753V6-Z
|
|
13
13
|
byzh_core/Bterminal/cmd.py,sha256=iK0fwI0D3peEwUYYZWwnl9X8ImFfrBsEq6ySd3DcRdE,3839
|
14
14
|
byzh_core/Btqdm/__init__.py,sha256=PQRcUn9WXd1YGyFMEKnJU74mdV695_8NHQ56Nsja0DM,53
|
15
15
|
byzh_core/Btqdm/my_tqdm.py,sha256=myyFo3GgyX_wWfSjMWfSTkcnTECf1tqwpXEFpJkzNtw,2878
|
16
|
-
byzh_core/Bwriter/__init__.py,sha256=
|
17
|
-
byzh_core/Bwriter/writer.py,sha256=
|
16
|
+
byzh_core/Bwriter/__init__.py,sha256=QcHzKs0305Pr78ZvZgcC_4miSYZh8jJQDt5TD0GIeEg,82
|
17
|
+
byzh_core/Bwriter/writer.py,sha256=S-tIwBUcU9_qFWP9JdCiFITg_hz76afXrqHWp-0ltIA,3104
|
18
18
|
byzh_core/obsolete/__init__.py,sha256=wpfHMPD4awPRDJVYlaiGtkkpjq2srWB7d7LrWhoX5R0,161
|
19
19
|
byzh_core/obsolete/auto_table.py,sha256=nC9eHj_IIGVkS2lmN_1gtOyglLCaGlwdoHzPvNNQDEw,13952
|
20
20
|
byzh_core/obsolete/row_table.py,sha256=rIX0-Yvb3RnO0RJBkA4m18gux1zYSnEKTy6uQGcWilc,5999
|
21
21
|
byzh_core/obsolete/xy_table.py,sha256=-KHK8EUlkJj3Rh0sp_KHI0QFt29AlMASMmR8q8ykUBM,6784
|
22
22
|
byzh_core/obsolete/Bconfig/__init__.py,sha256=7lAp7wNetW0AyJcike7ekdY_8wrQQtFjBsi6684t_lU,54
|
23
23
|
byzh_core/obsolete/Bconfig/config.py,sha256=TD8CC1P2Zu95Tf8AGK2IHRXjrCCMBA_tdoZsc1Rr0Gk,10953
|
24
|
-
byzh_core-0.0.2.
|
25
|
-
byzh_core-0.0.2.
|
26
|
-
byzh_core-0.0.2.
|
27
|
-
byzh_core-0.0.2.
|
28
|
-
byzh_core-0.0.2.
|
24
|
+
byzh_core-0.0.2.10.dist-info/LICENSE,sha256=-nRwf0Xga4AX5bsWBXXflpDpgX_U23X06oAMcdf0dSY,1089
|
25
|
+
byzh_core-0.0.2.10.dist-info/METADATA,sha256=gTKeddJiFqIxgtBtOvu_MI5_VU61LwUn8d1TNTgqxis,372
|
26
|
+
byzh_core-0.0.2.10.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
27
|
+
byzh_core-0.0.2.10.dist-info/top_level.txt,sha256=Xv-pzvl6kPdIbi5UehQcUdGhLtb8-4WhS5dRK1LINwM,10
|
28
|
+
byzh_core-0.0.2.10.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|