#!/usr/bin/python\r
# coding: utf-8\r
-# 1\ 解析命令 python main.py -d [DIR] -o [OUT_DIR]\r
-# 2\ 循环执行svg解析写入\r
import sys\r
import os\r
import argparse\r
from converter import DialConvertTool\r
+import time\r
\r
def GetParameters():\r
parser = argparse.ArgumentParser()\r
config = parser.parse_args()\r
return config\r
\r
-if __name__ == "__main__":\r
+def main():\r
+ # 使用 time.time() 获取 Unix 时间戳(秒)\r
+ start_unix_time = time.time()\r
+ start_perf_time = time.perf_counter() # 用于计算精确耗时\r
+ \r
+ print(f"=== 转换开始 ===")\r
+ # 使用 gmtime() 避免时区问题\r
+ print(f"开始时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(start_unix_time))} UTC")\r
+\r
userInput = GetParameters()\r
outputPath = userInput.output\r
inputFile = userInput.file\r
inputDir = userInput.dir\r
- # Create an output folder.\r
- print("output dir : " + outputPath)\r
+\r
+ # 创建输出文件夹\r
+ print(f"输出目录:{outputPath}")\r
if not os.path.exists(outputPath):\r
- os.mkdir(outputPath)\r
+ os.makedirs(outputPath, exist_ok=True) # 使用 makedirs 确保多级目录创建\r
\r
- if not os.path.isdir(inputFile) and inputFile[-3:].lower() == "xml":\r
- print("input file : " + inputFile)\r
+ # 处理单个文件\r
+ if inputFile and not os.path.isdir(inputFile) and inputFile.lower().endswith(".xml"):\r
+ print(f"处理文件:{inputFile}")\r
converter = DialConvertTool()\r
converter.convert_xml_to_output(inputFile, outputPath)\r
\r
- files = os.listdir(inputDir)\r
- print("input dir : " + inputDir)\r
- for file in files:\r
- if not os.path.isdir(file) and file[-3:].lower() == "xml":\r
- converter = DialConvertTool()\r
- converter.convert_xml_to_output(inputDir + "/" + file, outputPath)
\ No newline at end of file
+ # 处理目录下的所有文件\r
+ if inputDir:\r
+ print(f"处理目录:{inputDir}")\r
+ try:\r
+ files = os.listdir(inputDir)\r
+ for file in files:\r
+ file_path = os.path.join(inputDir, file)\r
+ if not os.path.isdir(file_path) and file.lower().endswith(".xml"):\r
+ print(f"处理文件:{file_path}")\r
+ converter = DialConvertTool()\r
+ converter.convert_xml_to_output(file_path, outputPath)\r
+ except Exception as e:\r
+ print(f"处理目录时出错:{str(e)}")\r
+\r
+ # 计算总耗时\r
+ end_perf_time = time.perf_counter()\r
+ total_duration = end_perf_time - start_perf_time\r
+ \r
+ end_unix_time = start_unix_time + total_duration # 推算结束时间戳\r
+ print("\n=== 转换完成 ===")\r
+ print(f"结束时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(end_unix_time))} UTC")\r
+ print(f"总耗时:{total_duration:.2f} 秒({total_duration*1000:.0f} 毫秒)")\r
+\r
+if __name__ == "__main__":\r
+ main()
\ No newline at end of file