44import re
55
66# 要排除的目录列表
7- EXCLUDE_DIRS = ['.git' , '.idea' , 'soft' , 'apps/cat' , 'plugins/pvideo' , 'plugins/req-proxy' , 'pyTools' , 'drop_code' ,
7+ EXCLUDE_DIRS = ['.git' , '.idea' , 'soft' , 'apps/cat' , 'plugins/pvideo' , 'plugins/req-proxy' , 'plugins/pup-sniffer' ,
8+ 'pyTools' , 'drop_code' ,
89 'jstest' ,
910 'local' , 'logs' ,
1011 '对话1.txt' ,
@@ -54,18 +55,18 @@ def generate_archive_name(script_dir, green=False):
5455 """
5556 # 获取当前目录名
5657 current_dir = os .path .basename (script_dir )
57-
58+
5859 # 获取当前时间
5960 current_time = datetime .datetime .now ().strftime ("%Y%m%d" )
60-
61+
6162 # 根据是否传入 green 参数生成压缩包文件名
6263 archive_suffix = "-green" if green else ""
6364 archive_name = f"{ current_dir } -{ current_time } { archive_suffix } .7z"
64-
65+
6566 # 压缩包输出路径 (脚本所在目录的外面)
6667 parent_dir = os .path .abspath (os .path .join (script_dir , ".." ))
6768 archive_path = os .path .join (parent_dir , archive_name )
68-
69+
6970 return archive_path
7071
7172
@@ -81,11 +82,11 @@ def build_exclude_params(script_dir, green=False):
8182 list: 排除参数列表
8283 """
8384 exclude_params = []
84-
85+
8586 # 排除目录
8687 for exclude_dir in EXCLUDE_DIRS :
8788 exclude_params .append (f"-xr!{ exclude_dir } " )
88-
89+
8990 # 排除文件
9091 for exclude_file in EXCLUDE_FILES :
9192 # 使用相对路径来确保文件的准确性
@@ -94,13 +95,13 @@ def build_exclude_params(script_dir, green=False):
9495 exclude_params .append (f"-xr!{ exclude_file } " )
9596 else :
9697 print (f"警告: { exclude_file } 不存在!" )
97-
98+
9899 # 如果启用 green 筛选,排除不符合条件的文件
99100 if green :
100101 green_files = filter_green_files (script_dir )
101102 for file in green_files :
102103 exclude_params .append (f"-x!{ file } " )
103-
104+
104105 return exclude_params
105106
106107
@@ -115,10 +116,10 @@ def execute_compression(archive_path, script_dir, exclude_params):
115116 """
116117 # 构建命令,打包目录内容而不包含目录本身
117118 command = f"7z a \" { archive_path } \" \" { script_dir } \\ *\" " + " " .join (exclude_params )
118-
119+
119120 # 打印构建的命令进行调试
120121 print (f"构建的 7z 命令: { command } " )
121-
122+
122123 try :
123124 # 执行压缩命令
124125 os .system (command )
@@ -137,10 +138,10 @@ def compress_directory(script_dir, green=False):
137138 """
138139 # 生成压缩包文件名和路径
139140 archive_path = generate_archive_name (script_dir , green )
140-
141+
141142 # 构建排除参数
142143 exclude_params = build_exclude_params (script_dir , green )
143-
144+
144145 # 执行压缩
145146 execute_compression (archive_path , script_dir , exclude_params )
146147
0 commit comments