upplib 3.2.1__py3-none-any.whl → 3.2.3__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/file.py +56 -56
- {upplib-3.2.1.dist-info → upplib-3.2.3.dist-info}/METADATA +1 -1
- {upplib-3.2.1.dist-info → upplib-3.2.3.dist-info}/RECORD +6 -6
- {upplib-3.2.1.dist-info → upplib-3.2.3.dist-info}/WHEEL +0 -0
- {upplib-3.2.1.dist-info → upplib-3.2.3.dist-info}/licenses/LICENSE +0 -0
- {upplib-3.2.1.dist-info → upplib-3.2.3.dist-info}/top_level.txt +0 -0
upplib/file.py
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
from upplib import *
|
|
2
2
|
from upplib.index import *
|
|
3
|
+
from upplib.index import is_win
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
def get_file(file_path: str = None,
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
path_startswith: str = None,
|
|
8
|
+
startswith: str = None,
|
|
8
9
|
path_contain: str = None,
|
|
9
10
|
contain: str = None,
|
|
10
11
|
sort_asc: bool | None = True,
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
path_endswith: str = None,
|
|
13
|
+
endswith: str = None) -> list[str]:
|
|
13
14
|
"""
|
|
14
15
|
有关文件的操作
|
|
15
16
|
查询指定文件夹下面的所有的文件信息, 也可以是指定的文件
|
|
16
|
-
file_path
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
path_contain
|
|
20
|
-
contain
|
|
21
|
-
sort_asc
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
file_path : 文件路径
|
|
18
|
+
path_startswith : 文件路径,以 path_startswith 开头
|
|
19
|
+
startswith : 文件名称,以 startswith 开头
|
|
20
|
+
path_contain : 文件路径,含有
|
|
21
|
+
contain : 文件名称,含有
|
|
22
|
+
sort_asc : 是否按升序排序,也就是从小到大排序
|
|
23
|
+
path_endswith : 文件路径,以 path_endswith 结尾
|
|
24
|
+
endswith : 文件名称,以 endswith 结尾
|
|
24
25
|
return list
|
|
25
26
|
"""
|
|
26
27
|
if file_path is None:
|
|
27
28
|
file_path = os.path.dirname(os.path.abspath('.'))
|
|
28
29
|
list_data = []
|
|
29
|
-
get_file_all(file_path, list_data,
|
|
30
|
+
get_file_all(file_path, list_data, path_startswith, startswith, path_contain, contain, path_endswith, endswith)
|
|
30
31
|
# 去一下重复的数据
|
|
31
32
|
r_list = list(set(list_data))
|
|
32
33
|
if sort_asc is not None:
|
|
@@ -50,30 +51,30 @@ def get_file_folder(file_name_one: str = None) -> str:
|
|
|
50
51
|
|
|
51
52
|
|
|
52
53
|
def remove_folder_file(file_path: str = None,
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
path_startswith: str = None,
|
|
55
|
+
startswith: str = None,
|
|
55
56
|
path_contain: str = None,
|
|
56
57
|
contain: str = None,
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
path_endswith: str = None,
|
|
59
|
+
endswith: str = None):
|
|
59
60
|
"""
|
|
60
61
|
删除指定文件夹下面的指定的文件
|
|
61
62
|
"""
|
|
62
63
|
file_part_all_list = get_file(file_path=file_path,
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
path_startswith=path_startswith,
|
|
65
|
+
startswith=startswith,
|
|
65
66
|
path_contain=path_contain,
|
|
66
67
|
contain=contain,
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
path_endswith=path_endswith,
|
|
69
|
+
endswith=endswith)
|
|
69
70
|
for file_part_all_one in file_part_all_list:
|
|
70
71
|
os.remove(file_part_all_one)
|
|
71
72
|
|
|
72
73
|
|
|
73
74
|
def get_folder(file_path: str = None,
|
|
74
|
-
|
|
75
|
+
startswith: str = None,
|
|
75
76
|
contain: str = None,
|
|
76
|
-
|
|
77
|
+
endswith: str = None) -> list[str]:
|
|
77
78
|
"""
|
|
78
79
|
有关文件的操作, 只查询文件夹
|
|
79
80
|
查询指定文件夹下面的所有的文件信息, 也可以是指定的文件
|
|
@@ -83,17 +84,17 @@ def get_folder(file_path: str = None,
|
|
|
83
84
|
if file_path is None:
|
|
84
85
|
file_path = os.path.dirname(os.path.abspath('.'))
|
|
85
86
|
list_data = []
|
|
86
|
-
get_folder_all(file_path, list_data,
|
|
87
|
+
get_folder_all(file_path, list_data, startswith, contain, endswith)
|
|
87
88
|
# 去一下重复的数据
|
|
88
89
|
return list(set(list_data))
|
|
89
90
|
|
|
90
91
|
|
|
91
92
|
# 是否包含指定的文件
|
|
92
93
|
def contain_file(file_path: str = None,
|
|
93
|
-
|
|
94
|
+
startswith: str = None,
|
|
94
95
|
contain: str = None,
|
|
95
|
-
|
|
96
|
-
return len(get_file(file_path,
|
|
96
|
+
endswith: str = None) -> bool:
|
|
97
|
+
return len(get_file(file_path, startswith, contain, endswith)) > 0
|
|
97
98
|
|
|
98
99
|
|
|
99
100
|
def get_file_data_line(file_path: str = None,
|
|
@@ -125,78 +126,77 @@ def get_file_data_line(file_path: str = None,
|
|
|
125
126
|
# 查询指定文件夹下面的所有的文件信息, 也可以是指定的文件
|
|
126
127
|
def get_file_all(file_path: str = None,
|
|
127
128
|
list_data: list = None,
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
path_startswith: str = None,
|
|
130
|
+
startswith: str = None,
|
|
130
131
|
path_contain: str = None,
|
|
131
132
|
contain: str = None,
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
path_endswith: str = None,
|
|
134
|
+
endswith: str = None) -> None:
|
|
134
135
|
if os.path.isdir(file_path):
|
|
135
136
|
for root, dir_names, file_names in os.walk(file_path):
|
|
136
137
|
for file_name in file_names:
|
|
137
|
-
if (get_file_check(os.path.join(root, file_name),
|
|
138
|
-
and get_file_check(file_name,
|
|
138
|
+
if (get_file_check(os.path.join(root, file_name), path_startswith, path_contain, path_endswith)
|
|
139
|
+
and get_file_check(file_name, startswith, contain, endswith)):
|
|
139
140
|
list_data.append(os.path.join(root, file_name))
|
|
140
141
|
for dir_name in dir_names:
|
|
141
|
-
get_file_all(os.path.join(root, dir_name), list_data,
|
|
142
|
-
elif (get_file_check(file_path,
|
|
143
|
-
and get_file_check(file_path,
|
|
142
|
+
get_file_all(os.path.join(root, dir_name), list_data, path_startswith, startswith, path_contain, contain, path_endswith, endswith)
|
|
143
|
+
elif (get_file_check(file_path, startswith, contain, endswith)
|
|
144
|
+
and get_file_check(file_path, path_startswith, path_contain, path_endswith)):
|
|
144
145
|
list_data.append(file_path)
|
|
145
146
|
|
|
146
147
|
|
|
147
148
|
# 查询指定文件夹下面的所有的文件信息, 也可以是指定的文件
|
|
148
149
|
def get_folder_all(file_path: str = None,
|
|
149
150
|
list_data: list = None,
|
|
150
|
-
|
|
151
|
+
startswith: str = None,
|
|
151
152
|
contain: str = None,
|
|
152
|
-
|
|
153
|
+
endswith: str = None) -> None:
|
|
153
154
|
if os.path.isdir(file_path):
|
|
154
155
|
for root, dir_names, file_names in os.walk(file_path):
|
|
155
156
|
for dir_name in dir_names:
|
|
156
157
|
dir_name_path = os.path.join(root, dir_name)
|
|
157
|
-
if get_file_check(dir_name_path,
|
|
158
|
+
if get_file_check(dir_name_path, startswith, contain, endswith):
|
|
158
159
|
list_data.append(dir_name_path)
|
|
159
160
|
else:
|
|
160
|
-
get_folder_all(dir_name_path, list_data,
|
|
161
|
+
get_folder_all(dir_name_path, list_data, startswith, contain, endswith)
|
|
161
162
|
|
|
162
163
|
|
|
163
|
-
def get_file_check(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
suffix: str = None) -> bool:
|
|
164
|
+
def get_file_check(name: str = None,
|
|
165
|
+
startswith: str = None,
|
|
166
|
+
contain: str = None,
|
|
167
|
+
endswith: str = None) -> bool:
|
|
168
168
|
"""
|
|
169
169
|
检查文件是否符合要求
|
|
170
|
-
|
|
171
|
-
contain
|
|
172
|
-
|
|
170
|
+
startswith : 以这个开头
|
|
171
|
+
contain : 包含这个字符
|
|
172
|
+
endswith : 以这个结尾
|
|
173
173
|
"""
|
|
174
174
|
if name is None or name == '':
|
|
175
175
|
return False
|
|
176
176
|
p = True
|
|
177
177
|
c = True
|
|
178
178
|
s = True
|
|
179
|
-
if
|
|
180
|
-
p = name.startswith(
|
|
179
|
+
if startswith is not None:
|
|
180
|
+
p = name.startswith(startswith)
|
|
181
181
|
if contain is not None:
|
|
182
182
|
c = name.find(contain) > -1
|
|
183
|
-
if
|
|
184
|
-
s = name.endswith(
|
|
183
|
+
if endswith is not None:
|
|
184
|
+
s = name.endswith(endswith)
|
|
185
185
|
return p and c and s
|
|
186
186
|
|
|
187
187
|
|
|
188
188
|
def find_file_by_content(file_path: str = '',
|
|
189
189
|
contain_txt: str = None,
|
|
190
|
-
|
|
190
|
+
startswith: str = None,
|
|
191
191
|
contain: str = None,
|
|
192
|
-
|
|
192
|
+
endswith: str = None) -> bool | None:
|
|
193
193
|
"""
|
|
194
194
|
检查文件内容是否包含指定的字符串
|
|
195
195
|
慎用,否则, 执行时间可能比较长
|
|
196
196
|
"""
|
|
197
|
-
list_file = get_file(file_path,
|
|
197
|
+
list_file = get_file(file_path, startswith, contain, endswith)
|
|
198
198
|
if len(list_file) == 0:
|
|
199
|
-
to_log(f'no_matched_file : {file_path} , {contain_txt} , {
|
|
199
|
+
to_log(f'no_matched_file : {file_path} , {contain_txt} , {startswith} , {contain} , {endswith}')
|
|
200
200
|
return False
|
|
201
201
|
if contain_txt is None:
|
|
202
202
|
to_log(list_file)
|
|
@@ -4,7 +4,7 @@ upplib/chart_html.py,sha256=39CTD2LbN7LNN3wtb3n-ojN2r_X7RJMWappPgiLSJG4,23144
|
|
|
4
4
|
upplib/clean_up_msg.py,sha256=yR4D2fIXOT8z9VpClfhBjVnjhexObgNZDhvPu5v_5Y4,19237
|
|
5
5
|
upplib/common_package.py,sha256=2-u66k4WbZnX6-PUaYy8wsblnz41nvtX4Hwo3J5hjO0,832
|
|
6
6
|
upplib/db.py,sha256=-3ZALQSzP92-zIhye6ckrXIctbHsVmwoLiCVOlTyDyo,7058
|
|
7
|
-
upplib/file.py,sha256
|
|
7
|
+
upplib/file.py,sha256=-IZ8NJq7iaOG0TZbTjpgZcDFNNR-wC0-78Nyt02PReM,8675
|
|
8
8
|
upplib/file_text.py,sha256=JYoRSatwPMVOqXpJ2wszfJ2pVx1Ot2rQ2Jnxm_vj_YY,43106
|
|
9
9
|
upplib/format_data.py,sha256=Qxq-OZ8v6HBRJ-tUcNFem1Imbauk3Y5qJTrAGT0CC4I,10153
|
|
10
10
|
upplib/http_util.py,sha256=8Xya5qpeCKGaglxKnirOlOnbnBU3K52FGV5Y9c8HH9k,16119
|
|
@@ -16,8 +16,8 @@ upplib/multi_thread.py,sha256=zOeWG5HGYIzwqiPvef-4ak5bzorf0S3q6Ht8wPit_M0,2705
|
|
|
16
16
|
upplib/query_log.py,sha256=m93f8wyZeatVs_PF8O5eyC6U5yJfohg7x6muXPUMOJA,9204
|
|
17
17
|
upplib/redis_tool.py,sha256=I1kOqBwfQWVIOAY-hQaaOn1Zrx8BNlK83u-pk4uHPCA,707
|
|
18
18
|
upplib/util.py,sha256=0JXo9eIEC67Cnby-s8IELkbP9m7a6deB4pX7OIGb3zg,4709
|
|
19
|
-
upplib-3.2.
|
|
20
|
-
upplib-3.2.
|
|
21
|
-
upplib-3.2.
|
|
22
|
-
upplib-3.2.
|
|
23
|
-
upplib-3.2.
|
|
19
|
+
upplib-3.2.3.dist-info/licenses/LICENSE,sha256=WI5JtXXhjcqnIcPllDA1ZtuxNnZ515xjElcILo7z28o,1073
|
|
20
|
+
upplib-3.2.3.dist-info/METADATA,sha256=3-BcSuY4ftZ41Qrkswuut-ru43zku2jXAM-8r79iU9Y,940
|
|
21
|
+
upplib-3.2.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
22
|
+
upplib-3.2.3.dist-info/top_level.txt,sha256=VwdHDDPP79e1LqtRu5_w30hHB4gT0zlj1weuQYOqFoA,7
|
|
23
|
+
upplib-3.2.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|