byzh-core 0.0.2.8__tar.gz → 0.0.2.9__tar.gz

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.
Files changed (34) hide show
  1. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/PKG-INFO +1 -1
  2. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/Bbasic/text_style.py +4 -3
  3. byzh_core-0.0.2.9/byzh_core/Bwriter/writer.py +107 -0
  4. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/__init__.py +1 -1
  5. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core.egg-info/PKG-INFO +1 -1
  6. byzh_core-0.0.2.8/byzh_core/Bwriter/writer.py +0 -138
  7. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/LICENSE +0 -0
  8. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/README.md +0 -0
  9. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/B_os.py +0 -0
  10. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/Barchive/__init__.py +0 -0
  11. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/Barchive/archive.py +0 -0
  12. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/Bbasic/__init__.py +0 -0
  13. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/Bmath/__init__.py +0 -0
  14. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/Bmath/divides.py +0 -0
  15. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/Bmath/get_norm.py +0 -0
  16. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/Btable/__init__.py +0 -0
  17. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/Btable/auto_table.py +0 -0
  18. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/Bterminal/__init__.py +0 -0
  19. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/Bterminal/cmd.py +0 -0
  20. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/Btqdm/__init__.py +0 -0
  21. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/Btqdm/my_tqdm.py +0 -0
  22. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/Bwriter/__init__.py +0 -0
  23. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/obsolete/Bconfig/__init__.py +0 -0
  24. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/obsolete/Bconfig/config.py +0 -0
  25. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/obsolete/__init__.py +0 -0
  26. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/obsolete/auto_table.py +0 -0
  27. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/obsolete/row_table.py +0 -0
  28. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core/obsolete/xy_table.py +0 -0
  29. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core.egg-info/SOURCES.txt +0 -0
  30. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core.egg-info/dependency_links.txt +0 -0
  31. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core.egg-info/requires.txt +0 -0
  32. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/byzh_core.egg-info/top_level.txt +0 -0
  33. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/setup.cfg +0 -0
  34. {byzh_core-0.0.2.8 → byzh_core-0.0.2.9}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: byzh_core
3
- Version: 0.0.2.8
3
+ Version: 0.0.2.9
4
4
  Summary: byzh_core是byzh系列的核心库,包含了一些常用的工具函数和类。
5
5
  Author: byzh_rc
6
6
  License: MIT
@@ -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" # 高亮
@@ -0,0 +1,107 @@
1
+ from pathlib import Path
2
+ from typing import Literal
3
+ import time
4
+ import os
5
+
6
+ from ..Bbasic import B_Color
7
+
8
+ class B_Writer:
9
+ def __init__(
10
+ self,
11
+ path:Path,
12
+ mode:Literal["w", "a"] = "w",
13
+ time_file:bool = False,
14
+ color:B_Color = B_Color.RESET,
15
+ ):
16
+ '''
17
+ :param path: 日志保存路径
18
+ :param time_file: 是否输出时间
19
+ '''
20
+ super().__init__()
21
+ self.path = Path(path)
22
+ self.mode = mode
23
+ self.time_file = time_file
24
+
25
+ self.color = color.value
26
+
27
+ self.f = None
28
+ self.setFile(self.path, self.mode, self.time_file)
29
+
30
+ def setFile(self, file: Path, mode: Literal["w", "a"] = "w", ifTime=False):
31
+ '''
32
+ 设置 file的path 以及 writer的ifTime
33
+ :param file: 设置log路径
34
+ :param ifTime:
35
+ :return:
36
+ '''
37
+ if self.f is not None:
38
+ self.f.close()
39
+ self.path = Path(file)
40
+ self.time_file = ifTime
41
+ self.__createDir(self.path)
42
+ self.f = open(self.path, mode, encoding="utf-8")
43
+
44
+ def clearFile(self):
45
+ '''
46
+ 清空内容
47
+ '''
48
+ assert self.f is not None, "请先调用setFile方法"
49
+ self.f.close()
50
+ self.f = open(self.path, 'w', encoding="utf-8")
51
+
52
+ def closeFile(self):
53
+ '''
54
+ 关闭log
55
+ '''
56
+ if self.f:
57
+ self.f.close()
58
+ self.f = None
59
+
60
+ def toCmd(self, string:str, ifTime:bool=False, color:B_Color = None):
61
+ '''
62
+ 打印到terminal
63
+ '''
64
+ t = ''
65
+ if ifTime:
66
+ t = time.strftime("%Y-%m-%d %H:%M:%S ##### ", time.localtime())
67
+
68
+ if color is None:
69
+ print(self.color + t + str(string) + B_Color.RESET.value)
70
+ else:
71
+ print(color.value + t + str(string) + B_Color.RESET.value)
72
+
73
+ def toFile(self, string:str, ifTime:bool=None):
74
+ '''
75
+ 写入到文件内
76
+ '''
77
+ assert self.f is not None, "请先调用setFile方法"
78
+
79
+ t = ''
80
+ if ifTime == False: # 为了使False时不管self.time_file
81
+ pass
82
+ elif ifTime==True or self.time_file==True:
83
+ t = time.strftime("%Y-%m-%d %H:%M:%S ##### ", time.localtime())
84
+
85
+ self.f.write(str(string+t))
86
+ self.f.write("\n")
87
+ self.f.flush()
88
+
89
+ def toBoth(self, string:str, file_time:bool=None, cmd_time:bool=False, color:B_Color = None):
90
+ '''
91
+ 同时写入到文件和terminal
92
+ :param string:
93
+ :param color:
94
+ :return:
95
+ '''
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)
100
+
101
+ def __createDir(self, path):
102
+ # 获取到该文件的文件夹
103
+ dir = path.parents[0]
104
+ os.makedirs(dir, exist_ok=True)
105
+
106
+ def __exit__(self):
107
+ self.closeFile()
@@ -2,4 +2,4 @@
2
2
  # class 以"B_"开头
