byzh-core 0.0.2.7__py3-none-any.whl → 0.0.2.9__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.
@@ -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" # 高亮
@@ -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
- self,
25
- path: Path,
26
- ifTime: bool = False,
27
- color: Color_Literal = 'default',
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 ifTime: 是否输出时间
18
+ :param time_file: 是否输出时间
32
19
  '''
33
20
  super().__init__()
34
21
  self.path = Path(path)
35
- self.ifTime = ifTime
36
- self.toWant_file = False
37
- self.toWant_cmd = False
22
+ self.mode = mode
23
+ self.time_file = time_file
38
24
 
39
- self.__checkColor(color)
40
- self.color = color
25
+ self.color = color.value
41
26
 
42
27
  self.f = None
43
- self.setFile(self.path, self.ifTime)
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.ifTime = ifTime
40
+ self.time_file = ifTime
56
41
  self.__createDir(self.path)
57
- self.f = open(self.path, "a", encoding="utf-8")
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: Color_Literal = None):
60
+ def toCmd(self, string:str, ifTime:bool=False, color:B_Color = None):
76
61
  '''
77
62
  打印到terminal
78
63
  '''
79
- # 检查color是否在字典中
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(COLOR_DICT.get(self.color) + str(string) + B_Color.RESET)
69
+ print(self.color + t + str(string) + B_Color.RESET.value)
82
70
  else:
83
- assert color in COLOR_DICT, f"color参数错误,请输入{COLOR_DICT.keys()}"
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=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
- if ifTime == False:
79
+ t = ''
80
+ if ifTime == False: # 为了使False时不管self.time_file
93
81
  pass
94
- elif ifTime==True or self.ifTime==True:
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, ifTime=False, color: Color_Literal = None):
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), ifTime)
110
- self.toCmd(str(string), color)
111
-
112
- def setWant(self, toCmd=False, toFile=False):
113
- '''
114
- toWant的全局选项设置
115
- '''
116
- self.toWant_cmd = toCmd
117
- self.toWant_file = toFile
118
-
119
- def toWant(self, string, ifTime=False, 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
@@ -2,4 +2,4 @@
2
2
  # class 以"B_"开头
3
3
  # function 以"b_"开头
4
4
 
5
- __version__ = '0.0.2.7'
5
+ __version__ = '0.0.2.9'
@@ -1,4 +1,4 @@
1
- from ..Bbasic import B_Color
1
+ from ...Bbasic import B_Color
2
2
 
3
3
 
4
4
  class B_Config:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: byzh_core
3
- Version: 0.0.2.7
3
+ Version: 0.0.2.9
4
4
  Summary: byzh_core是byzh系列的核心库,包含了一些常用的工具函数和类。
5
5
  Author: byzh_rc
6
6
  License: MIT
@@ -1,28 +1,28 @@
1
1
  byzh_core/B_os.py,sha256=-6KjK2NzEeF8GiQno0BmbVDei9DDxOaXdaKGqFeL_eY,2372
2
- byzh_core/__init__.py,sha256=d_c6dl-Qv2eGijPSDNAHZUqubney2tU5yZ3iWTk17FI,110
2
+ byzh_core/__init__.py,sha256=Jpm12RuyaGv73hJYtIWEASKiuGG7tmFNvLa3ZZ5D9Rc,110
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=JelgL3AgcH607Mr-Bvr4u8Svb0twmNmqwXvOl4hHOSs,3161
7
- byzh_core/Bconfig/__init__.py,sha256=7lAp7wNetW0AyJcike7ekdY_8wrQQtFjBsi6684t_lU,54
8
- byzh_core/Bconfig/config.py,sha256=zfURiqwxXrPo4Pei63GaVvTslHnYTgmleCjeaGBR9K8,10952
6
+ byzh_core/Bbasic/text_style.py,sha256=waaj_DKg6eBEyM3kcdpPJtghLPIR171opIjx4rXrUus,3202
9
7
  byzh_core/Bmath/__init__.py,sha256=G3AQug6izkEX3UfzO_mqUNJW88ZKlmYb4Q8CAactK4w,105
10
8
  byzh_core/Bmath/divides.py,sha256=dr85IqGSE9NvugQu7az29GLcjRiLjXU_hZTwtNifIXg,1132
11
9
  byzh_core/Bmath/get_norm.py,sha256=y1QsCTo7qhtGTXIxpc6JtamLWloC7ENRuVdNtK5yi58,596
12
10
  byzh_core/Btable/__init__.py,sha256=NlQBjp_mvObEUm4y6wXbGipkNM2N3uNIUidaJkTwFsw,62
13
11
  byzh_core/Btable/auto_table.py,sha256=nc8RvF86laDnITAzX8sVj3l5tbIGflrsstIbSbGDaAI,14747
14
- byzh_core/Btable/obsolete/__init__.py,sha256=wpfHMPD4awPRDJVYlaiGtkkpjq2srWB7d7LrWhoX5R0,161
15
- byzh_core/Btable/obsolete/auto_table.py,sha256=nC9eHj_IIGVkS2lmN_1gtOyglLCaGlwdoHzPvNNQDEw,13952
16
- byzh_core/Btable/obsolete/row_table.py,sha256=rIX0-Yvb3RnO0RJBkA4m18gux1zYSnEKTy6uQGcWilc,5999
17
- byzh_core/Btable/obsolete/xy_table.py,sha256=-KHK8EUlkJj3Rh0sp_KHI0QFt29AlMASMmR8q8ykUBM,6784
18
12
  byzh_core/Bterminal/__init__.py,sha256=B6p6mHVhi5LAHKlvqfrv20E6XNqUsfU2xD753V6-Zf4,83
19
13
  byzh_core/Bterminal/cmd.py,sha256=iK0fwI0D3peEwUYYZWwnl9X8ImFfrBsEq6ySd3DcRdE,3839
20
14
  byzh_core/Btqdm/__init__.py,sha256=PQRcUn9WXd1YGyFMEKnJU74mdV695_8NHQ56Nsja0DM,53
21
15
  byzh_core/Btqdm/my_tqdm.py,sha256=myyFo3GgyX_wWfSjMWfSTkcnTECf1tqwpXEFpJkzNtw,2878
22
16
  byzh_core/Bwriter/__init__.py,sha256=7db9No0yYOW5ZUtFVKWLRZcu_nz3kvw2W25IoiIiilE,54
23
- byzh_core/Bwriter/writer.py,sha256=px0ZNoSuXS_RbwVnYsBx2lYohyhHACfHM8-HBNEflhU,4006
24
- byzh_core-0.0.2.7.dist-info/LICENSE,sha256=-nRwf0Xga4AX5bsWBXXflpDpgX_U23X06oAMcdf0dSY,1089
25
- byzh_core-0.0.2.7.dist-info/METADATA,sha256=v5PcdMGqu_VZFUOqpGQ5OPD-xJNh4XarkoXdYONIyQo,371
26
- byzh_core-0.0.2.7.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
27
- byzh_core-0.0.2.7.dist-info/top_level.txt,sha256=Xv-pzvl6kPdIbi5UehQcUdGhLtb8-4WhS5dRK1LINwM,10
28
- byzh_core-0.0.2.7.dist-info/RECORD,,
17
+ byzh_core/Bwriter/writer.py,sha256=S-tIwBUcU9_qFWP9JdCiFITg_hz76afXrqHWp-0ltIA,3104
18
+ byzh_core/obsolete/__init__.py,sha256=wpfHMPD4awPRDJVYlaiGtkkpjq2srWB7d7LrWhoX5R0,161
19
+ byzh_core/obsolete/auto_table.py,sha256=nC9eHj_IIGVkS2lmN_1gtOyglLCaGlwdoHzPvNNQDEw,13952
20
+ byzh_core/obsolete/row_table.py,sha256=rIX0-Yvb3RnO0RJBkA4m18gux1zYSnEKTy6uQGcWilc,5999
21
+ byzh_core/obsolete/xy_table.py,sha256=-KHK8EUlkJj3Rh0sp_KHI0QFt29AlMASMmR8q8ykUBM,6784
22
+ byzh_core/obsolete/Bconfig/__init__.py,sha256=7lAp7wNetW0AyJcike7ekdY_8wrQQtFjBsi6684t_lU,54
23
+ byzh_core/obsolete/Bconfig/config.py,sha256=TD8CC1P2Zu95Tf8AGK2IHRXjrCCMBA_tdoZsc1Rr0Gk,10953
24
+ byzh_core-0.0.2.9.dist-info/LICENSE,sha256=-nRwf0Xga4AX5bsWBXXflpDpgX_U23X06oAMcdf0dSY,1089
25
+ byzh_core-0.0.2.9.dist-info/METADATA,sha256=ruX8yL0I0IqpfSyrUQJkbMFTO0oFsdnOr4dWcGmmweQ,371
26
+ byzh_core-0.0.2.9.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
27
+ byzh_core-0.0.2.9.dist-info/top_level.txt,sha256=Xv-pzvl6kPdIbi5UehQcUdGhLtb8-4WhS5dRK1LINwM,10
28
+ byzh_core-0.0.2.9.dist-info/RECORD,,
File without changes
File without changes
File without changes
File without changes
File without changes