gomyck-tools 1.2.12__py3-none-any.whl → 1.3.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.
- ctools/czip.py +121 -10
- ctools/thread_pool.py +1 -1
- gomyck_tools-1.3.2.dist-info/METADATA +66 -0
- {gomyck_tools-1.2.12.dist-info → gomyck_tools-1.3.2.dist-info}/RECORD +6 -6
- {gomyck_tools-1.2.12.dist-info → gomyck_tools-1.3.2.dist-info}/WHEEL +1 -1
- gomyck_tools-1.2.12.dist-info/METADATA +0 -57
- {gomyck_tools-1.2.12.dist-info → gomyck_tools-1.3.2.dist-info}/top_level.txt +0 -0
ctools/czip.py
CHANGED
@@ -4,16 +4,127 @@ __author__ = 'haoyang'
|
|
4
4
|
__date__ = '2025/1/24 08:48'
|
5
5
|
|
6
6
|
import io
|
7
|
+
import os
|
7
8
|
import time
|
8
|
-
|
9
9
|
import pyzipper
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
"""
|
12
|
+
target_directory = '/Users/haoyang/Desktop/知识库文件'
|
13
|
+
zip_password = None
|
14
|
+
process_directory_to_single_zip(target_directory, zip_password, "knowledge_base")
|
15
|
+
|
16
|
+
files_to_compress = [
|
17
|
+
'/path/to/file1.txt',
|
18
|
+
'/path/to/file2.pdf',
|
19
|
+
'/path/to/file3.jpg'
|
20
|
+
]
|
21
|
+
output_directory = '/Users/haoyang/Desktop'
|
22
|
+
compress_specific_files(files_to_compress, output_directory, zip_password, "my_files")
|
23
|
+
"""
|
24
|
+
def create_zip_with_files(file_dict, password=None) -> io.BytesIO:
|
25
|
+
"""Compress multiple files into a single password-protected ZIP archive in memory.
|
26
|
+
Args:
|
27
|
+
file_dict: Dictionary of {filename: file_content} pairs
|
28
|
+
filename = os.path.relpath(file_path, start=root_dir) # 相对路径获取, 用于在 zip 内的路径定位
|
29
|
+
password: Optional password for the ZIP file
|
30
|
+
Returns:
|
31
|
+
BytesIO object containing the ZIP file
|
32
|
+
"""
|
33
|
+
zip_buffer = io.BytesIO()
|
34
|
+
try:
|
35
|
+
if password:
|
36
|
+
with pyzipper.AESZipFile(zip_buffer, 'w', compression=pyzipper.ZIP_DEFLATED, encryption=pyzipper.WZ_AES) as zipf:
|
37
|
+
zipf.setpassword(password.encode('utf-8'))
|
38
|
+
for filename, content in file_dict.items():
|
39
|
+
zipf.writestr(filename, content)
|
40
|
+
else:
|
41
|
+
with pyzipper.ZipFile(zip_buffer, 'w', compression=pyzipper.ZIP_DEFLATED) as zipf:
|
42
|
+
for filename, content in file_dict.items():
|
43
|
+
zipf.writestr(filename, content)
|
44
|
+
zip_buffer.seek(0)
|
45
|
+
return zip_buffer
|
46
|
+
except Exception as e:
|
47
|
+
zip_buffer.close()
|
48
|
+
raise e
|
49
|
+
|
50
|
+
|
51
|
+
def process_directory_to_single_zip(root_dir, password=None, zip_name=None):
|
52
|
+
"""Walk through directory and compress all files into a single ZIP.
|
53
|
+
Args:
|
54
|
+
root_dir: Root directory to scan for files
|
55
|
+
password: Optional password for the ZIP file
|
56
|
+
zip_name: Base name for the ZIP file (without extension)
|
57
|
+
"""
|
58
|
+
file_dict = {}
|
59
|
+
for dirpath, _, filenames in os.walk(root_dir):
|
60
|
+
for filename in filenames:
|
61
|
+
file_path = os.path.join(dirpath, filename)
|
62
|
+
try:
|
63
|
+
with open(file_path, 'rb') as f:
|
64
|
+
rel_path = os.path.relpath(file_path, start=root_dir)
|
65
|
+
file_dict[rel_path] = f.read()
|
66
|
+
except Exception as e:
|
67
|
+
print(f"Error reading {file_path}: {str(e)}")
|
68
|
+
if not file_dict:
|
69
|
+
print("No files found to compress.")
|
70
|
+
return
|
71
|
+
|
72
|
+
try:
|
73
|
+
zip_buffer = create_zip_with_files(file_dict, password)
|
74
|
+
timestamp = time.strftime('%Y%m%d_%H%M%S', time.localtime())
|
75
|
+
if zip_name:
|
76
|
+
base_name = f"{zip_name}_{timestamp}.zip"
|
77
|
+
else:
|
78
|
+
base_name = f"archive_{timestamp}.zip"
|
79
|
+
output_path = os.path.join(root_dir, base_name)
|
80
|
+
with open(output_path, 'wb') as out_file:
|
81
|
+
out_file.write(zip_buffer.read())
|
82
|
+
print(f"Created single archive: {output_path}")
|
83
|
+
except Exception as e:
|
84
|
+
print(f"Error creating ZIP archive: {str(e)}")
|
85
|
+
finally:
|
86
|
+
if 'zip_buffer' in locals(): zip_buffer.close()
|
87
|
+
|
88
|
+
|
89
|
+
def compress_specific_files(file_paths:[], output_dir:str, password=None, zip_name=None):
|
90
|
+
"""Compress multiple specified files into a single ZIP archive.
|
91
|
+
Args:
|
92
|
+
file_paths: List of absolute file paths to compress
|
93
|
+
output_dir: Directory where the ZIP file will be saved
|
94
|
+
password: Optional password for the ZIP file
|
95
|
+
zip_name: Base name for the ZIP file (without extension)
|
96
|
+
"""
|
97
|
+
if not file_paths:
|
98
|
+
print("No files specified to compress.")
|
99
|
+
return
|
100
|
+
file_dict = {}
|
101
|
+
for file_path in file_paths:
|
102
|
+
if not os.path.isfile(file_path):
|
103
|
+
print(f"Warning: {file_path} is not a file or doesn't exist. Skipping.")
|
104
|
+
continue
|
105
|
+
try:
|
106
|
+
with open(file_path, 'rb') as f:
|
107
|
+
filename_in_zip = os.path.basename(file_path)
|
108
|
+
file_dict[filename_in_zip] = f.read()
|
109
|
+
except Exception as e:
|
110
|
+
print(f"Error reading {file_path}: {str(e)}")
|
111
|
+
if not file_dict:
|
112
|
+
print("No valid files found to compress.")
|
113
|
+
return
|
114
|
+
try:
|
115
|
+
zip_buffer = create_zip_with_files(file_dict, password)
|
116
|
+
timestamp = time.strftime('%Y%m%d_%H%M%S', time.localtime())
|
117
|
+
if zip_name:
|
118
|
+
base_name = f"{zip_name}_{timestamp}.zip"
|
119
|
+
else:
|
120
|
+
first_file = os.path.basename(file_paths[0])
|
121
|
+
base_name = f"{os.path.splitext(first_file)[0]}_{timestamp}.zip"
|
122
|
+
output_path = os.path.join(output_dir, base_name)
|
123
|
+
os.makedirs(output_dir, exist_ok=True)
|
124
|
+
with open(output_path, 'wb') as out_file:
|
125
|
+
out_file.write(zip_buffer.read())
|
126
|
+
print(f"Created archive: {output_path}")
|
127
|
+
except Exception as e:
|
128
|
+
print(f"Error creating ZIP archive: {str(e)}")
|
129
|
+
finally:
|
130
|
+
if 'zip_buffer' in locals(): zip_buffer.close()
|
ctools/thread_pool.py
CHANGED
@@ -0,0 +1,66 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: gomyck-tools
|
3
|
+
Version: 1.3.2
|
4
|
+
Summary: A tools collection for python development by hao474798383
|
5
|
+
Author-email: gomyck <hao474798383@163.com>
|
6
|
+
License: MIT
|
7
|
+
Requires-Python: >=3.10
|
8
|
+
Description-Content-Type: text/markdown
|
9
|
+
Requires-Dist: jsonpickle~=3.4.2
|
10
|
+
Requires-Dist: SQLAlchemy~=2.0.36
|
11
|
+
Requires-Dist: chardet~=5.2.0
|
12
|
+
Requires-Dist: psycopg2-binary~=2.9.10
|
13
|
+
Requires-Dist: croniter~=5.0.1
|
14
|
+
Requires-Dist: gmssl~=3.2.2
|
15
|
+
Requires-Dist: psutil~=6.1.0
|
16
|
+
Requires-Dist: jsonpath_ng~=1.7.0
|
17
|
+
Requires-Dist: bottle~=0.13.2
|
18
|
+
Requires-Dist: requests~=2.32.3
|
19
|
+
Requires-Dist: urllib3~=1.26.20
|
20
|
+
Requires-Dist: kafka-python~=2.0.2
|
21
|
+
Requires-Dist: bs4~=0.0.2
|
22
|
+
Requires-Dist: paho-mqtt~=2.1.0
|
23
|
+
Requires-Dist: fuzzywuzzy~=0.18.0
|
24
|
+
Requires-Dist: pymysql~=1.1.1
|
25
|
+
Requires-Dist: pyzipper==0.3.6
|
26
|
+
Requires-Dist: prometheus_client==0.21.1
|
27
|
+
Requires-Dist: paramiko==3.5.0
|
28
|
+
Requires-Dist: pyjwt==2.10.1
|
29
|
+
Requires-Dist: cryptography==44.0.2
|
30
|
+
Requires-Dist: redis==5.2.1
|
31
|
+
Provides-Extra: db
|
32
|
+
Requires-Dist: sqlalchemy>=2.0; extra == "db"
|
33
|
+
Requires-Dist: asyncpg>=0.28; extra == "db"
|
34
|
+
Provides-Extra: dev
|
35
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
36
|
+
Requires-Dist: black>=24.0; extra == "dev"
|
37
|
+
Requires-Dist: mypy>=1.0; extra == "dev"
|
38
|
+
Provides-Extra: full
|
39
|
+
Requires-Dist: sqlalchemy>=2.0; extra == "full"
|
40
|
+
Requires-Dist: asyncpg>=0.28; extra == "full"
|
41
|
+
Requires-Dist: pytest>=7.0; extra == "full"
|
42
|
+
Requires-Dist: black>=24.0; extra == "full"
|
43
|
+
Requires-Dist: mypy>=1.0; extra == "full"
|
44
|
+
|
45
|
+
# Gomyck-Tools
|
46
|
+
|
47
|
+
## project
|
48
|
+
|
49
|
+
https://github.com/mzxc
|
50
|
+
|
51
|
+
## install
|
52
|
+
|
53
|
+
This package need python version >= 3.9
|
54
|
+
|
55
|
+
```shell
|
56
|
+
pip install gomyck-tools
|
57
|
+
```
|
58
|
+
|
59
|
+
## usage
|
60
|
+
|
61
|
+
```python
|
62
|
+
from ctools import sys_log
|
63
|
+
sys_log.clog.info('hello world')
|
64
|
+
```
|
65
|
+
|
66
|
+
|
@@ -19,7 +19,7 @@ ctools/credis.py,sha256=sW7yDQvxa7B4dWvGwUH7GROq-7ElRMDhFT6g2C8ryfE,4522
|
|
19
19
|
ctools/cron_lite.py,sha256=f9g7-64GsCxcAW-HUAvT6S-kooScl8zaJyqwHY-X_rE,8308
|
20
20
|
ctools/ctoken.py,sha256=NZSBGF3lJajJFLRIZoeXmpp8h5cKM0dAH2weySgeORc,882
|
21
21
|
ctools/cword.py,sha256=ZRzAFn96yjo-hAbZuGIm4DoBAL2y8tFySWZ5xbYgY6Q,857
|
22
|
-
ctools/czip.py,sha256=
|
22
|
+
ctools/czip.py,sha256=8VQ420KgMF09U8McSXTkaAz0jd0Zzm6qazf3iJADQI4,4674
|
23
23
|
ctools/database.py,sha256=4j8pPBCJ8DwZrWpeBEiLVtYDMjzkDgkPGQTkOD_kzKI,6415
|
24
24
|
ctools/date_utils.py,sha256=h3rvlw_K2F0QTac2Zat_1us76R0P-Qj6_6NeQPfM3VE,1697
|
25
25
|
ctools/dict_wrapper.py,sha256=otxDX0CCKbBCVFtASweo5VEv6_ettH-CptA6azX1mJI,460
|
@@ -49,14 +49,14 @@ ctools/str_diff.py,sha256=QUtXOfsRLTFozH_zByqsC39JeuG3eZtrwGVeLyaHYUI,429
|
|
49
49
|
ctools/string_tools.py,sha256=itK59W4Ed4rQzuyHuioNgDRUcBlfb4ZoZnwmS9cJxiI,1887
|
50
50
|
ctools/sys_info.py,sha256=NvKCuBlWHHiW4bDI4tYZUo3QusvODm1HlW6aAkrllnE,4248
|
51
51
|
ctools/sys_log.py,sha256=oqb1S41LosdeZxtogFVgDk8R4sjiHhUeYJLCzHd728E,2805
|
52
|
-
ctools/thread_pool.py,sha256=
|
52
|
+
ctools/thread_pool.py,sha256=Mt60XMhs-nk-hbkPo8NA7wQ4RxRLZTk4X6vh5Wn3WEw,944
|
53
53
|
ctools/upload_tools.py,sha256=sqe6K3ZWiyY58pFE5IO5mNaS1znnS7U4c4UqY8noED4,1068
|
54
54
|
ctools/win_canvas.py,sha256=PAxI4i1jalfree9d1YG4damjc2EzaHZrgHZCTgk2GiM,2530
|
55
55
|
ctools/win_control.py,sha256=35f9x_ijSyc4ZDkcT32e9ZIhr_ffNxadynrQfFuIdYo,3489
|
56
56
|
ctools/word_fill.py,sha256=xeo-P4DOjQUqd-o9XL3g66wQrE2diUPGwFywm8TdVyw,18210
|
57
57
|
ctools/word_fill_entity.py,sha256=eX3G0Gy16hfGpavQSEkCIoKDdTnNgRRJrFvKliETZK8,985
|
58
58
|
ctools/work_path.py,sha256=OmfYu-Jjg2huRY6Su8zJ_2EGFFhtBZFbobYTwbjJtG4,1817
|
59
|
-
gomyck_tools-1.2.
|
60
|
-
gomyck_tools-1.2.
|
61
|
-
gomyck_tools-1.2.
|
62
|
-
gomyck_tools-1.2.
|
59
|
+
gomyck_tools-1.3.2.dist-info/METADATA,sha256=n0mq8Z9a0-nOrX3PWZ8JA6ILp79wX__r8foWccyIQB4,1682
|
60
|
+
gomyck_tools-1.3.2.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
|
61
|
+
gomyck_tools-1.3.2.dist-info/top_level.txt,sha256=-MiIH9FYRVKp1i5_SVRkaI-71WmF1sZSRrNWFU9ls3s,7
|
62
|
+
gomyck_tools-1.3.2.dist-info/RECORD,,
|
@@ -1,57 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: gomyck-tools
|
3
|
-
Version: 1.2.12
|
4
|
-
Summary: A tools collection for python development by hao474798383
|
5
|
-
Home-page: https://blog.gomyck.com
|
6
|
-
Author: gomyck
|
7
|
-
Author-email: hao474798383@163.com
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
10
|
-
Classifier: Operating System :: OS Independent
|
11
|
-
Requires-Python: >=3.9
|
12
|
-
Description-Content-Type: text/markdown
|
13
|
-
Requires-Dist: jsonpickle ~=3.4.2
|
14
|
-
Requires-Dist: SQLAlchemy ~=2.0.36
|
15
|
-
Requires-Dist: chardet ~=5.2.0
|
16
|
-
Requires-Dist: psycopg2-binary ~=2.9.10
|
17
|
-
Requires-Dist: croniter ~=5.0.1
|
18
|
-
Requires-Dist: gmssl ~=3.2.2
|
19
|
-
Requires-Dist: psutil ~=6.1.0
|
20
|
-
Requires-Dist: jsonpath-ng ~=1.7.0
|
21
|
-
Requires-Dist: bottle ~=0.13.2
|
22
|
-
Requires-Dist: requests ~=2.32.3
|
23
|
-
Requires-Dist: urllib3 ~=1.26.20
|
24
|
-
Requires-Dist: kafka-python ~=2.0.2
|
25
|
-
Requires-Dist: bs4 ~=0.0.2
|
26
|
-
Requires-Dist: paho-mqtt ~=2.1.0
|
27
|
-
Requires-Dist: fuzzywuzzy ~=0.18.0
|
28
|
-
Requires-Dist: pymysql ~=1.1.1
|
29
|
-
Requires-Dist: pyzipper ==0.3.6
|
30
|
-
Requires-Dist: prometheus-client ==0.21.1
|
31
|
-
Requires-Dist: paramiko ==3.5.0
|
32
|
-
Requires-Dist: pyjwt ==2.10.1
|
33
|
-
Requires-Dist: cryptography ==44.0.2
|
34
|
-
Requires-Dist: redis ==5.2.1
|
35
|
-
|
36
|
-
# Gomyck-Tools
|
37
|
-
|
38
|
-
## project
|
39
|
-
|
40
|
-
https://github.com/mzxc
|
41
|
-
|
42
|
-
## install
|
43
|
-
|
44
|
-
This package need python version >= 3.9
|
45
|
-
|
46
|
-
```shell
|
47
|
-
pip install gomyck-tools
|
48
|
-
```
|
49
|
-
|
50
|
-
## usage
|
51
|
-
|
52
|
-
```python
|
53
|
-
from ctools import sys_log
|
54
|
-
sys_log.clog.info('hello world')
|
55
|
-
```
|
56
|
-
|
57
|
-
|
File without changes
|