3
3
  # function 以"b_"开头
4
4
 
5
- __version__ = '0.0.2.8'
5
+ __version__ = '0.0.2.9'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: byzh_core
3
- Version: 0.0.2.8
3
+ Version: 0.0.2.9
4
4
  Summary: byzh_core是byzh系列的核心库,包含了一些常用的工具函数和类。
5
5
  Author: byzh_rc
6
6
  License: MIT
@@ -1,138 +0,0 @@
1
- from pathlib import Path
2
- from typing import Literal
3
- import time
4
- import os
5
-
6
- from ..Bbasic import B_Color
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
- class B_Writer:
23
- def __init__(
24
- self,
25
- path: Path,
26
- ifTime: bool = False,
27
- color: Color_Literal = 'default',
28
- ):
29
- '''
30
- :param path: 日志保存路径
31
- :param ifTime: 是否输出时间
32
- '''
33
- super().__init__()
34
- self.path = Path(path)
35
- self.ifTime = ifTime
36
- self.toWant_file = False
37
- self.toWant_cmd = False
38
-
39
- self.__checkColor(color)
40
- self.color = color
41
-
42
- self.f = None
43
- self.setFile(self.path, self.ifTime)
44
-
45
- def setFile(self, file: Path, ifTime=False):
46
- '''
47
- 设置 file的path 以及 writer的ifTime
48
- :param file: 设置log路径
49
- :param ifTime:
50
- :return:
51
- '''
52
- if self.f is not None:
53
- self.f.close()
54
- self.path = Path(file)
55
- self.ifTime = ifTime
56
- self.__createDir(self.path)
57
- self.f = open(self.path, "a", encoding="utf-8")
58
-
59
- def clearFile(self):
60
- '''
61
- 清空内容
62
- '''
63
- assert self.f is not None, "请先调用setFile方法"
64
- self.f.close()
65
- self.f = open(self.path, 'w', encoding="utf-8")
66
-
67
- def closeFile(self):
68
- '''
69
- 关闭log
70
- '''
71
- if self.f:
72
- self.f.close()
73
- self.f = None
74
-
75
- def toCmd(self, string, color: Color_Literal = None):
76
- '''
77
- 打印到terminal
78
- '''
79
- # 检查color是否在字典中
80
- if color is None:
81
- print(COLOR_DICT.get(self.color) + str(string) + B_Color.RESET)
82
- else:
83
- assert color in COLOR_DICT, f"color参数错误,请输入{COLOR_DICT.keys()}"
84
- print(COLOR_DICT.get(color) + str(string) + B_Color.RESET)
85
-
86
- def toFile(self, string, ifTime:bool=None):
87
- '''
88
- 写入到文件内
89
- '''
90
- assert self.f is not None, "请先调用setFile方法"
91
-
92
- if ifTime == False:
93
- pass
94
- elif ifTime==True or self.ifTime==True:
95
- t = time.strftime("%Y-%m-%d %H:%M:%S ##### ", time.localtime())
96
- self.f.write(t)
97
-
98
- self.f.write(str(string))
99
- self.f.write("\n")
100
- self.f.flush()
101
-
102
- def toBoth(self, string, ifTime:bool=None, color: Color_Literal = None):
103
- '''
104
- 同时写入到文件和terminal
105
- :param string:
106
- :param color:
107
- :return:
108
- '''
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: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())}"
134
-
135
- def __createDir(self, path):
136
- # 获取到该文件的文件夹
137
- dir = path.parents[0]
138
- os.makedirs(dir, exist_ok=True)
File without changes
File without changes
File without changes
File without changes