feat: 支持使用命令行调用
This commit is contained in:
@@ -27,6 +27,7 @@ v4.3
|
||||
|
||||
from loguru import logger
|
||||
from PySide6.QtCore import Signal
|
||||
import argparse
|
||||
import sqlite3
|
||||
import json
|
||||
import sys
|
||||
@@ -614,6 +615,27 @@ class AppConfig(GlobalConfig):
|
||||
self.if_ignore_silence = False
|
||||
self.if_database_opened = False
|
||||
|
||||
self.search_member()
|
||||
self.search_queue()
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="AUTO_MAA",
|
||||
description="A MAA Multi Account Management and Automation Tool",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--mode",
|
||||
choices=["gui", "cli"],
|
||||
default="gui",
|
||||
help="使用UI界面或命令行模式运行程序",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--config",
|
||||
nargs="+",
|
||||
choices=list(self.member_dict.keys()) + list(self.queue_dict.keys()),
|
||||
help="指定需要运行哪些配置项",
|
||||
)
|
||||
self.args = parser.parse_args()
|
||||
|
||||
self.initialize()
|
||||
|
||||
def initialize(self) -> None:
|
||||
@@ -636,7 +658,8 @@ class AppConfig(GlobalConfig):
|
||||
def init_logger(self) -> None:
|
||||
"""初始化日志记录器"""
|
||||
|
||||
logger.remove(0)
|
||||
if self.args.mode != "cli":
|
||||
logger.remove(0)
|
||||
|
||||
logger.add(
|
||||
sink=self.log_path,
|
||||
@@ -649,10 +672,14 @@ class AppConfig(GlobalConfig):
|
||||
retention="1 month",
|
||||
compression="zip",
|
||||
)
|
||||
logger.info("")
|
||||
logger.info("===================================")
|
||||
logger.info("AUTO_MAA 主程序")
|
||||
logger.info(f"版本号: v{self.VERSION}")
|
||||
logger.info(f"根目录: {self.app_path}")
|
||||
logger.info(
|
||||
f"运行模式: {'图形化界面' if self.args.mode == 'gui' else '命令行界面'}"
|
||||
)
|
||||
logger.info("===================================")
|
||||
|
||||
logger.info("日志记录器初始化完成")
|
||||
|
||||
@@ -283,6 +283,9 @@ class _TaskManager(QObject):
|
||||
)
|
||||
)
|
||||
|
||||
if Config.args.mode == "cli" and Config.power_sign == "NoAction":
|
||||
Config.set_power_sign("KillSelf")
|
||||
|
||||
def check_maa_version(self, v: str):
|
||||
"""检查MAA版本"""
|
||||
|
||||
|
||||
@@ -112,6 +112,7 @@ class _SystemHandler:
|
||||
|
||||
Config.main_window.close()
|
||||
QApplication.quit()
|
||||
sys.exit(0)
|
||||
|
||||
elif sys.platform.startswith("linux"):
|
||||
|
||||
@@ -138,6 +139,7 @@ class _SystemHandler:
|
||||
|
||||
Config.main_window.close()
|
||||
QApplication.quit()
|
||||
sys.exit(0)
|
||||
|
||||
def is_startup(self) -> bool:
|
||||
"""判断程序是否已经开机自启"""
|
||||
|
||||
@@ -162,7 +162,7 @@ class ProgressRingMessageBox(MessageBoxBase):
|
||||
super().__init__(parent)
|
||||
self.title = SubtitleLabel(title)
|
||||
|
||||
self.time = 100
|
||||
self.time = 100 if Config.args.mode == "gui" else 1
|
||||
Widget = QWidget()
|
||||
Layout = QHBoxLayout(Widget)
|
||||
self.ring = ProgressRing()
|
||||
|
||||
@@ -257,6 +257,9 @@ class AUTO_MAA(MSFluentWindow):
|
||||
) -> None:
|
||||
"""配置窗口状态"""
|
||||
|
||||
if Config.args.mode != "gui":
|
||||
return None
|
||||
|
||||
self.switch_theme()
|
||||
|
||||
if mode == "显示主窗口":
|
||||
@@ -379,6 +382,41 @@ class AUTO_MAA(MSFluentWindow):
|
||||
|
||||
self.titleBar.minBtn.click()
|
||||
|
||||
if Config.args.config:
|
||||
|
||||
for config in [_ for _ in Config.args.config if _ in Config.queue_dict]:
|
||||
|
||||
TaskManager.add_task(
|
||||
"自动代理_新调度台",
|
||||
config,
|
||||
Config.queue_dict["调度队列_1"]["Config"].toDict(),
|
||||
)
|
||||
|
||||
for config in [_ for _ in Config.args.config if _ in Config.member_dict]:
|
||||
|
||||
TaskManager.add_task(
|
||||
"自动代理_新调度台",
|
||||
"自定义队列",
|
||||
{"Queue": {"Member_1": config}},
|
||||
)
|
||||
|
||||
if not any(
|
||||
_ in (list(Config.member_dict.keys()) + list(Config.queue_dict.keys()))
|
||||
for _ in Config.args.config
|
||||
):
|
||||
|
||||
logger.warning(
|
||||
"当前运行模式为命令行模式,由于您使用了错误的 --config 参数进行配置,程序自动退出"
|
||||
)
|
||||
System.set_power("KillSelf")
|
||||
|
||||
elif Config.args.mode == "cli":
|
||||
|
||||
logger.warning(
|
||||
"当前运行模式为命令行模式,由于您未使用 --config 参数进行配置,程序自动退出"
|
||||
)
|
||||
System.set_power("KillSelf")
|
||||
|
||||
def clean_old_logs(self):
|
||||
"""
|
||||
删除超过用户设定天数的日志文件(基于目录日期)
|
||||
|
||||
@@ -561,12 +561,7 @@ class Setting(QWidget):
|
||||
8. AUTO_MAA 没有实时合成语音的能力,软件所有语音都存储在本地。如果听到本地不存在的语音,立即关闭扬声器,并检查是否有未知脚本在运行。
|
||||
9. AUTO_MAA 不会在周六凌晨更新。如果收到更新提示,请忽略,不要查看更新内容,直到第二天天亮。
|
||||
10. 用户守则仅有一页""",
|
||||
"--- 标记文档中止 ---": """
|
||||
xdfv-serfcx-jiol,m: !1 $bad food of do $5b 9630-300 $daad 100-1
|
||||
|
||||
// 0 == o //
|
||||
|
||||
∠( °ω°)/ """,
|
||||
"--- 标记文档中止 ---": "xdfv-serfcx-jiol,m: !1 $bad food of do $5b 9630-300 $daad 100-1\n\n// 0 == o //\n\n∠( °ω°)/",
|
||||
},
|
||||
)
|
||||
cc.button_cancel.hide()
|
||||
|
||||
@@ -71,7 +71,7 @@ if __name__ == "__main__":
|
||||
|
||||
os.system(
|
||||
"powershell -Command python -m nuitka --standalone --onefile --mingw64"
|
||||
" --enable-plugins=pyside6 --windows-console-mode=disable"
|
||||
" --enable-plugins=pyside6 --windows-console-mode=attach"
|
||||
" --onefile-tempdir-spec='{TEMP}\\AUTO_MAA'"
|
||||
" --windows-icon-from-ico=resources\\icons\\AUTO_MAA.ico"
|
||||
" --company-name='AUTO_MAA Team' --product-name=AUTO_MAA"
|
||||
|
||||
Reference in New Issue
Block a user