From 328804dd7182c83aa5f14f6fdc9ff05406361c0b Mon Sep 17 00:00:00 2001 From: zhangzepeng Date: Tue, 29 Aug 2023 16:53:36 +0800 Subject: [PATCH] =?UTF-8?q?=E2=80=98=E7=BC=96=E8=AF=91=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E6=B8=85=E7=90=86=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangzepeng --- ide/server/smarperfServer.py | 26 +++++++++---------- .../build/{protoc_w.sh => protoc_w.py} | 0 2 files changed, 13 insertions(+), 13 deletions(-) rename trace_streamer/build/{protoc_w.sh => protoc_w.py} (100%) diff --git a/ide/server/smarperfServer.py b/ide/server/smarperfServer.py index 2f30cb88..d3d0ffc2 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 -- Gitee