From 1a8435277f347df1a1a56d02928612c8eea1ebbc Mon Sep 17 00:00:00 2001 From: KimigaiiWuyi <444835641@qq.com> Date: Tue, 4 Jun 2024 04:07:13 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E6=A3=80=E6=B5=8B=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E7=8E=AF=E5=A2=83,=20=E5=B9=B6=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E5=88=87=E6=8D=A2=E6=98=AF=E5=90=A6=E8=87=AA?= =?UTF-8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core_command/core_restart/restart.py | 12 +++++++ gsuid_core/server.py | 31 ++++++++++++++----- .../utils/plugins_config/config_default.py | 7 ++++- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/gsuid_core/plugins/core_command/core_restart/restart.py b/gsuid_core/plugins/core_command/core_restart/restart.py index d2f869d..866698c 100644 --- a/gsuid_core/plugins/core_command/core_restart/restart.py +++ b/gsuid_core/plugins/core_command/core_restart/restart.py @@ -5,6 +5,7 @@ import platform import subprocess from pathlib import Path +from gsuid_core.server import check_start_tool from gsuid_core.utils.plugins_config.gs_config import core_plugins_config from gsuid_core.plugins.core_command.core_status.command_global_val import ( save_global_val, @@ -21,6 +22,17 @@ kill -9 {} restart_command = core_plugins_config.get_config('restart_command').data +def get_restart_command(): + is_use_custom_restart_command = core_plugins_config.get_config( + 'is_use_custom_restart_command' + ).data + if is_use_custom_restart_command: + return restart_command + else: + tool = check_start_tool() + return f'{tool} run python' + + async def get_restart_sh() -> str: args = f'{restart_command} {str(bot_start.absolute())}' return _restart_sh.format(str(bot_start.absolute()), args) diff --git a/gsuid_core/server.py b/gsuid_core/server.py index 23fb2a7..bf72971 100644 --- a/gsuid_core/server.py +++ b/gsuid_core/server.py @@ -38,20 +38,37 @@ def on_core_shutdown(func: Callable): return func -def check_start_tool(): +def check_start_tool(is_pip: bool = False): + PDM = 'pdm' + POETRY = 'poetry' + OTHER = start_venv.strip() + + if is_pip: + PIP = ' run python -m pip' + PDM += PIP + POETRY += PIP + + if OTHER == 'python': + OTHER = 'python -m pip' + else: + OTHER += PIP + path = Path(__file__).parent.parent pdm_python_path = path / '.pdm-python' + if start_venv == 'auto': if pdm_python_path.exists(): - return 'pdm run pip' + command = PDM else: - return 'poetry run pip' + command = POETRY elif start_venv == 'pdm': - return 'pdm run pip' + command = PDM elif start_venv == 'poetry': - return 'poetry run pip' + command = POETRY else: - return start_venv.strip() + command = start_venv.strip() + + return command class GsServer: @@ -212,7 +229,7 @@ def check_pyproject(pyproject: Path): def install_dependencies(dependencies: Dict): global installed_dependencies - start_tool = check_start_tool() + start_tool = check_start_tool(True) if start_tool == 'pdm': result = subprocess.run( 'pdm run python -m ensurepip', diff --git a/gsuid_core/utils/plugins_config/config_default.py b/gsuid_core/utils/plugins_config/config_default.py index 61c8ae8..1df69cc 100644 --- a/gsuid_core/utils/plugins_config/config_default.py +++ b/gsuid_core/utils/plugins_config/config_default.py @@ -12,8 +12,13 @@ CONIFG_DEFAULT: Dict[str, GSC] = { 'Gproxy': GsStrConfig('设置米游社国际代理', '设置国际服的代理地址', ''), 'Nproxy': GsStrConfig('设置米游社常规代理', '设置常规的代理地址', ''), '_pass_API': GsStrConfig('神奇API', '设置某种神奇的API', ''), + 'is_use_custom_restart_command': GsBoolConfig( + '使用自定义重启命令', + '是否使用下面的自定义重启命令, 否则自动判断环境', + False, + ), 'restart_command': GsStrConfig( - '重启命令', + '自定义重启命令', '自定义使用gs重启时触发的控制台命令(看不懂勿改)', 'poetry run python', ),