mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-08 21:15:46 +08:00
🎨 检测启动环境, 并提供选项切换是否自动
This commit is contained in:
parent
17205829fd
commit
1a8435277f
@ -5,6 +5,7 @@ import platform
|
|||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
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.utils.plugins_config.gs_config import core_plugins_config
|
||||||
from gsuid_core.plugins.core_command.core_status.command_global_val import (
|
from gsuid_core.plugins.core_command.core_status.command_global_val import (
|
||||||
save_global_val,
|
save_global_val,
|
||||||
@ -21,6 +22,17 @@ kill -9 {}
|
|||||||
restart_command = core_plugins_config.get_config('restart_command').data
|
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:
|
async def get_restart_sh() -> str:
|
||||||
args = f'{restart_command} {str(bot_start.absolute())}'
|
args = f'{restart_command} {str(bot_start.absolute())}'
|
||||||
return _restart_sh.format(str(bot_start.absolute()), args)
|
return _restart_sh.format(str(bot_start.absolute()), args)
|
||||||
|
@ -38,20 +38,37 @@ def on_core_shutdown(func: Callable):
|
|||||||
return func
|
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
|
path = Path(__file__).parent.parent
|
||||||
pdm_python_path = path / '.pdm-python'
|
pdm_python_path = path / '.pdm-python'
|
||||||
|
|
||||||
if start_venv == 'auto':
|
if start_venv == 'auto':
|
||||||
if pdm_python_path.exists():
|
if pdm_python_path.exists():
|
||||||
return 'pdm run pip'
|
command = PDM
|
||||||
else:
|
else:
|
||||||
return 'poetry run pip'
|
command = POETRY
|
||||||
elif start_venv == 'pdm':
|
elif start_venv == 'pdm':
|
||||||
return 'pdm run pip'
|
command = PDM
|
||||||
elif start_venv == 'poetry':
|
elif start_venv == 'poetry':
|
||||||
return 'poetry run pip'
|
command = POETRY
|
||||||
else:
|
else:
|
||||||
return start_venv.strip()
|
command = start_venv.strip()
|
||||||
|
|
||||||
|
return command
|
||||||
|
|
||||||
|
|
||||||
class GsServer:
|
class GsServer:
|
||||||
@ -212,7 +229,7 @@ def check_pyproject(pyproject: Path):
|
|||||||
|
|
||||||
def install_dependencies(dependencies: Dict):
|
def install_dependencies(dependencies: Dict):
|
||||||
global installed_dependencies
|
global installed_dependencies
|
||||||
start_tool = check_start_tool()
|
start_tool = check_start_tool(True)
|
||||||
if start_tool == 'pdm':
|
if start_tool == 'pdm':
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
'pdm run python -m ensurepip',
|
'pdm run python -m ensurepip',
|
||||||
|
@ -12,8 +12,13 @@ CONIFG_DEFAULT: Dict[str, GSC] = {
|
|||||||
'Gproxy': GsStrConfig('设置米游社国际代理', '设置国际服的代理地址', ''),
|
'Gproxy': GsStrConfig('设置米游社国际代理', '设置国际服的代理地址', ''),
|
||||||
'Nproxy': GsStrConfig('设置米游社常规代理', '设置常规的代理地址', ''),
|
'Nproxy': GsStrConfig('设置米游社常规代理', '设置常规的代理地址', ''),
|
||||||
'_pass_API': GsStrConfig('神奇API', '设置某种神奇的API', ''),
|
'_pass_API': GsStrConfig('神奇API', '设置某种神奇的API', ''),
|
||||||
|
'is_use_custom_restart_command': GsBoolConfig(
|
||||||
|
'使用自定义重启命令',
|
||||||
|
'是否使用下面的自定义重启命令, 否则自动判断环境',
|
||||||
|
False,
|
||||||
|
),
|
||||||
'restart_command': GsStrConfig(
|
'restart_command': GsStrConfig(
|
||||||
'重启命令',
|
'自定义重启命令',
|
||||||
'自定义使用gs重启时触发的控制台命令(看不懂勿改)',
|
'自定义使用gs重启时触发的控制台命令(看不懂勿改)',
|
||||||
'poetry run python',
|
'poetry run python',
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user