From 003769b8e496a7e97644dba884f1f916dd0b6c03 Mon Sep 17 00:00:00 2001 From: EightyDollars Date: Thu, 28 Nov 2024 15:34:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=98=BF=E9=87=8C=E9=95=9C?= =?UTF-8?q?=E5=83=8F=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=BE=9D=E8=B5=96=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=88=A0=E9=99=A4python/Scripts=EF=BC=8Cfast/slow->?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=89=88/=E7=A8=B3=E5=AE=9A=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py => launcher.py | 19 ++++++++++++++----- log.py | 33 +++++++++++++++++++++++++++++++++ ui/src/pages/Fix.vue | 27 ++++++++++++++++++++++----- ui/src/pages/Update.vue | 5 +++-- 4 files changed, 72 insertions(+), 12 deletions(-) rename main.py => launcher.py (86%) create mode 100644 log.py diff --git a/main.py b/launcher.py similarity index 86% rename from main.py rename to launcher.py index bea2394..b0ab98e 100644 --- a/main.py +++ b/launcher.py @@ -3,14 +3,13 @@ import mimetypes from pathlib import Path from shutil import rmtree from subprocess import PIPE, STDOUT, Popen - import webview mimetypes.add_type("text/html", ".html") mimetypes.add_type("text/css", ".css") mimetypes.add_type("application/javascript", ".js") -version = "2024-10-10" +version = "2024-11-28" config = { "page": "init", @@ -34,6 +33,7 @@ def custom_event(data): mirror_list = { + "aliyun": "https://mirrors.aliyun.com/pypi/simple/", "pypi": "https://pypi.org/simple", "tuna": "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple", "sjtu": "https://mirror.sjtu.edu.cn/pypi/web/simple", @@ -72,6 +72,10 @@ class Api: def set_mirror(self, mirror): config["mirror"] = mirror + def update_self(self): + # 更新启动器本身 + pass + def rm_site_packages(self): site_packages_path = Path("./python/Lib/site-packages") if site_packages_path.exists(): @@ -79,6 +83,13 @@ class Api: return "移除成功" return "python\\Lib\\site-packages目录不存在" + def rm_python_script(self): + python_script_path = Path("./python/Scripts") + if python_script_path.exists(): + rmtree(python_script_path) + return "移除成功" + return "python\\Scripts目录不存在" + def run(self, command, cwd=None): command = command_list[command] if callable(command): @@ -101,9 +112,7 @@ class Api: return "failed" -window = webview.create_window( - f"mower-ng launcher {version}", "ui/dist/index.html", js_api=Api() -) +window = webview.create_window("mower-ng launcher", "ui/dist/index.html", js_api=Api()) webview.start() with config_path.open("w") as f: diff --git a/log.py b/log.py new file mode 100644 index 0000000..686d527 --- /dev/null +++ b/log.py @@ -0,0 +1,33 @@ +import logging +from logging.handlers import RotatingFileHandler + + +# 配置日志 +def setup_logger(): + logger = logging.getLogger("launcher.log") + logger.setLevel(logging.DEBUG) + + # 控制台输出 + console_handler = logging.StreamHandler() + console_handler.setLevel(logging.DEBUG) + + # 文件输出 + file_handler = RotatingFileHandler( + "launcher.log", maxBytes=5 * 1024 * 1024, backupCount=3 + ) + file_handler.setLevel(logging.INFO) + + # 设置格式化器 + formatter = logging.Formatter("%(asctime)s [%(levelname)s] - %(message)s") + console_handler.setFormatter(formatter) + file_handler.setFormatter(formatter) + + # 添加 Handler + logger.addHandler(console_handler) + logger.addHandler(file_handler) + + return logger + + +# 创建全局 Logger 实例 +logger = setup_logger() diff --git a/ui/src/pages/Fix.vue b/ui/src/pages/Fix.vue index 1f97086..89e1148 100644 --- a/ui/src/pages/Fix.vue +++ b/ui/src/pages/Fix.vue @@ -16,23 +16,40 @@ async function rm_site_packages() { }) running.value = false } + + +async function rm_python_script() { + running.value = true + notification['info']({ + content: '提示', + meta: '开始移除python/Script', + duration: 3000 + }) + const response = await pywebview.api.rm_python_script() + notification['info']({ + content: '提示', + meta: response, + duration: 3000 + }) + running.value = false +} diff --git a/ui/src/pages/Update.vue b/ui/src/pages/Update.vue index 567b794..99dc1bc 100644 --- a/ui/src/pages/Update.vue +++ b/ui/src/pages/Update.vue @@ -43,14 +43,15 @@ provide('current_state', current_state) - fast - slow + 测试版 + 稳定版 + 阿里云镜像站 PyPI 上海交通大学镜像站 清华大学镜像站