byzh-core 0.0.2__py3-none-any.whl → 0.0.2.2__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/B_os.py +59 -0
- byzh_core/Bos/B_os.py +35 -0
- byzh_core/Bos/__init__.py +1 -3
- byzh_core/Bos/make.py +12 -0
- byzh_core/Btqdm/__init__.py +1 -1
- byzh_core/Btqdm/my_tqdm.py +80 -0
- byzh_core/__init__.py +1 -1
- {byzh_core-0.0.2.dist-info → byzh_core-0.0.2.2.dist-info}/METADATA +1 -1
- {byzh_core-0.0.2.dist-info → byzh_core-0.0.2.2.dist-info}/RECORD +12 -11
- byzh_core/Bos/path.py +0 -17
- byzh_core/Btqdm/b_tqdm.py +0 -76
- {byzh_core-0.0.2.dist-info → byzh_core-0.0.2.2.dist-info}/LICENSE +0 -0
- {byzh_core-0.0.2.dist-info → byzh_core-0.0.2.2.dist-info}/WHEEL +0 -0
- {byzh_core-0.0.2.dist-info → byzh_core-0.0.2.2.dist-info}/top_level.txt +0 -0
byzh_core/B_os.py
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
import shutil
|
2
|
+
import os
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import Literal
|
5
|
+
|
6
|
+
def get_parent_dir(path: Literal['__file__']) -> Path:
|
7
|
+
'''
|
8
|
+
获取 该py文件 所在的文件夹
|
9
|
+
:param path: __file__
|
10
|
+
'''
|
11
|
+
parent_dir = Path(path).parent
|
12
|
+
return parent_dir
|
13
|
+
|
14
|
+
def get_cwd() -> Path:
|
15
|
+
'''
|
16
|
+
获取 当前工作目录current working directory
|
17
|
+
'''
|
18
|
+
return Path.cwd()
|
19
|
+
|
20
|
+
|
21
|
+
def makedirs(path):
|
22
|
+
def is_dir(path):
|
23
|
+
path = Path(path)
|
24
|
+
|
25
|
+
# 存在
|
26
|
+
if os.path.isdir(path):
|
27
|
+
return True
|
28
|
+
|
29
|
+
# 不存在
|
30
|
+
name = path.name
|
31
|
+
if '.' in name:
|
32
|
+
return False
|
33
|
+
return True
|
34
|
+
|
35
|
+
def is_file(path):
|
36
|
+
path = Path(path)
|
37
|
+
|
38
|
+
# 存在
|
39
|
+
if os.path.isfile(path):
|
40
|
+
return True
|
41
|
+
|
42
|
+
# 不存在
|
43
|
+
name = path.name
|
44
|
+
if '.' in name:
|
45
|
+
return True
|
46
|
+
return False
|
47
|
+
|
48
|
+
path = Path(path)
|
49
|
+
|
50
|
+
if is_dir(path):
|
51
|
+
os.makedirs(path, exist_ok=True)
|
52
|
+
if is_file(path):
|
53
|
+
os.makedirs(path.parent, exist_ok=True)
|
54
|
+
|
55
|
+
def rm(path):
|
56
|
+
if os.path.isdir(path):
|
57
|
+
shutil.rmtree(path)
|
58
|
+
if os.path.isfile(path):
|
59
|
+
os.remove(path)
|
byzh_core/Bos/B_os.py
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
import shutil
|
2
|
+
import os
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import Literal
|
5
|
+
|
6
|
+
def get_parent_dir(path: Literal['__file__']) -> Path:
|
7
|
+
'''
|
8
|
+
获取 该py文件 所在的文件夹
|
9
|
+
:param path: __file__
|
10
|
+
'''
|
11
|
+
parent_dir = Path(path).parent
|
12
|
+
return parent_dir
|
13
|
+
|
14
|
+
def get_cwd() -> Path:
|
15
|
+
'''
|
16
|
+
获取 当前工作目录current working directory
|
17
|
+
'''
|
18
|
+
return Path.cwd()
|
19
|
+
|
20
|
+
|
21
|
+
def makedirs(path):
|
22
|
+
from .make import is_dir, is_file
|
23
|
+
|
24
|
+
path = Path(path)
|
25
|
+
|
26
|
+
if is_dir(path):
|
27
|
+
os.makedirs(path, exist_ok=True)
|
28
|
+
if is_file(path):
|
29
|
+
os.makedirs(path.parent, exist_ok=True)
|
30
|
+
|
31
|
+
def rm(path):
|
32
|
+
if os.path.isdir(path):
|
33
|
+
shutil.rmtree(path)
|
34
|
+
if os.path.isfile(path):
|
35
|
+
os.remove(path)
|
byzh_core/Bos/__init__.py
CHANGED
byzh_core/Bos/make.py
CHANGED
@@ -4,6 +4,12 @@ import shutil
|
|
4
4
|
|
5
5
|
def is_dir(path):
|
6
6
|
path = Path(path)
|
7
|
+
|
8
|
+
# 存在
|
9
|
+
if os.path.isdir(path):
|
10
|
+
return True
|
11
|
+
|
12
|
+
# 不存在
|
7
13
|
name = path.name
|
8
14
|
if '.' in name:
|
9
15
|
return False
|
@@ -11,6 +17,12 @@ def is_dir(path):
|
|
11
17
|
|
12
18
|
def is_file(path):
|
13
19
|
path = Path(path)
|
20
|
+
|
21
|
+
# 存在
|
22
|
+
if os.path.isfile(path):
|
23
|
+
return True
|
24
|
+
|
25
|
+
# 不存在
|
14
26
|
name = path.name
|
15
27
|
if '.' in name:
|
16
28
|
return True
|
byzh_core/Btqdm/__init__.py
CHANGED
@@ -0,0 +1,80 @@
|
|
1
|
+
import sys
|
2
|
+
import time
|
3
|
+
import threading
|
4
|
+
|
5
|
+
from ..Bbasic import B_Color
|
6
|
+
|
7
|
+
|
8
|
+
class B_Tqdm:
|
9
|
+
def __init__(
|
10
|
+
self,
|
11
|
+
total: int|None = None,
|
12
|
+
prefix: str = 'Processing',
|
13
|
+
suffix: str = '',
|
14
|
+
length: int = 20,
|
15
|
+
fill: str = '█',
|
16
|
+
):
|
17
|
+
"""
|
18
|
+
类似tqdm的进度条
|
19
|
+
:param total: 总数
|
20
|
+
:param prefix: 前缀
|
21
|
+
:param suffix: 后缀
|
22
|
+
:param length: 进度条长度(字符)
|
23
|
+
:param fill: 填充字符
|
24
|
+
"""
|
25
|
+
super().__init__()
|
26
|
+
self.total = total
|
27
|
+
self.prefix = prefix
|
28
|
+
self.suffix = suffix
|
29
|
+
self.length = length
|
30
|
+
self.fill = fill
|
31
|
+
self.start_time = 0
|
32
|
+
self.current = 0
|
33
|
+
|
34
|
+
self._lock = threading.Lock()
|
35
|
+
|
36
|
+
def _format_time(self, seconds):
|
37
|
+
"""将秒数转换为mm:ss格式"""
|
38
|
+
minutes = int(seconds // 60)
|
39
|
+
seconds = int(seconds % 60)
|
40
|
+
return f'{minutes:02}:{seconds:02}'
|
41
|
+
|
42
|
+
def update(self, step=1, color=B_Color.BLUE, prefix=None, suffix=None):
|
43
|
+
with self._lock:
|
44
|
+
if self.current == 0:
|
45
|
+
self.start_time = time.time()
|
46
|
+
if prefix is not None:
|
47
|
+
self.prefix = prefix
|
48
|
+
if suffix is not None:
|
49
|
+
self.suffix = suffix
|
50
|
+
|
51
|
+
# 更新进度
|
52
|
+
self.current += step
|
53
|
+
|
54
|
+
# 计算已用时间
|
55
|
+
elapsed_time = time.time() - self.start_time
|
56
|
+
elapsed_str = self._format_time(elapsed_time)
|
57
|
+
# 预估剩余时间
|
58
|
+
if self.total is not None:
|
59
|
+
estimated_time = elapsed_time / self.current * (self.total - self.current) if self.current > 0 else 0
|
60
|
+
estimated_str = self._format_time(estimated_time)
|
61
|
+
# 计算每秒处理的项数
|
62
|
+
speed = self.current / elapsed_time if elapsed_time > 0 else 0
|
63
|
+
|
64
|
+
# 更新进度条
|
65
|
+
if self.total is not None:
|
66
|
+
filled_length = int(self.length * self.current // self.total)
|
67
|
+
bar = self.fill * filled_length + '-' * (self.length - filled_length)
|
68
|
+
|
69
|
+
sys.stdout.write(f'\r{color}{self.prefix} |{bar}|'
|
70
|
+
f' {self.current}/{self.total} -> {elapsed_str}<{estimated_str} | {speed:.1f} it/s |'
|
71
|
+
f' {self.suffix}{B_Color.RESET}')
|
72
|
+
else:
|
73
|
+
sys.stdout.write(f'\r{color}{self.prefix} | {self.current} iters -> {elapsed_str} | {speed:.1f} it/s |'
|
74
|
+
f' {self.suffix}{B_Color.RESET}')
|
75
|
+
sys.stdout.flush()
|
76
|
+
|
77
|
+
# 补回车
|
78
|
+
if self.current == self.total:
|
79
|
+
sys.stdout.write('\n')
|
80
|
+
sys.stdout.flush()
|
byzh_core/__init__.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
byzh_core/
|
1
|
+
byzh_core/B_os.py,sha256=xqEYTiOKkFCpJhPXGyA5Qjiz9NX7qpMPCTHuN_Z-M7Y,1226
|
2
|
+
byzh_core/__init__.py,sha256=9kQtKRLFe5bTTI8z2hHUl96YHEP-kb8pfPNT_WoHglk,110
|
2
3
|
byzh_core/Barchive/__init__.py,sha256=wUdz646VS0Uhq9lwMkd3YQHCvQhLDqgADoDjFGMqIn0,65
|
3
4
|
byzh_core/Barchive/archive.py,sha256=yIQgef1APUcZdHM_7Pa9rCam-P3PA3pbcSJSaySoUj4,2498
|
4
5
|
byzh_core/Bbasic/__init__.py,sha256=wr7Y7YJINhgpV5X6BT5DaGJKcHUOZYNerCGXoi2Egac,116
|
@@ -8,9 +9,9 @@ byzh_core/Bconfig/config.py,sha256=P9C4kAkxKnIFaJCErBXdABfOyWgFgVHpR-i-fiZXCNs,1
|
|
8
9
|
byzh_core/Bmath/__init__.py,sha256=G3AQug6izkEX3UfzO_mqUNJW88ZKlmYb4Q8CAactK4w,105
|
9
10
|
byzh_core/Bmath/divides.py,sha256=dr85IqGSE9NvugQu7az29GLcjRiLjXU_hZTwtNifIXg,1132
|
10
11
|
byzh_core/Bmath/get_norm.py,sha256=y1QsCTo7qhtGTXIxpc6JtamLWloC7ENRuVdNtK5yi58,596
|
11
|
-
byzh_core/Bos/
|
12
|
-
byzh_core/Bos/
|
13
|
-
byzh_core/Bos/
|
12
|
+
byzh_core/Bos/B_os.py,sha256=iGzL9if9Jh5z3U_qWRPIZCrHly2ZCz8MJLWiJwYVefA,763
|
13
|
+
byzh_core/Bos/__init__.py,sha256=mMa6OugZs8gIfZMj7go_wEHZRe0JRffgiyIKTF5I_uc,88
|
14
|
+
byzh_core/Bos/make.py,sha256=uGmHc96lXChihJs2jGiXJRp3tU_U5DPCo8jcc-aW6d4,663
|
14
15
|
byzh_core/Bos/remove.py,sha256=HuGQlEOz7IZB_c6T9MzR3miRx60IeaBYP-3lp-P20-I,156
|
15
16
|
byzh_core/Btable/__init__.py,sha256=wpfHMPD4awPRDJVYlaiGtkkpjq2srWB7d7LrWhoX5R0,161
|
16
17
|
byzh_core/Btable/auto_table.py,sha256=JREmn6KIlZKkv1Vsc23Ow3fDiJAgfMppbGKDUY8rfyk,14002
|
@@ -20,13 +21,13 @@ byzh_core/Btable/obsolete/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
|
|
20
21
|
byzh_core/Btable/obsolete/b_auto_table.py,sha256=Cmblv_pknQeMew_KLO8vGdeSRtAykwbMh30QVhgS3UI,10422
|
21
22
|
byzh_core/Bterminal/__init__.py,sha256=B6p6mHVhi5LAHKlvqfrv20E6XNqUsfU2xD753V6-Zf4,83
|
22
23
|
byzh_core/Bterminal/cmd.py,sha256=iK0fwI0D3peEwUYYZWwnl9X8ImFfrBsEq6ySd3DcRdE,3839
|
23
|
-
byzh_core/Btqdm/__init__.py,sha256=
|
24
|
-
byzh_core/Btqdm/
|
24
|
+
byzh_core/Btqdm/__init__.py,sha256=PQRcUn9WXd1YGyFMEKnJU74mdV695_8NHQ56Nsja0DM,53
|
25
|
+
byzh_core/Btqdm/my_tqdm.py,sha256=3Xrw6qOEidLqKGE2UD3i37_cMzrSWy4QpNpO2_4I88M,2833
|
25
26
|
byzh_core/Bwriter/__init__.py,sha256=KSsbCJZ-1j5wOr-ZbTg8K3A8Du73d22DQVLdmq-3CBo,116
|
26
27
|
byzh_core/Bwriter/globalwriter.py,sha256=tSjWxzLylAeZep67n5jbRsjQkXkBKRZLvKXUyGSY92Q,1824
|
27
28
|
byzh_core/Bwriter/writer.py,sha256=px0ZNoSuXS_RbwVnYsBx2lYohyhHACfHM8-HBNEflhU,4006
|
28
|
-
byzh_core-0.0.2.dist-info/LICENSE,sha256=-nRwf0Xga4AX5bsWBXXflpDpgX_U23X06oAMcdf0dSY,1089
|
29
|
-
byzh_core-0.0.2.dist-info/METADATA,sha256=
|
30
|
-
byzh_core-0.0.2.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
31
|
-
byzh_core-0.0.2.dist-info/top_level.txt,sha256=Xv-pzvl6kPdIbi5UehQcUdGhLtb8-4WhS5dRK1LINwM,10
|
32
|
-
byzh_core-0.0.2.dist-info/RECORD,,
|
29
|
+
byzh_core-0.0.2.2.dist-info/LICENSE,sha256=-nRwf0Xga4AX5bsWBXXflpDpgX_U23X06oAMcdf0dSY,1089
|
30
|
+
byzh_core-0.0.2.2.dist-info/METADATA,sha256=foV-fXyBRcoTlI5x3EVzS5OFMtMmjLeocQZkE0uA23Y,371
|
31
|
+
byzh_core-0.0.2.2.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
32
|
+
byzh_core-0.0.2.2.dist-info/top_level.txt,sha256=Xv-pzvl6kPdIbi5UehQcUdGhLtb8-4WhS5dRK1LINwM,10
|
33
|
+
byzh_core-0.0.2.2.dist-info/RECORD,,
|
byzh_core/Bos/path.py
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
from pathlib import Path
|
3
|
-
from typing import Literal
|
4
|
-
|
5
|
-
def b_get_parent_dir(path: Literal['__file__']) -> Path:
|
6
|
-
'''
|
7
|
-
获取 该py文件 所在的文件夹
|
8
|
-
:param path: __file__
|
9
|
-
'''
|
10
|
-
parent_dir = Path(path).parent
|
11
|
-
return parent_dir
|
12
|
-
|
13
|
-
def b_get_cwd() -> Path:
|
14
|
-
'''
|
15
|
-
获取 当前工作目录current working directory
|
16
|
-
'''
|
17
|
-
return Path.cwd()
|
byzh_core/Btqdm/b_tqdm.py
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
import sys
|
2
|
-
import time
|
3
|
-
|
4
|
-
from ..Bbasic import B_Color
|
5
|
-
|
6
|
-
|
7
|
-
class B_Tqdm:
|
8
|
-
def __init__(
|
9
|
-
self,
|
10
|
-
total: int|None = None,
|
11
|
-
prefix: str = 'Processing',
|
12
|
-
suffix: str = '',
|
13
|
-
length: int = 20,
|
14
|
-
fill: str = '█',
|
15
|
-
):
|
16
|
-
"""
|
17
|
-
类似tqdm的进度条
|
18
|
-
:param total: 总数
|
19
|
-
:param prefix: 前缀
|
20
|
-
:param suffix: 后缀
|
21
|
-
:param length: 进度条长度(字符)
|
22
|
-
:param fill: 填充字符
|
23
|
-
"""
|
24
|
-
super().__init__()
|
25
|
-
self.total = total
|
26
|
-
self.prefix = prefix
|
27
|
-
self.suffix = suffix
|
28
|
-
self.length = length
|
29
|
-
self.fill = fill
|
30
|
-
self.start_time = 0
|
31
|
-
self.current = 0
|
32
|
-
|
33
|
-
def _format_time(self, seconds):
|
34
|
-
"""将秒数转换为mm:ss格式"""
|
35
|
-
minutes = int(seconds // 60)
|
36
|
-
seconds = int(seconds % 60)
|
37
|
-
return f'{minutes:02}:{seconds:02}'
|
38
|
-
|
39
|
-
def update(self, step=1, color=B_Color.BLUE, prefix=None, suffix=None):
|
40
|
-
if self.current == 0:
|
41
|
-
self.start_time = time.time()
|
42
|
-
if prefix is not None:
|
43
|
-
self.prefix = prefix
|
44
|
-
if suffix is not None:
|
45
|
-
self.suffix = suffix
|
46
|
-
|
47
|
-
# 更新进度
|
48
|
-
self.current += step
|
49
|
-
|
50
|
-
# 计算已用时间
|
51
|
-
elapsed_time = time.time() - self.start_time
|
52
|
-
elapsed_str = self._format_time(elapsed_time)
|
53
|
-
# 预估剩余时间
|
54
|
-
if self.total is not None:
|
55
|
-
estimated_time = elapsed_time / self.current * (self.total - self.current) if self.current > 0 else 0
|
56
|
-
estimated_str = self._format_time(estimated_time)
|
57
|
-
# 计算每秒处理的项数
|
58
|
-
speed = self.current / elapsed_time if elapsed_time > 0 else 0
|
59
|
-
|
60
|
-
# 更新进度条
|
61
|
-
if self.total is not None:
|
62
|
-
filled_length = int(self.length * self.current // self.total)
|
63
|
-
bar = self.fill * filled_length + '-' * (self.length - filled_length)
|
64
|
-
|
65
|
-
sys.stdout.write(f'\r{color}{self.prefix} |{bar}|'
|
66
|
-
f' {self.current}/{self.total} -> {elapsed_str}<{estimated_str} | {speed:.1f} it/s |'
|
67
|
-
f' {self.suffix}{B_Color.RESET}')
|
68
|
-
else:
|
69
|
-
sys.stdout.write(f'\r{color}{self.prefix} | {self.current} iters -> {elapsed_str} | {speed:.1f} it/s |'
|
70
|
-
f' {self.suffix}{B_Color.RESET}')
|
71
|
-
sys.stdout.flush()
|
72
|
-
|
73
|
-
# 补回车
|
74
|
-
if self.current == self.total:
|
75
|
-
sys.stdout.write('\n')
|
76
|
-
sys.stdout.flush()
|
File without changes
|
File without changes
|
File without changes
|