fix: output error message by logging

This commit is contained in:
wcbing 2025-01-01 20:12:11 +08:00
parent 891b3d8cf2
commit 179b5fcc2f
2 changed files with 9 additions and 13 deletions

View File

@ -72,9 +72,9 @@ if __name__ == "__main__":
check_download(args[1], args[2], args[3], args[4]) check_download(args[1], args[2], args[3], args[4])
elif len(args) == 4: elif len(args) == 4:
check_download(args[1], args[2], args[3], "x86_64") check_download(args[1], args[2], args[3], "x86_64")
elif len(args) > 1:
logging.error(f"Unknown Args: {args[1:]}")
else: else:
if len(args) > 1:
print(f"Unknown Args: {args[1:]}\n")
print(f"Usage: {args[0]} <package_name> <version> <url> [arch]") print(f"Usage: {args[0]} <package_name> <version> <url> [arch]")
print("options:") print("options:")
print(" arch: x86_64, arm64. default is x86_64") print(" arch: x86_64, arm64. default is x86_64")

View File

@ -31,7 +31,7 @@ def read_repo_list(repo_list_file):
with open(repo_list_file, "r") as f: with open(repo_list_file, "r") as f:
return json.load(f) return json.load(f)
except Exception as e: except Exception as e:
logging.warning(f"Error reading repo list: {e}") logging.error(f"Error reading repo list: {e}")
return [] return []
@ -41,7 +41,7 @@ def get_remote_packages(repo_url, file_path):
try: try:
response = requests.get(file_url, timeout=10) response = requests.get(file_url, timeout=10)
if response.status_code != 200: if response.status_code != 200:
logging.warning( logging.error(
f"GetError: {file_url} returned status {response.status_code}" f"GetError: {file_url} returned status {response.status_code}"
) )
return b"" return b""
@ -52,7 +52,7 @@ def get_remote_packages(repo_url, file_path):
content += b"\n" content += b"\n"
return content.replace(b"Filename: ", f"Filename: {repo_url}".encode()) return content.replace(b"Filename: ", f"Filename: {repo_url}".encode())
except Exception as e: except Exception as e:
logging.warning(f"Error fetching packages: {e}") logging.error(f"Error fetching packages: {e}")
return b"" return b""
@ -86,18 +86,14 @@ def get_latest(deb_packages):
def process_repo(r): def process_repo(r):
try: try:
deb_packages = b"" deb_packages = b""
if r.get("mix_path"): if r.get("mix_path"): # 获取扁平 Repo 中包信息
# 获取扁平 Repo 中包信息
deb_packages += get_remote_packages(r["repo"], r["mix_path"]) deb_packages += get_remote_packages(r["repo"], r["mix_path"])
else: else:
if r.get("amd64_path"): if r.get("amd64_path"): # 获取 Repo 中 Amd64 包信息
# 获取 Repo 中 Amd64 包信息
deb_packages += get_remote_packages(r["repo"], r["amd64_path"]) deb_packages += get_remote_packages(r["repo"], r["amd64_path"])
if r.get("arm64_path"): if r.get("arm64_path"): # 获取 Repo 中 Arm64 包信息
# 获取 Repo 中 Arm64 包信息
deb_packages += get_remote_packages(r["repo"], r["arm64_path"]) deb_packages += get_remote_packages(r["repo"], r["arm64_path"])
if r.get("all_path"): if r.get("all_path"): # 获取 Repo 中 All 包信息
# 获取 Repo 中 All 包信息
deb_packages += get_remote_packages(r["repo"], r["all_path"]) deb_packages += get_remote_packages(r["repo"], r["all_path"])
get_latest(deb_packages) get_latest(deb_packages)
except Exception as e: except Exception as e: