From: Caisking Date: Thu, 5 Jun 2025 02:34:18 +0000 (+0800) Subject: 优化表盘工具增加时间戳打印 X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~261^2~6 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=2269f906f3b860c420329cc37563d90360143283;p=mirrors%2FFD230.git 优化表盘工具增加时间戳打印 --- diff --git a/tools/dial_converter_tool/main.py b/tools/dial_converter_tool/main.py index cc57403c5..53bdc8629 100644 --- a/tools/dial_converter_tool/main.py +++ b/tools/dial_converter_tool/main.py @@ -1,11 +1,10 @@ #!/usr/bin/python # coding: utf-8 -# 1\ 解析命令 python main.py -d [DIR] -o [OUT_DIR] -# 2\ 循环执行svg解析写入 import sys import os import argparse from converter import DialConvertTool +import time def GetParameters(): parser = argparse.ArgumentParser() @@ -22,24 +21,53 @@ def GetParameters(): config = parser.parse_args() return config -if __name__ == "__main__": +def main(): + # 使用 time.time() 获取 Unix 时间戳(秒) + start_unix_time = time.time() + start_perf_time = time.perf_counter() # 用于计算精确耗时 + + print(f"=== 转换开始 ===") + # 使用 gmtime() 避免时区问题 + print(f"开始时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(start_unix_time))} UTC") + userInput = GetParameters() outputPath = userInput.output inputFile = userInput.file inputDir = userInput.dir - # Create an output folder. - print("output dir : " + outputPath) + + # 创建输出文件夹 + print(f"输出目录:{outputPath}") if not os.path.exists(outputPath): - os.mkdir(outputPath) + os.makedirs(outputPath, exist_ok=True) # 使用 makedirs 确保多级目录创建 - if not os.path.isdir(inputFile) and inputFile[-3:].lower() == "xml": - print("input file : " + inputFile) + # 处理单个文件 + if inputFile and not os.path.isdir(inputFile) and inputFile.lower().endswith(".xml"): + print(f"处理文件:{inputFile}") converter = DialConvertTool() converter.convert_xml_to_output(inputFile, outputPath) - files = os.listdir(inputDir) - print("input dir : " + inputDir) - for file in files: - if not os.path.isdir(file) and file[-3:].lower() == "xml": - converter = DialConvertTool() - converter.convert_xml_to_output(inputDir + "/" + file, outputPath) \ No newline at end of file + # 处理目录下的所有文件 + if inputDir: + print(f"处理目录:{inputDir}") + try: + files = os.listdir(inputDir) + for file in files: + file_path = os.path.join(inputDir, file) + if not os.path.isdir(file_path) and file.lower().endswith(".xml"): + print(f"处理文件:{file_path}") + converter = DialConvertTool() + converter.convert_xml_to_output(file_path, outputPath) + except Exception as e: + print(f"处理目录时出错:{str(e)}") + + # 计算总耗时 + end_perf_time = time.perf_counter() + total_duration = end_perf_time - start_perf_time + + end_unix_time = start_unix_time + total_duration # 推算结束时间戳 + print("\n=== 转换完成 ===") + print(f"结束时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(end_unix_time))} UTC") + print(f"总耗时:{total_duration:.2f} 秒({total_duration*1000:.0f} 毫秒)") + +if __name__ == "__main__": + main() \ No newline at end of file