Skip to content

Commit 5b6ec5b

Browse files
committed
add:新增打包发布7z脚本
1 parent 052e96a commit 5b6ec5b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Diff for: package.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import datetime
3+
4+
# 要排除的目录列表,可以根据需要自行添加
5+
EXCLUDE_DIRS = ['.git', '.idea','soft','drop_code','jstest','local','logs','对话1.txt']
6+
7+
def compress_directory():
8+
# 获取当前目录名
9+
current_dir = os.path.basename(os.getcwd())
10+
11+
# 获取当前时间
12+
current_time = datetime.datetime.now().strftime("%Y%m%d")
13+
14+
# 生成压缩包文件名
15+
archive_name = f"{current_dir}-{current_time}.7z"
16+
17+
# 压缩包输出路径 (脚本所在目录的外面)
18+
parent_dir = os.path.abspath(os.path.join(os.getcwd(), ".."))
19+
archive_path = os.path.join(parent_dir, archive_name)
20+
21+
# 构建 7z 压缩命令
22+
exclude_params = []
23+
for exclude_dir in EXCLUDE_DIRS:
24+
exclude_params.extend(["-xr!", exclude_dir])
25+
26+
command = (
27+
f"7z a \"{archive_path}\" ./ -r " + " ".join(f"-xr!{dir}" for dir in EXCLUDE_DIRS)
28+
)
29+
30+
try:
31+
# 执行压缩命令
32+
os.system(command)
33+
print(f"压缩完成: {archive_path}")
34+
except Exception as e:
35+
print(f"压缩失败: {e}")
36+
37+
if __name__ == "__main__":
38+
compress_directory()

0 commit comments

Comments
 (0)