byzh-core 0.0.2.13__tar.gz → 0.0.2.15__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.
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/PKG-INFO +1 -1
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/B_os.py +55 -0
- byzh_core-0.0.2.15/byzh_core/Barchive/archive.py +149 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/Bterminal/cmd.py +1 -1
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/Btqdm/my_tqdm.py +1 -1
- byzh_core-0.0.2.15/byzh_core/Butils/__init__.py +7 -0
- byzh_core-0.0.2.15/byzh_core/Butils/timer.py +17 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/Bwriter/writer.py +1 -1
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/__init__.py +1 -1
- byzh_core-0.0.2.15/byzh_core/__main__.py +10 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/obsolete/Bconfig/config.py +1 -1
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core.egg-info/PKG-INFO +1 -1
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core.egg-info/SOURCES.txt +5 -2
- byzh_core-0.0.2.15/byzh_core.egg-info/entry_points.txt +2 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/setup.py +5 -0
- byzh_core-0.0.2.13/byzh_core/Barchive/archive.py +0 -80
- byzh_core-0.0.2.13/byzh_core/Bbasic/__init__.py +0 -3
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/LICENSE +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/README.md +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/Barchive/__init__.py +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/Btable/__init__.py +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/Btable/auto_table.py +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/Bterminal/__init__.py +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/Btqdm/__init__.py +0 -0
- {byzh_core-0.0.2.13/byzh_core/Bbasic → byzh_core-0.0.2.15/byzh_core/Butils}/text_style.py +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/Bwriter/__init__.py +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/obsolete/Bconfig/__init__.py +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/obsolete/__init__.py +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/obsolete/auto_table.py +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/obsolete/row_table.py +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core/obsolete/xy_table.py +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core.egg-info/dependency_links.txt +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core.egg-info/requires.txt +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/byzh_core.egg-info/top_level.txt +0 -0
- {byzh_core-0.0.2.13 → byzh_core-0.0.2.15}/setup.cfg +0 -0
@@ -52,6 +52,14 @@ def makedirs(path):
|
|
52
52
|
if is_file(path):
|
53
53
|
os.makedirs(path.parent, exist_ok=True)
|
54
54
|
|
55
|
+
def makefile(path):
|
56
|
+
path = Path(path)
|
57
|
+
|
58
|
+
parent_dir = path.parent
|
59
|
+
makedirs(parent_dir)
|
60
|
+
|
61
|
+
path.touch() # 创建文件
|
62
|
+
|
55
63
|
def rm(path):
|
56
64
|
if os.path.isdir(path):
|
57
65
|
shutil.rmtree(path)
|
@@ -86,6 +94,53 @@ def get_filepaths_in_dir(root_dir_path, exclude_name=[], exclude_suffix=['.pyc']
|
|
86
94
|
file_paths.append(file_path)
|
87
95
|
return file_paths
|
88
96
|
|
97
|
+
def walk(
|
98
|
+
root: str,
|
99
|
+
black_dirnames: list[str] = None,
|
100
|
+
black_filenames: list[str] = None,
|
101
|
+
black_stems: list[str] = None,
|
102
|
+
black_exts: list[str] = None,
|
103
|
+
):
|
104
|
+
"""
|
105
|
+
遍历目录, 类似os.walk, 但可以指定黑名单
|
106
|
+
:param root:
|
107
|
+
:param black_dirnames:
|
108
|
+
:param black_stems: 文件名
|
109
|
+
:param black_stems: 文件名, 不包括后缀
|
110
|
+
:param black_exts: 文件名的后缀(含.)
|
111
|
+
:return: root, dirs, files
|
112
|
+
"""
|
113
|
+
|
114
|
+
def get_lst(lst):
|
115
|
+
return [] if lst is None else lst
|
116
|
+
black_dirnames = get_lst(black_dirnames)
|
117
|
+
black_filenames = get_lst(black_filenames)
|
118
|
+
black_stems = get_lst(black_stems)
|
119
|
+
black_exts = get_lst(black_exts)
|
120
|
+
|
121
|
+
dirs = []
|
122
|
+
files = []
|
123
|
+
for entry in os.listdir(root):
|
124
|
+
path = os.path.join(root, entry)
|
125
|
+
# 是文件夹
|
126
|
+
if os.path.isdir(path):
|
127
|
+
dirs.append(entry)
|
128
|
+
# 是文件
|
129
|
+
elif os.path.isfile(path):
|
130
|
+
files.append(entry)
|
131
|
+
else:
|
132
|
+
continue
|
133
|
+
dirs = [d for d in dirs if d not in black_dirnames]
|
134
|
+
files = [f for f in files if f not in black_filenames]
|
135
|
+
files = [f for f in files if os.path.splitext(f)[0] not in black_stems]
|
136
|
+
files = [f for f in files if os.path.splitext(f)[1] not in black_exts]
|
137
|
+
|
138
|
+
yield root, dirs, files
|
139
|
+
|
140
|
+
for dirname in dirs:
|
141
|
+
new_path = os.path.join(root, dirname)
|
142
|
+
yield from walk(new_path, black_dirnames, black_filenames, black_stems, black_exts)
|
143
|
+
|
89
144
|
if __name__ == '__main__':
|
90
145
|
# print(get_dirpaths_in_dir(r'E:\byzh_workingplace\byzh-rc-to-pypi'))
|
91
146
|
a = get_filepaths_in_dir(r'E:\byzh_workingplace\byzh-rc-to-pypi')
|
@@ -0,0 +1,149 @@
|
|
1
|
+
import os
|
2
|
+
import zipfile
|
3
|
+
import time
|
4
|
+
from pathlib import Path
|
5
|
+
|
6
|
+
from ..Btqdm import B_Tqdm
|
7
|
+
from .. import B_os
|
8
|
+
|
9
|
+
def b_archive_zip(
|
10
|
+
source_path,
|
11
|
+
output_path:str|Path=None,
|
12
|
+
black_dirnames:list[str]=None,
|
13
|
+
black_filenames:list[str]=None,
|
14
|
+
black_stems:list[str]=None,
|
15
|
+
black_exts:list[str]=None,
|
16
|
+
white_filepath:list[str]=None,
|
17
|
+
white_dirpath:list[str]=None,
|
18
|
+
contain_empty_folder:bool=True,
|
19
|
+
):
|
20
|
+
'''
|
21
|
+
压缩文件夹,排除 指定文件夹and指定后缀文件
|
22
|
+
|
23
|
+
name代表前缀, ext代表后缀(包括.)
|
24
|
+
|
25
|
+
:param source_path:
|
26
|
+
:param output_path: 如果不传入, 则默认为source_path同名同路径的zip文件
|
27
|
+
:param black_dirnames: 黑名单-文件夹名 >>> ['__pycache__', '.git', '.idea']
|
28
|
+
:param black_filenames: 黑名单-文件全名 >>> ['.gitignore', 'README.md']
|
29
|
+
:param black_stems: 黑名单-文件名(不含后缀) >>> ['README']
|
30
|
+
:param black_exts: 黑名单-文件后缀(包括.) >>> ['.csv', '.npy', '.pt', '.pth']
|
31
|
+
:param white_filepath: 白名单-文件全名 >>> ['.gitignore', 'README.md']
|
32
|
+
:param white_dirpath: 白名单-文件夹路径 >>> ['E:\byzh_workingplace\byzh-rc-to-pypi\big_work\文件夹1']
|
33
|
+
:param contain_empty_folder: 是否包含空文件夹
|
34
|
+
:return:
|
35
|
+
'''
|
36
|
+
output_path = source_path + '.zip' if output_path is None else output_path
|
37
|
+
if os.path.exists(output_path):
|
38
|
+
print(f"检测到{output_path}已存在, 将在3秒后删除...")
|
39
|
+
time.sleep(3)
|
40
|
+
B_os.rm(output_path)
|
41
|
+
print(f"{output_path}已删除")
|
42
|
+
def get_lst(lst):
|
43
|
+
return [] if lst is None else lst
|
44
|
+
black_dirnames = get_lst(black_dirnames)
|
45
|
+
black_filenames = get_lst(black_filenames)
|
46
|
+
black_stems = get_lst(black_stems)
|
47
|
+
black_exts = get_lst(black_exts)
|
48
|
+
white_filepath = get_lst(white_filepath)
|
49
|
+
white_dirpath = get_lst(white_dirpath)
|
50
|
+
|
51
|
+
my_tqdm = B_Tqdm(prefix='[b_archive_zip]')
|
52
|
+
|
53
|
+
with zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
54
|
+
# 如果传入的是文件:
|
55
|
+
if os.path.isfile(source_path):
|
56
|
+
arcname = os.path.basename(source_path)
|
57
|
+
zipf.write(source_path, arcname)
|
58
|
+
my_tqdm.update(1)
|
59
|
+
return
|
60
|
+
|
61
|
+
# 如果传入的是文件夹:
|
62
|
+
if os.path.isdir(source_path):
|
63
|
+
for root, dirs, files in B_os.walk(source_path,
|
64
|
+
black_dirnames=black_dirnames,
|
65
|
+
black_filenames=black_filenames,
|
66
|
+
black_stems=black_stems,
|
67
|
+
black_exts=black_exts):
|
68
|
+
|
69
|
+
# 压缩文件:
|
70
|
+
for file in files:
|
71
|
+
file_path = os.path.join(root, file)
|
72
|
+
arcname = os.path.relpath(file_path, source_path) # 相对于source_path的相对路径
|
73
|
+
zipf.write(file_path, arcname)
|
74
|
+
my_tqdm.update(1)
|
75
|
+
# 压缩文件夹:
|
76
|
+
for i, dir in enumerate(dirs):
|
77
|
+
if len(os.listdir(os.path.join(root, dir))) == 0:
|
78
|
+
if not contain_empty_folder:
|
79
|
+
dirs.pop(i)
|
80
|
+
continue
|
81
|
+
dir_path = os.path.join(root, dir)
|
82
|
+
arcname = os.path.relpath(dir_path, source_path) # 相对于source_path的相对路径
|
83
|
+
zipf.write(dir_path, arcname)
|
84
|
+
my_tqdm.update(1)
|
85
|
+
|
86
|
+
# 白名单-文件:
|
87
|
+
for filepath in white_filepath:
|
88
|
+
arcname = os.path.relpath(filepath, source_path)
|
89
|
+
zipf.write(filepath, arcname)
|
90
|
+
my_tqdm.update(1)
|
91
|
+
|
92
|
+
# 白名单-文件夹:
|
93
|
+
for dirpath in white_dirpath:
|
94
|
+
for root, dirs, files in B_os.walk(dirpath):
|
95
|
+
# 压缩文件:
|
96
|
+
for file in files:
|
97
|
+
file_path = os.path.join(root, file)
|
98
|
+
arcname = os.path.relpath(file_path, source_path) # 相对于source_path的相对路径
|
99
|
+
zipf.write(file_path, arcname)
|
100
|
+
my_tqdm.update(1)
|
101
|
+
# 压缩文件夹:
|
102
|
+
for i, dir in enumerate(dirs):
|
103
|
+
if len(os.listdir(os.path.join(root, dir))) == 0:
|
104
|
+
if not contain_empty_folder:
|
105
|
+
dirs.pop(i)
|
106
|
+
continue
|
107
|
+
dir_path = os.path.join(root, dir)
|
108
|
+
arcname = os.path.relpath(dir_path, source_path) # 相对于source_path的相对路径
|
109
|
+
zipf.write(dir_path, arcname)
|
110
|
+
my_tqdm.update(1)
|
111
|
+
|
112
|
+
if __name__ == '__main__':
|
113
|
+
# 不包含空文件夹:`文件夹111`
|
114
|
+
B_os.makedirs('根文件夹/文件夹1/文件夹11/文件夹111')
|
115
|
+
contain_empty_folder = False
|
116
|
+
|
117
|
+
# 不包含`文件夹12`
|
118
|
+
B_os.makefile('根文件夹/文件夹1/文件夹12/file1.txt')
|
119
|
+
B_os.makefile('根文件夹/文件夹1/文件夹12/文件夹123/file2.txt')
|
120
|
+
B_os.makefile('根文件夹/文件夹1/文件夹12/文件夹1234/文件夹12345/file3.txt')
|
121
|
+
black_dirnames = ['文件夹12']
|
122
|
+
|
123
|
+
# 不包含`file4.txt`, 且因此`文件夹21`变为空文件夹, 因此不包含
|
124
|
+
B_os.makefile('根文件夹/文件夹2/文件夹21/file4.txt')
|
125
|
+
black_filenames = ['file4.txt']
|
126
|
+
|
127
|
+
# 不包含`awa.txt`, `awa.html`
|
128
|
+
B_os.makefile('根文件夹/文件夹3/awa.txt')
|
129
|
+
B_os.makefile('根文件夹/文件夹3/文件夹31/awa.html')
|
130
|
+
black_stems = ['awa']
|
131
|
+
|
132
|
+
# 不包含`file5.csv`
|
133
|
+
B_os.makefile('根文件夹/文件夹4/file5.csv')
|
134
|
+
black_exts = ['.csv']
|
135
|
+
|
136
|
+
white_filepath = ['根文件夹/文件夹1/文件夹12/文件夹1234/文件夹12345/file3.txt']
|
137
|
+
white_dirpath = ['根文件夹/文件夹1/文件夹12/文件夹123']
|
138
|
+
|
139
|
+
b_archive_zip(
|
140
|
+
source_path=r'根文件夹',
|
141
|
+
output_path=r'awaqwq.zip',
|
142
|
+
black_dirnames=black_dirnames,
|
143
|
+
black_filenames=black_filenames,
|
144
|
+
black_stems=black_stems,
|
145
|
+
black_exts=black_exts,
|
146
|
+
white_filepath=white_filepath,
|
147
|
+
white_dirpath=white_dirpath,
|
148
|
+
contain_empty_folder=contain_empty_folder,
|
149
|
+
)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import time
|
2
|
+
class B_Timer:
|
3
|
+
def __init__(self):
|
4
|
+
self.start_time = 0
|
5
|
+
self.end_time = 0
|
6
|
+
|
7
|
+
def __enter__(self):
|
8
|
+
self.start_time = time.time()
|
9
|
+
return self
|
10
|
+
|
11
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
12
|
+
self.end_time = time.time()
|
13
|
+
print(f"[Timer] cost: {self.end_time - self.start_time:.4f}s")
|
14
|
+
|
15
|
+
if __name__ == '__main__':
|
16
|
+
with B_Timer():
|
17
|
+
time.sleep(2)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import argparse
|
2
|
+
|
3
|
+
def main():
|
4
|
+
parser = argparse.ArgumentParser(description="打个招呼的命令行工具")
|
5
|
+
parser.add_argument("name", help="你的名字")
|
6
|
+
parser.add_argument("-t", "--times", type=int, default=1, help="打招呼的次数")
|
7
|
+
args = parser.parse_args()
|
8
|
+
|
9
|
+
for _ in range(args.times):
|
10
|
+
print(f"你好,{args.name}!")
|
@@ -3,21 +3,24 @@ README.md
|
|
3
3
|
setup.py
|
4
4
|
byzh_core/B_os.py
|
5
5
|
byzh_core/__init__.py
|
6
|
+
byzh_core/__main__.py
|
6
7
|
byzh_core.egg-info/PKG-INFO
|
7
8
|
byzh_core.egg-info/SOURCES.txt
|
8
9
|
byzh_core.egg-info/dependency_links.txt
|
10
|
+
byzh_core.egg-info/entry_points.txt
|
9
11
|
byzh_core.egg-info/requires.txt
|
10
12
|
byzh_core.egg-info/top_level.txt
|
11
13
|
byzh_core/Barchive/__init__.py
|
12
14
|
byzh_core/Barchive/archive.py
|
13
|
-
byzh_core/Bbasic/__init__.py
|
14
|
-
byzh_core/Bbasic/text_style.py
|
15
15
|
byzh_core/Btable/__init__.py
|
16
16
|
byzh_core/Btable/auto_table.py
|
17
17
|
byzh_core/Bterminal/__init__.py
|
18
18
|
byzh_core/Bterminal/cmd.py
|
19
19
|
byzh_core/Btqdm/__init__.py
|
20
20
|
byzh_core/Btqdm/my_tqdm.py
|
21
|
+
byzh_core/Butils/__init__.py
|
22
|
+
byzh_core/Butils/text_style.py
|
23
|
+
byzh_core/Butils/timer.py
|
21
24
|
byzh_core/Bwriter/__init__.py
|
22
25
|
byzh_core/Bwriter/writer.py
|
23
26
|
byzh_core/obsolete/__init__.py
|
@@ -1,80 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
import zipfile
|
3
|
-
from pathlib import Path
|
4
|
-
|
5
|
-
from ..Btqdm import B_Tqdm
|
6
|
-
|
7
|
-
def b_archive_zip(
|
8
|
-
source_path,
|
9
|
-
output_path:str|Path=None,
|
10
|
-
exclude_dirs:list[str]=None,
|
11
|
-
exclude_files:list[str]=None,
|
12
|
-
exclude_exts:list[str]=None,
|
13
|
-
while_list:list[str]=None,
|
14
|
-
contain_empty_folder:bool=True,
|
15
|
-
):
|
16
|
-
'''
|
17
|
-
压缩文件夹,排除 指定文件夹and指定后缀文件
|
18
|
-
|
19
|
-
name代表前缀, ext代表后缀(包括.)
|
20
|
-
|
21
|
-
:param source_path:
|
22
|
-
:param output_path: 如果不传入, 则默认为source_path同名同路径的zip文件
|
23
|
-
:param exclude_dirs: 黑名单-文件夹名 >>> ['__pycache__', '.git', '.idea']
|
24
|
-
:param exclude_files: 黑名单-文件全名 >>> ['.gitignore', 'README.md']
|
25
|
-
:param exclude_exts: 黑名单-文件后缀(包括.) >>> ['.csv', '.npy', '.pt', '.pth']
|
26
|
-
:param while_list: 白名单-文件全名 >>> ['.gitignore', 'README.md']
|
27
|
-
:param contain_empty_folder: 是否包含空文件夹
|
28
|
-
:return:
|
29
|
-
'''
|
30
|
-
output_path = source_path + '.zip' if output_path is None else output_path
|
31
|
-
def get_lst(lst):
|
32
|
-
return [] if lst is None else lst
|
33
|
-
exclude_dirs = get_lst(exclude_dirs)
|
34
|
-
exclude_files = get_lst(exclude_files)
|
35
|
-
exclude_exts = get_lst(exclude_exts)
|
36
|
-
while_list = get_lst(while_list)
|
37
|
-
|
38
|
-
|
39
|
-
my_tqdm = B_Tqdm(prefix='Archive')
|
40
|
-
|
41
|
-
with zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
42
|
-
# 压缩文件:
|
43
|
-
if os.path.isfile(source_path):
|
44
|
-
arcname = os.path.basename(source_path)
|
45
|
-
zipf.write(source_path, arcname)
|
46
|
-
my_tqdm.update(1)
|
47
|
-
return
|
48
|
-
|
49
|
-
# 压缩文件夹:
|
50
|
-
if os.path.isdir(source_path):
|
51
|
-
for root, dirs, files in os.walk(source_path):
|
52
|
-
# 排除指定文件夹dirs
|
53
|
-
dirs[:] = [d for d in dirs if d in while_list or d not in exclude_dirs]
|
54
|
-
# 排除指定文件files
|
55
|
-
files = [f for f in files if f in while_list or f not in exclude_files]
|
56
|
-
# 排除指定后缀文件files
|
57
|
-
files = [f for f in files if f in while_list or not any(f.endswith(ext) for ext in exclude_exts)]
|
58
|
-
|
59
|
-
# 压缩文件:
|
60
|
-
for file in files:
|
61
|
-
file_path = os.path.join(root, file)
|
62
|
-
arcname = os.path.relpath(file_path, source_path) # 相对于source_path的相对路径
|
63
|
-
zipf.write(file_path, arcname)
|
64
|
-
|
65
|
-
my_tqdm.update(1)
|
66
|
-
|
67
|
-
# 若是空文件夹,则压缩文件夹:
|
68
|
-
if contain_empty_folder and (len(dirs) == 0 and len(files) == 0):
|
69
|
-
arcname = os.path.relpath(root, source_path)
|
70
|
-
folder_path = root
|
71
|
-
zipf.write(folder_path, arcname)
|
72
|
-
my_tqdm.update(1)
|
73
|
-
|
74
|
-
if __name__ == '__main__':
|
75
|
-
b_archive_zip(
|
76
|
-
source_path=r'E:\byzh_workingplace\byzh-rc-to-pypi\mnist',
|
77
|
-
output_path=r'E:\byzh_workingplace\byzh-rc-to-pypi\awaqwq.zip',
|
78
|
-
exclude_dirs=['__pycache__', 'com'],
|
79
|
-
exclude_exts=['.ppt']
|
80
|
-
)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|