byzh-core 0.0.2.13__py3-none-any.whl → 0.0.2.15__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 CHANGED
@@ -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')
@@ -1,16 +1,20 @@
1
1
  import os
2
2
  import zipfile
3
+ import time
3
4
  from pathlib import Path
4
5
 
5
6
  from ..Btqdm import B_Tqdm
7
+ from .. import B_os
6
8
 
7
9
  def b_archive_zip(
8
10
  source_path,
9
11
  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,
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,
14
18
  contain_empty_folder:bool=True,
15
19
  ):
16
20
  '''
@@ -20,61 +24,126 @@ def b_archive_zip(
20
24
 
21
25
  :param source_path:
22
26
  :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 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']
27
33
  :param contain_empty_folder: 是否包含空文件夹
28
34
  :return:
29
35
  '''
30
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}已删除")
31
42
  def get_lst(lst):
32
43
  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)
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)
37
50
 
38
-
39
- my_tqdm = B_Tqdm(prefix='Archive')
51
+ my_tqdm = B_Tqdm(prefix='[b_archive_zip]')
40
52
 
41
53
  with zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
42
- # 压缩文件:
54
+ # 如果传入的是文件:
43
55
  if os.path.isfile(source_path):
44
56
  arcname = os.path.basename(source_path)
45
57
  zipf.write(source_path, arcname)
46
58
  my_tqdm.update(1)
47
59
  return
48
60
 
49
- # 压缩文件夹:
61
+ # 如果传入的是文件夹:
50
62
  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)]
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):
58
68
 
59
69
  # 压缩文件:
60
70
  for file in files:
61
71
  file_path = os.path.join(root, file)
62
72
  arcname = os.path.relpath(file_path, source_path) # 相对于source_path的相对路径
63
73
  zipf.write(file_path, arcname)
64
-
65
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)
66
91
 
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)
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)
72
110
  my_tqdm.update(1)
73
111
 
74
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
+
75
139
  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']
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,
80
149
  )
@@ -3,7 +3,7 @@ from pathlib import Path
3
3
  import subprocess
4
4
  import time
5
5
 
6
- from ..Bbasic import B_Color
6
+ from ..Butils import B_Color
7
7
 
8
8
 
9
9
  def args_process(args: tuple) -> list:
@@ -2,7 +2,7 @@ import sys
2
2
  import time
3
3
  import threading
4
4
 
5
- from ..Bbasic import B_Color, B_Appearance, B_Background
5
+ from ..Butils import B_Color, B_Appearance, B_Background
6
6
 
7
7
 
8
8
  class B_Tqdm:
@@ -0,0 +1,7 @@
1
+ from .text_style import B_Color, B_Appearance, B_Background
2
+ from .timer import B_Timer
3
+
4
+ __all__ = [
5
+ 'B_Color', 'B_Appearance', 'B_Background',
6
+ 'B_Timer'
7
+ ]
@@ -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)
@@ -3,7 +3,7 @@ from typing import Literal
3
3
  import time
4
4
  import os
5
5
 
6
- from ..Bbasic import B_Color
6
+ from ..Butils import B_Color
7
7
 
8
8
  def color_wrap(string:str, color:B_Color):
9
9
  return color.value + string + B_Color.RESET.value
byzh_core/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
  # class 以"B_"开头
3
3
  # function 以"b_"开头
4
4
 
5
- __version__ = '0.0.2.13'
5
+ __version__ = '0.0.2.15'
byzh_core/__main__.py ADDED
@@ -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}!")
@@ -1,4 +1,4 @@
1
- from ...Bbasic import B_Color
1
+ from ...Butils 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.13
3
+ Version: 0.0.2.15
4
4
  Summary: byzh_core是byzh系列的核心库,包含了一些常用的工具函数和类。
5
5
  Author: byzh_rc
6
6
  License: MIT
