This repository has been archived on 2025-02-28. You can view files and clone it, but cannot push or open issues or pull requests.
controller-hd/Tests/version.py

42 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
import re
import os
import sys
# 设置控制台编码为 UTF-8
sys.stdout.reconfigure(encoding='utf-8')
# 获取当前脚本所在目录
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建entity.h文件的绝对路径
file_path = os.path.join(current_dir, '../User/entity.h')
# 打开并读取文件内容
try:
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
# 读取调试模式
debug_enable_match = re.search(r'#define DEBUG_ENABLE (TRUE|FALSE)', content)
# 使用正则表达式匹配并提取版本号
dw_ver_match = re.search(r'#define DW_VER (\d+)', content)
hw_ver_match = re.search(r'#define HW_VER (\d+)', content)
sw_ver_match = re.search(r'#define SW_VER (\d+)', content)
# 提取调试模式
debug_enable = debug_enable_match.group(1) if debug_enable_match else 'N/A'
# 提取版本号
dw_ver = dw_ver_match.group(1) if dw_ver_match else 'N/A'
hw_ver = hw_ver_match.group(1) if hw_ver_match else 'N/A'
sw_ver = sw_ver_match.group(1) if sw_ver_match else 'N/A'
version_info_path = os.path.join(current_dir, 'version.txt')
# 将版本号写入文件
with open(version_info_path, 'w', encoding='utf-8') as version_file:
version_file.write(f'VERSION=v{dw_ver}.{hw_ver}.{sw_ver}\n')
version_file.write(f'DEBUG_ENABLE={debug_enable}\n')
print(f"version: {dw_ver}.{hw_ver}.{sw_ver}")
print(f"debug: {debug_enable}")
except FileNotFoundError:
print(f"file not find: {file_path}")