添加阿里镜像,修复依赖增加删除python/Scripts,fast/slow->测试版/稳定版

This commit is contained in:
EightyDollars 2024-11-28 15:34:49 +08:00
parent 9e6001d0e0
commit 003769b8e4
4 changed files with 72 additions and 12 deletions

View file

@ -3,14 +3,13 @@ import mimetypes
from pathlib import Path from pathlib import Path
from shutil import rmtree from shutil import rmtree
from subprocess import PIPE, STDOUT, Popen from subprocess import PIPE, STDOUT, Popen
import webview import webview
mimetypes.add_type("text/html", ".html") mimetypes.add_type("text/html", ".html")
mimetypes.add_type("text/css", ".css") mimetypes.add_type("text/css", ".css")
mimetypes.add_type("application/javascript", ".js") mimetypes.add_type("application/javascript", ".js")
version = "2024-10-10" version = "2024-11-28"
config = { config = {
"page": "init", "page": "init",
@ -34,6 +33,7 @@ def custom_event(data):
mirror_list = { mirror_list = {
"aliyun": "https://mirrors.aliyun.com/pypi/simple/",
"pypi": "https://pypi.org/simple", "pypi": "https://pypi.org/simple",
"tuna": "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple", "tuna": "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple",
"sjtu": "https://mirror.sjtu.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): def set_mirror(self, mirror):
config["mirror"] = mirror config["mirror"] = mirror
def update_self(self):
# 更新启动器本身
pass
def rm_site_packages(self): def rm_site_packages(self):
site_packages_path = Path("./python/Lib/site-packages") site_packages_path = Path("./python/Lib/site-packages")
if site_packages_path.exists(): if site_packages_path.exists():
@ -79,6 +83,13 @@ class Api:
return "移除成功" return "移除成功"
return "python\\Lib\\site-packages目录不存在" 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): def run(self, command, cwd=None):
command = command_list[command] command = command_list[command]
if callable(command): if callable(command):
@ -101,9 +112,7 @@ class Api:
return "failed" return "failed"
window = webview.create_window( window = webview.create_window("mower-ng launcher", "ui/dist/index.html", js_api=Api())
f"mower-ng launcher {version}", "ui/dist/index.html", js_api=Api()
)
webview.start() webview.start()
with config_path.open("w") as f: with config_path.open("w") as f:

33
log.py Normal file
View file

@ -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()

View file

@ -16,23 +16,40 @@ async function rm_site_packages() {
}) })
running.value = false 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
}
</script> </script>
<template> <template>
<n-flex <n-flex vertical style="
vertical
style="
gap: 16px; gap: 16px;
height: 100%; height: 100%;
padding: 16px; padding: 16px;
box-sizing: border-box; box-sizing: border-box;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
" ">
>
<n-button class="fix-btn" type="error" secondary size="large" @click="rm_site_packages"> <n-button class="fix-btn" type="error" secondary size="large" @click="rm_site_packages">
移除 site-packages 移除 site-packages
</n-button> </n-button>
<n-button class="fix-btn" type="error" secondary size="large" @click="rm_python_script">
移除 python/Script
</n-button>
</n-flex> </n-flex>
</template> </template>

View file

@ -43,14 +43,15 @@ provide('current_state', current_state)
<n-form-item label="mower-ng 代码分支"> <n-form-item label="mower-ng 代码分支">
<n-radio-group v-model:value="branch"> <n-radio-group v-model:value="branch">
<n-flex> <n-flex>
<n-radio value="fast">fast</n-radio> <n-radio value="fast">测试版</n-radio>
<n-radio value="slow">slow</n-radio> <n-radio value="slow">稳定版</n-radio>
</n-flex> </n-flex>
</n-radio-group> </n-radio-group>
</n-form-item> </n-form-item>
<n-form-item label="PyPI 仓库镜像"> <n-form-item label="PyPI 仓库镜像">
<n-radio-group v-model:value="mirror"> <n-radio-group v-model:value="mirror">
<n-flex> <n-flex>
<n-radio value="aliyun">阿里云镜像站</n-radio>
<n-radio value="pypi">PyPI</n-radio> <n-radio value="pypi">PyPI</n-radio>
<n-radio value="sjtu">上海交通大学镜像站</n-radio> <n-radio value="sjtu">上海交通大学镜像站</n-radio>
<n-radio value="tuna">清华大学镜像站</n-radio> <n-radio value="tuna">清华大学镜像站</n-radio>