upplib 3.1.7__py3-none-any.whl → 3.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.
upplib/__init__.py CHANGED
@@ -8,6 +8,7 @@ from upplib.util import *
8
8
 
9
9
  # 有关文件操作类的包
10
10
  from upplib.file import *
11
+ from upplib.file_text import *
11
12
 
12
13
  # 有关 图表的 html 代码的包
13
14
  from upplib.chart_html import *
upplib/file.py CHANGED
@@ -3,30 +3,30 @@ from upplib.index import *
3
3
 
4
4
 
5
5
  def get_file(file_path: str = None,
6
- path_prefix: str = None,
7
- prefix: str = None,
6
+ path_startswith: str = None,
7
+ startswith: str = None,
8
8
  path_contain: str = None,
9
9
  contain: str = None,
10
- sort_asc: bool | None = None,
11
- path_suffix: str = None,
12
- suffix: str = None) -> list[str]:
10
+ sort_asc: bool | None = True,
11
+ path_endswith: str = None,
12
+ endswith: str = None) -> list[str]:
13
13
  """
14
14
  有关文件的操作
15
15
  查询指定文件夹下面的所有的文件信息, 也可以是指定的文件
16
- file_path : 文件路径
17
- path_prefix : 文件路径,以 prefix 开头
18
- prefix : 文件名称,以 prefix 开头
19
- path_contain : 文件路径,含有
20
- contain : 文件名称,含有
21
- sort_asc : 是否按升序排序,也就是从小到大排序
22
- path_suffix : 文件路径,以 suffix 结尾
23
- suffix : 文件名称,以 suffix 结尾
16
+ file_path : 文件路径
17
+ path_startswith : 文件路径,以 path_startswith 开头
18
+ startswith : 文件名称,以 startswith 开头
19
+ path_contain : 文件路径,含有
20
+ contain : 文件名称,含有
21
+ sort_asc : 是否按升序排序,也就是从小到大排序
22
+ path_endswith : 文件路径,以 path_endswith 结尾
23
+ endswith : 文件名称,以 endswith 结尾
24
24
  return list
25
25
  """
26
26
  if file_path is None:
27
27
  file_path = os.path.dirname(os.path.abspath('.'))
28
28
  list_data = []
29
- get_file_all(file_path, list_data, path_prefix, prefix, path_contain, contain, path_suffix, suffix)
29
+ get_file_all(file_path, list_data, path_startswith, startswith, path_contain, contain, path_endswith, endswith)
30
30
  # 去一下重复的数据
31
31
  r_list = list(set(list_data))
32
32
  if sort_asc is not None:
@@ -49,10 +49,31 @@ def get_file_folder(file_name_one: str = None) -> str:
49
49
  return all_file_path
50
50
 
51
51
 
