(cls, *now_report: Dict)
| 1054 | |
| 1055 | @classmethod |
| 1056 | def update_report(cls, *now_report: Dict) -> Optional[str]: |
| 1057 | try: |
| 1058 | with open(cls.REPORT_FILE, "r") as fs: |
| 1059 | old_data = json.loads(fs.read()) |
| 1060 | except: |
| 1061 | old_data = {"environments": [], "update_time": int(time.time())} |
| 1062 | |
| 1063 | path_map = OrderedDict() |
| 1064 | for e in old_data["environments"]: |
| 1065 | path_map[e["bin_path"]] = e |
| 1066 | |
| 1067 | add_list = [] |
| 1068 | for e in now_report: |
| 1069 | if e["bin_path"] in path_map: |
| 1070 | tmp_ps = path_map[e["bin_path"]]["ps"] |
| 1071 | path_map[e["bin_path"]].update(e) |
| 1072 | if tmp_ps and not path_map[e["bin_path"]]["ps"]: |
| 1073 | path_map[e["bin_path"]]["ps"] = tmp_ps |
| 1074 | else: |
| 1075 | path_map[e["bin_path"]] = e |
| 1076 | add_list.append(e) |
| 1077 | |
| 1078 | now_data = {"environments": add_list + old_data["environments"], "update_time": int(time.time())} |
| 1079 | try: |
| 1080 | with open(cls.REPORT_FILE, "w") as fs: |
| 1081 | fs.write(json.dumps(now_data, indent=4)) |
| 1082 | return None |
| 1083 | except Exception as e: |
| 1084 | return "保存记录失败:{}".format(e) |
| 1085 | |
| 1086 | def init_report(self): |
| 1087 | if os.path.exists(self.REPORT_FILE): |
no test coverage detected