diff --git a/ide/server/smarperfServer.py b/ide/server/smarperfServer.py index 2f30cb886a770446a588bd3ccd2df6c3f313cc08..d3d0ffc214351a7e325ee2d39da85091fe314310 100644 --- a/ide/server/smarperfServer.py +++ b/ide/server/smarperfServer.py @@ -161,19 +161,19 @@ class SpRequestHandler(http.server.BaseHTTPRequestHandler): nowDate = datetime.now() now = nowDate.strftime("%Y-%m-%d") fileName = f"{now}.txt" - dst = open("./logger/" + fileName, "a") - content_type = self.headers.get("Content-Type") - if content_type and content_type.startswith("application/json"): - content_length = int(self.headers.get("Content-Length", 0)) - req_data = self.rfile.read(content_length) - req = json.loads(req_data) - now = datetime.now() - formatted_date = now.strftime("%Y-%m-%d %H:%M:%S") - dst.write(f"{formatted_date} {req['fileName']} ({req['fileSize']} M)\n") - self.send_response(200) - self.send_header("Content-type", "text/html") - self.end_headers() - self.wfile.write(bytes(f"日志写入成功", "utf-8")) + with open("./logger/" + fileName, "a") as dst: + content_type = self.headers.get("Content-Type") + if content_type and content_type.startswith("application/json"): + content_length = int(self.headers.get("Content-Length", 0)) + req_data = self.rfile.read(content_length) + req = json.loads(req_data) + now = datetime.now() + formatted_date = now.strftime("%Y-%m-%d %H:%M:%S") + dst.write(f"{formatted_date} {req['fileName']} ({req['fileSize']} M)\n") + self.send_response(200) + self.send_header("Content-type", "text/html") + self.end_headers() + self.wfile.write(bytes(f"日志写入成功", "utf-8")) def check_dir(self, dir_path): if not os.path.exists(dir_path): diff --git a/trace_streamer/build/protoc_w.sh b/trace_streamer/build/protoc_w.py similarity index 100% rename from trace_streamer/build/protoc_w.sh rename to trace_streamer/build/protoc_w.py