auto_build_launcher/main.py

55 lines
1.7 KiB
Python

import os
import argparse
import sys
from scripts.build import run
from scripts.context import Context
from utils import SystemUtils
from utils.logger_utils import init
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='构建脚本')
parser.add_argument('--config', type=str, help='配置文件', default='build_config.json')
args = parser.parse_args()
config_path = args.config
if not config_path.endswith('.json'):
config_path += '.json'
print(config_path)
if not os.path.exists(config_path):
print(f"输入的配置文件不存在 {config_path}")
sys.exit(0)
context = Context.from_json(open(config_path, "r", encoding="UTF-8").read())
if SystemUtils.is_windows():
context.project_original_path = context.project_original_path.replace("/", os.sep)
pass
logger = init()
run(context)
# # 系统信息示例
# print(f"当前系统: {SystemUtils.get_platform_name()}")
# print(f"是Windows系统吗? {SystemUtils.is_windows()}")
#
# # 命令执行示例
# if SystemUtils.is_windows():
# cmd = "echo Hello Windows"
# else:
# cmd = "echo 'Hello Unix/Linux/macOS'"
#
# # 执行并获取输出
# return_code, output, error = CommandUtils.execute(cmd)
# print(f"\n命令执行结果:")
# print(f"返回码: {return_code}")
# print(f"输出: {output.strip()}")
# if error:
# print(f"错误: {error}")
#
# # 实时输出示例
# print("\n实时输出示例:")
# CommandUtils.execute_with_real_time_output(
# "ping -c 4 127.0.0.1" if not SystemUtils.is_windows() else "ping -n 4 127.0.0.1")