@@ -0,0 +1,28 @@
1
+ byzh_core/B_os.py,sha256=dMQvaeyp5biW8GfLCc6ivfpPshkHJaR3vxc-ef3nuZU,4022
2
+ byzh_core/__init__.py,sha256=63yKymaZaQiHS18yNbasNXZT9eraqiuINSxUV7tbIKQ,111
3
+ byzh_core/__main__.py,sha256=0CXIQY5vma1qV2ykdCGH_9MXukMBFOkA1Y84bVb0LO0,368
4
+ byzh_core/Barchive/__init__.py,sha256=wUdz646VS0Uhq9lwMkd3YQHCvQhLDqgADoDjFGMqIn0,65
5
+ byzh_core/Barchive/archive.py,sha256=LGCHt92wP3hg26dpbPt9IbLByXKgcRGwB_IVCOhSFC8,6351
6
+ byzh_core/Btable/__init__.py,sha256=NlQBjp_mvObEUm4y6wXbGipkNM2N3uNIUidaJkTwFsw,62
7
+ byzh_core/Btable/auto_table.py,sha256=nc8RvF86laDnITAzX8sVj3l5tbIGflrsstIbSbGDaAI,14747
8
+ byzh_core/Bterminal/__init__.py,sha256=B6p6mHVhi5LAHKlvqfrv20E6XNqUsfU2xD753V6-Zf4,83
9
+ byzh_core/Bterminal/cmd.py,sha256=0I-d7VPHv9eYJoSrAZOnEK-R-hyjWVY0hRRn3Zoq1fg,3839
10
+ byzh_core/Btqdm/__init__.py,sha256=G8pvJYizvdTUI3Xw-yELXY7BbjTghCXJLdqUuDoRNZA,141
11
+ byzh_core/Btqdm/my_tqdm.py,sha256=61FeXKrkteKpCvXM5qU2hoMROqFkZW-bs5Rz86KMQSo,3202
12
+ byzh_core/Butils/__init__.py,sha256=ZtdKTJ8rcJ9zogD4t5pdmWSF1l-TiDaot_C1bvzHQaE,168
13
+ byzh_core/Butils/text_style.py,sha256=34u2-Rsur63iNQ0m7tHxpFWqnQZWybSxBx7vnhOhqDo,3346
14
+ byzh_core/Butils/timer.py,sha256=QrIQ37LALSfx3wUuILLd953-iLDpq_SyqMqrwN6njBs,435
15
+ byzh_core/Bwriter/__init__.py,sha256=QcHzKs0305Pr78ZvZgcC_4miSYZh8jJQDt5TD0GIeEg,82
16
+ byzh_core/Bwriter/writer.py,sha256=P3TDFKhc_o2LgDumsrgtfhHkAczJ1JO1yYrd2NjdlrY,3167
17
+ byzh_core/obsolete/__init__.py,sha256=wpfHMPD4awPRDJVYlaiGtkkpjq2srWB7d7LrWhoX5R0,161
18
+ byzh_core/obsolete/auto_table.py,sha256=nC9eHj_IIGVkS2lmN_1gtOyglLCaGlwdoHzPvNNQDEw,13952
19
+ byzh_core/obsolete/row_table.py,sha256=rIX0-Yvb3RnO0RJBkA4m18gux1zYSnEKTy6uQGcWilc,5999
20
+ byzh_core/obsolete/xy_table.py,sha256=-KHK8EUlkJj3Rh0sp_KHI0QFt29AlMASMmR8q8ykUBM,6784
21
+ byzh_core/obsolete/Bconfig/__init__.py,sha256=7lAp7wNetW0AyJcike7ekdY_8wrQQtFjBsi6684t_lU,54
22
+ byzh_core/obsolete/Bconfig/config.py,sha256=_gUNHfW46mTRecYsz_DQn0LENEPifcF3IMHFVE1prgg,10953
23
+ byzh_core-0.0.2.15.dist-info/LICENSE,sha256=-nRwf0Xga4AX5bsWBXXflpDpgX_U23X06oAMcdf0dSY,1089
24
+ byzh_core-0.0.2.15.dist-info/METADATA,sha256=wDqDKTawSgTTHhfYtbmc99CtPSbHCgx8ujVzaKVMKPo,372
25
+ byzh_core-0.0.2.15.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
26
+ byzh_core-0.0.2.15.dist-info/entry_points.txt,sha256=n9TtHWWOcdcCVFqF4FTXLj2KKGHpvjifBDRoufTrgN0,49
27
+ byzh_core-0.0.2.15.dist-info/top_level.txt,sha256=Xv-pzvl6kPdIbi5UehQcUdGhLtb8-4WhS5dRK1LINwM,10
28
+ byzh_core-0.0.2.15.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ byzh = byzh_core.__main__:main
@@ -1,3 +0,0 @@
1
- from .text_style import B_Color, B_Appearance, B_Background
2
-
3
- __all__ = ['B_Color', 'B_Appearance', 'B_Background']
@@ -1,25 +0,0 @@
1
- byzh_core/B_os.py,sha256=-6KjK2NzEeF8GiQno0BmbVDei9DDxOaXdaKGqFeL_eY,2372
2
- byzh_core/__init__.py,sha256=3MQSx_FHA9m2ns8iWJvgFa0fodxgXK2zeOmKii0WeIU,111
3
- byzh_core/Barchive/__init__.py,sha256=wUdz646VS0Uhq9lwMkd3YQHCvQhLDqgADoDjFGMqIn0,65
4
- byzh_core/Barchive/archive.py,sha256=sG9m1Hr-d2zxYVmzTVRNXX2U2T5baMYECZVqjt0k8pU,3157
5
- byzh_core/Bbasic/__init__.py,sha256=wr7Y7YJINhgpV5X6BT5DaGJKcHUOZYNerCGXoi2Egac,116
6
- byzh_core/Bbasic/text_style.py,sha256=34u2-Rsur63iNQ0m7tHxpFWqnQZWybSxBx7vnhOhqDo,3346
7
- byzh_core/Btable/__init__.py,sha256=NlQBjp_mvObEUm4y6wXbGipkNM2N3uNIUidaJkTwFsw,62
8
- byzh_core/Btable/auto_table.py,sha256=nc8RvF86laDnITAzX8sVj3l5tbIGflrsstIbSbGDaAI,14747
9
- byzh_core/Bterminal/__init__.py,sha256=B6p6mHVhi5LAHKlvqfrv20E6XNqUsfU2xD753V6-Zf4,83
10
- byzh_core/Bterminal/cmd.py,sha256=iK0fwI0D3peEwUYYZWwnl9X8ImFfrBsEq6ySd3DcRdE,3839
11
- byzh_core/Btqdm/__init__.py,sha256=G8pvJYizvdTUI3Xw-yELXY7BbjTghCXJLdqUuDoRNZA,141
12
- byzh_core/Btqdm/my_tqdm.py,sha256=OIlT01P6g-rDyDt6wlX9lORAUux9x-LA6EZRGQyJaXU,3202
13
- byzh_core/Bwriter/__init__.py,sha256=QcHzKs0305Pr78ZvZgcC_4miSYZh8jJQDt5TD0GIeEg,82
14
- byzh_core/Bwriter/writer.py,sha256=kSfIyGdx-XGoV1TBUY6f7NoFL_40fTx9ISTT8Fic0yE,3167
15
- byzh_core/obsolete/__init__.py,sha256=wpfHMPD4awPRDJVYlaiGtkkpjq2srWB7d7LrWhoX5R0,161
16
- byzh_core/obsolete/auto_table.py,sha256=nC9eHj_IIGVkS2lmN_1gtOyglLCaGlwdoHzPvNNQDEw,13952
17
- byzh_core/obsolete/row_table.py,sha256=rIX0-Yvb3RnO0RJBkA4m18gux1zYSnEKTy6uQGcWilc,5999
18
- byzh_core/obsolete/xy_table.py,sha256=-KHK8EUlkJj3Rh0sp_KHI0QFt29AlMASMmR8q8ykUBM,6784
19
- byzh_core/obsolete/Bconfig/__init__.py,sha256=7lAp7wNetW0AyJcike7ekdY_8wrQQtFjBsi6684t_lU,54
20
- byzh_core/obsolete/Bconfig/config.py,sha256=TD8CC1P2Zu95Tf8AGK2IHRXjrCCMBA_tdoZsc1Rr0Gk,10953
21
- byzh_core-0.0.2.13.dist-info/LICENSE,sha256=-nRwf0Xga4AX5bsWBXXflpDpgX_U23X06oAMcdf0dSY,1089
22
- byzh_core-0.0.2.13.dist-info/METADATA,sha256=3zXlKKCBBEzdMdoI6-WVmgqsnZ7UqAaB5lzqjjy1ZqM,372
23
- byzh_core-0.0.2.13.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
24
- byzh_core-0.0.2.13.dist-info/top_level.txt,sha256=Xv-pzvl6kPdIbi5UehQcUdGhLtb8-4WhS5dRK1LINwM,10
25
- byzh_core-0.0.2.13.dist-info/RECORD,,
File without changes