import os file_src = "dl_bg_test_h.jpg" file_name = "dl_bg_test_h.jpg" package_name = "h5yxd-csjs2test" param_dic = { "file_src": file_src, "file_name": file_name, "package_name": package_name, } def check_file_size(param_dic={}): file_src = param_dic.get("file_src") file_name = param_dic.get("file_name") package_name = param_dic.get("package_name") # 获取文件名字 file_size = os.stat(file_src).st_size / 1024 response_data = { "code":"success", "msg":"检测通过", } # 获取file_name的前一节 pre_file_name = file_name.split(".")[0] if package_name.startswith("h5") or package_name.startswith("wxgame"): if pre_file_name.endswith("_h"): if file_size>100: response_data["code"] = "fail" response_data["msg"] = f"ERROR :{package_name}下的{file_name}>100KB" elif pre_file_name.endswith("_w"): if file_size>500: response_data["code"] = "fail" response_data["msg"] = f"ERROR :{package_name}下的{file_name}>500KB" return response_data check_file_size(param_dic)