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', ),