@@ -30,6 +30,7 @@ def __init__(self, github_token, github_proxy, tools_path) -> None:
3030
3131 def start (self , out_path ):
3232 self .__set_proxy__ ()
33+ tools_name = ""
3334 with open (file = self .tools_path , encoding = "utf8" ) as open_file :
3435 content = open_file .read ()
3536 try :
@@ -60,7 +61,7 @@ def start(self, out_path):
6061 raise (CustomException (error_msg ))
6162 except KeyError as e :
6263 msg = re .sub (r'KeyError.*?:' ,"" , str (e )).strip ()
63- error_msg = ("配置文件: %s 中未检索到Key: %s ,请参考配置样例文件后重新输入!!!" ) % (self .tools_path ,msg )
64+ error_msg = ("%s, 配置文件: %s 中未检索到Key: %s ,请参考配置样例文件后重新输入!!!" ) % (tools_name , self .tools_path ,msg )
6465 raise (CustomException (error_msg ))
6566 except Exception as e :
6667 raise (e )
@@ -105,21 +106,25 @@ def download_code_or_binary(self, tools_out_path, tools_url, platforms, tools_ty
105106 except KeyError as e :
106107 # 如果是Java版本则下载所有Java版本的
107108 sys_platform = platforms ["java" ]
108- except Exception as e :
109- raise (e )
110-
111- if type (sys_platform ) == type ("str" ):
112- # 如果是str类型则直接获取工具名称
113- file_name = sys_platform
114- else :
115- cpu_type = get_cpu_type () # 获取CPU类型
116- file_name = sys_platform [cpu_type ]
117-
118- if "www" in tools_url :
119- api_url = tools_url .replace ("www" , "" )
120- api_url = tools_url .replace ("github.com" , "api.github.com/repos" ) + "/releases/latest"
121109
122110 try :
111+ if type (sys_platform ) == type ("str" ):
112+ # 如果是str类型则直接获取工具名称
113+ file_name = sys_platform
114+ else :
115+ cpu_type = get_cpu_type ().lower () # 获取CPU类型
116+ if cpu_type == "x86" or cpu_type == "i386" or cpu_type == "ia32" :
117+ cpu_type = "i386"
118+ if cpu_type == "x86_64" or cpu_type == "x64" or cpu_type == "amd64" :
119+ cpu_type = "amd64"
120+ if cpu_type == "arm" or cpu_type == "arm64" :
121+ cpu_type = "arm64"
122+ file_name = sys_platform [cpu_type ]
123+
124+ if "www" in tools_url :
125+ api_url = tools_url .replace ("www" , "" )
126+ api_url = tools_url .replace ("github.com" , "api.github.com/repos" ) + "/releases/latest"
127+
123128 resp = self .__requsets__ (api_url )
124129 repos_json_obj = resp .json ()
125130 tools_vesion = str (repos_json_obj ["tag_name" ])
@@ -144,7 +149,7 @@ def download_code_or_binary(self, tools_out_path, tools_url, platforms, tools_ty
144149 # 无发布版本忽略
145150 return
146151 except AttributeError as e :
147- errmsg = ("访问地址 %s 地址异常,请检查网络或者使用-p参数配置代理后重试 !!!" % api_url )
152+ errmsg = ("访问地址 %s 地址异常,请检查网络或者使用-p参数配置代理后重试或者使用-t参数追加github token !!!" % api_url )
148153 raise (CustomException (errmsg ))
149154 except Exception as e :
150155 raise (e )
@@ -255,7 +260,16 @@ def init():
255260 if not os .path .exists (tools_path ):
256261 script_tools = os .path .join (os .path .dirname (__file__ ), "tools.json" )
257262 shutil .copyfile (script_tools , tools_path )
258-
263+ else :
264+ # 文件存在将最新的tools.json文件替换,并备份旧的配置文件
265+ script_tools = os .path .join (os .path .dirname (__file__ ), "tools.json" )
266+ tools_mtime = os .path .getmtime (tools_path )
267+ script_tools_mtime = os .path .getmtime (script_tools )
268+ if script_tools_mtime > tools_mtime :
269+ old_script_tools = os .path .join (doc_dir , "tools.json_" + str (tools_mtime ))
270+ shutil .move (tools_path , old_script_tools ) # 备份旧的tools.json文件
271+ shutil .copyfile (script_tools , tools_path ) # 替换为新的tools.json文件
272+
259273 # 获取全局配置文件信息
260274 config_dict = None
261275 with open (config_path , "r" ,encoding = "utf-8" ) as config_file :
0 commit comments