52
+ def remove_folder_file(file_path: str = None,
53
+ path_startswith: str = None,
54
+ startswith: str = None,
55
+ path_contain: str = None,
56
+ contain: str = None,
57
+ path_endswith: str = None,
58
+ endswith: str = None):
59
+ """
60
+ 删除指定文件夹下面的指定的文件
61
+ """
62
+ file_part_all_list = get_file(file_path=file_path,
63
+ path_startswith=path_startswith,
64
+ startswith=startswith,
65
+ path_contain=path_contain,
66
+ contain=contain,
67
+ path_endswith=path_endswith,
68
+ endswith=endswith)
69
+ for file_part_all_one in file_part_all_list:
70
+ os.remove(file_part_all_one)
71
+
72
+
52
73
  def get_folder(file_path: str = None,
53
- prefix: str = None,
74
+ startswith: str = None,
54
75
  contain: str = None,
55
- suffix: str = None) -> list[str]:
76
+ endswith: str = None) -> list[str]:
56
77
  """
57
78
  有关文件的操作, 只查询文件夹
58
79
  查询指定文件夹下面的所有的文件信息, 也可以是指定的文件
@@ -62,17 +83,17 @@ def get_folder(file_path: str = None,
62
83
  if file_path is None:
63
84
  file_path = os.path.dirname(os.path.abspath('.'))
64
85
  list_data = []
65
- get_folder_all(file_path, list_data, prefix, contain, suffix)
86
+ get_folder_all(file_path, list_data, startswith, contain, endswith)
66
87
  # 去一下重复的数据
67
88
  return list(set(list_data))
68
89
 
69
90
 
70
91
  # 是否包含指定的文件
71
92
  def contain_file(file_path: str = None,
72
- prefix: str = None,
93
+ startswith: str = None,
73
94
  contain: str = None,
74
- suffix: str = None) -> bool:
75
- return len(get_file(file_path, prefix, contain, suffix)) > 0
95
+ endswith: str = None) -> bool:
96
+ return len(get_file(file_path, startswith, contain, endswith)) > 0
76
97
 
77
98
 
78
99
  def get_file_data_line(file_path: str = None,
@@ -104,78 +125,77 @@ def get_file_data_line(file_path: str = None,
104
125
  # 查询指定文件夹下面的所有的文件信息, 也可以是指定的文件
105
126
  def get_file_all(file_path: str = None,
106
127
  list_data: list = None,
107
- path_prefix: str = None,
108
- prefix: str = None,
128
+ path_startswith: str = None,
129
+ startswith: str = None,
109
130
  path_contain: str = None,
110
131
  contain: str = None,
111
- path_suffix: str = None,
112
- suffix: str = None) -> None:
132
+ path_endswith: str = None,
133
+ endswith: str = None) -> None:
113
134
  if os.path.isdir(file_path):
114
135
  for root, dir_names, file_names in os.walk(file_path):
115
136
  for file_name in file_names:
116
- if (get_file_check(os.path.join(root, file_name), path_prefix, path_contain, path_suffix)
117
- and get_file_check(file_name, prefix, contain, suffix)):
137
+ if (get_file_check(os.path.join(root, file_name), path_startswith, path_contain, path_endswith)
138
+ and get_file_check(file_name, startswith, contain, endswith)):
118
139
  list_data.append(os.path.join(root, file_name))
119
140
  for dir_name in dir_names:
120
- get_file_all(os.path.join(root, dir_name), list_data, path_prefix, prefix, path_contain, contain, path_suffix, suffix)
121
- elif (get_file_check(file_path, prefix, contain, suffix)
122
- and get_file_check(file_path, path_prefix, path_contain, path_suffix)):
141
+ get_file_all(os.path.join(root, dir_name), list_data, path_startswith, startswith, path_contain, contain, path_endswith, endswith)
142
+ elif (get_file_check(file_path, startswith, contain, endswith)
143
+ and get_file_check(file_path, path_startswith, path_contain, path_endswith)):
123
144
  list_data.append(file_path)
124
145
 
125
146
 
126
147
  # 查询指定文件夹下面的所有的文件信息, 也可以是指定的文件
127
148
  def get_folder_all(file_path: str = None,
128
149
  list_data: list = None,
129
- prefix: str = None,
150
+ startswith: str = None,
130
151
  contain: str = None,
131
- suffix: str = None) -> None:
152
+ endswith: str = None) -> None:
132
153
  if os.path.isdir(file_path):
133
154
  for root, dir_names, file_names in os.walk(file_path):
134
155
  for dir_name in dir_names:
135
156
  dir_name_path = os.path.join(root, dir_name)
136
- if get_file_check(dir_name_path, prefix, contain, suffix):
157
+ if get_file_check(dir_name_path, startswith, contain, endswith):
137
158
  list_data.append(dir_name_path)
138
159
  else:
139
- get_folder_all(dir_name_path, list_data, prefix, contain, suffix)
160
+ get_folder_all(dir_name_path, list_data, startswith, contain, endswith)
140
161
 
141
162
 
142
- def get_file_check(
143
- name: str = None,
144
- prefix: str = None,
145
- contain: str = None,
146
- suffix: str = None) -> bool:
163
+ def get_file_check(name: str = None,
164
+ startswith: str = None,
165
+ contain: str = None,
166
+ endswith: str = None) -> bool:
147
167
  """
148
168
  检查文件是否符合要求
149
- prefix : 前缀
150
- contain : 包含这个字符
151
- suffix : 后缀
169
+ startswith : 以这个开头
170
+ contain : 包含这个字符
171
+ endswith : 以这个结尾
152
172
  """
153
173
  if name is None or name == '':
154
174
  return False
155
175
  p = True
156
176
  c = True
157
177
  s = True
158
- if prefix is not None:
159
- p = name.startswith(prefix)
178
+ if startswith is not None:
179
+ p = name.startswith(startswith)
160
180
  if contain is not None:
161
181
  c = name.find(contain) > -1
162
- if suffix is not None:
163
- s = name.endswith(suffix)
182
+ if endswith is not None:
183
+ s = name.endswith(endswith)
164
184
  return p and c and s
165
185
 
166
186
 
167
187
  def find_file_by_content(file_path: str = '',
168
188
  contain_txt: str = None,
169
- prefix: str = None,
189
+ startswith: str = None,
170
190
  contain: str = None,
171
- suffix: str = None) -> bool | None:
191
+ endswith: str = None) -> bool | None:
172
192
  """
173
193
  检查文件内容是否包含指定的字符串
174
194
  慎用,否则, 执行时间可能比较长
175
195
  """
176
- list_file = get_file(file_path, prefix, contain, suffix)
196
+ list_file = get_file(file_path, startswith, contain, endswith)
177
197
  if len(list_file) == 0:
178
- to_log(f'no_matched_file : {file_path} , {contain_txt} , {prefix} , {contain} , {suffix}')
198
+ to_log(f'no_matched_file : {file_path} , {contain_txt} , {startswith} , {contain} , {endswith}')
179
199
  return False
180
200
  if contain_txt is None:
181
201
  to_log(list_file)