jiateng_ws/utils/app_mode.py

56 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import logging
from utils.config_loader import ConfigLoader
class AppMode:
"""
应用运行模式工具类,用于判断当前系统是单机模式还是接口模式
"""
@staticmethod
def get_mode():
"""
获取当前应用运行模式
Returns:
str: 'standalone'(单机模式) 或 'api'(接口模式)
"""
config_loader = ConfigLoader.get_instance()
return config_loader.get_app_mode()
@staticmethod
def set_mode(mode):
"""
设置应用运行模式
Args:
mode: 'standalone'(单机模式) 或 'api'(接口模式)
Returns:
bool: 是否设置成功
"""
config_loader = ConfigLoader.get_instance()
result = config_loader.set_app_mode(mode)
logging.info(f"应用运行模式已设置为: {mode}")
return result
@staticmethod
def is_standalone():
"""
检查是否为单机模式
Returns:
bool: True表示单机模式False表示接口模式
"""
config_loader = ConfigLoader.get_instance()
return config_loader.is_standalone_mode()
@staticmethod
def is_api():
"""
检查是否为接口模式
Returns:
bool: True表示接口模式False表示单机模式
"""
config_loader = ConfigLoader.get_instance()
return config_loader.is_api_mode()