feat: 代码格式化, 改进仪表盘, 新增多CSS支持

This commit is contained in:
2026-04-20 16:30:04 +08:00
parent 845a505ca1
commit 65fbdec0a9
43 changed files with 551 additions and 349 deletions
+38 -31
View File
@@ -23,7 +23,7 @@ ident, content, meaning, ...
, "Woof", "狗发出的声音"
```
转换后的 TOML:
转换后的 TOML:
```toml
[Fox]
content = "Fox"
@@ -65,6 +65,7 @@ meaning = "狗发出的声音"
- 如果 CSV 包含更多列,它们也会以相同方式转换为键值对
- 支持 `-r` 参数指定随机种子来打乱 section 顺序
"""
import csv
import sys
import os
@@ -72,10 +73,11 @@ import random
import argparse
from pathlib import Path
def csv_to_toml(csv_path, toml_path=None, random_seed=None):
"""
将CSV文件转换为TOML格式
Args:
csv_path (str): 输入CSV文件路径
toml_path (str): 输出TOML文件路径,默认为相同目录下同名文件
@@ -86,92 +88,97 @@ def csv_to_toml(csv_path, toml_path=None, random_seed=None):
if not csv_file.exists():
print(f"错误: CSV文件不存在 - {csv_path}")
sys.exit(1)
# 确定输出TOML文件路径
if toml_path is None:
toml_path = csv_file.with_suffix('.toml')
toml_path = csv_file.with_suffix(".toml")
else:
toml_path = Path(toml_path)
# 读取CSV文件
try:
with open(csv_file, 'r', encoding='utf-8') as f:
with open(csv_file, "r", encoding="utf-8") as f:
reader = csv.DictReader(f)
rows = list(reader)
except Exception as e:
print(f"错误: 无法读取CSV文件 - {e}")
sys.exit(1)
# 检查CSV文件是否有数据
if not rows:
print("错误: CSV文件为空或格式不正确")
sys.exit(1)
# 如果指定了随机种子,设置随机种子并打乱行顺序
if random_seed is not None:
random.seed(random_seed)
random.shuffle(rows)
print(f"提示: 使用随机种子 {random_seed} 打乱了 section 顺序")
# 生成TOML内容
toml_content = []
idx_counter = 1
for row in rows:
# 处理ident列,为空时生成自动标识符
ident = row.get('ident', '').strip()
ident = row.get("ident", "").strip()
if not ident:
ident = f"idx_{idx_counter}"
idx_counter += 1
# 添加section标题
toml_content.append(f"[{ident}]")
# 添加所有其他列作为键值对(排除ident列)
for key, value in row.items():
if key == 'ident':
if key == "ident":
continue
# 确保值存在且不为空
if value is not None and str(value).strip() != '':
if value is not None and str(value).strip() != "":
# 转义特殊字符并添加引号
escaped_value = str(value).replace('"', '\\"')
toml_content.append(f'"{key}" = "{escaped_value}"')
# section之间添加空行
toml_content.append("")
# 写入TOML文件
try:
with open(toml_path, 'w', encoding='utf-8') as f:
f.write('\n'.join(toml_content).strip())
with open(toml_path, "w", encoding="utf-8") as f:
f.write("\n".join(toml_content).strip())
print(f"成功: 已生成TOML文件 - {toml_path}")
except Exception as e:
print(f"错误: 无法写入TOML文件 - {e}")
sys.exit(1)
def main():
"""主函数"""
parser = argparse.ArgumentParser(
description='将CSV文件转换为TOML格式,支持随机打乱section顺序',
description="将CSV文件转换为TOML格式,支持随机打乱section顺序",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog='''
epilog="""
示例:
%(prog)s input.csv output.toml
%(prog)s input.csv # 自动生成input.toml
%(prog)s input.csv -r 42 # 使用种子42打乱顺序
%(prog)s input.csv -r 123 output.toml # 指定种子和输出路径
'''
""",
)
parser.add_argument('csv_path', help='输入的CSV文件路径')
parser.add_argument('toml_path', nargs='?', help='输出的TOML文件路径,默认为CSV同名文件')
parser.add_argument('-r', '--random-seed', type=int,
help='随机种子,用于打乱TOML section的顺序')
parser.add_argument("csv_path", help="输入的CSV文件路径")
parser.add_argument(
"toml_path", nargs="?", help="输出的TOML文件路径,默认为CSV同名文件"
)
parser.add_argument(
"-r", "--random-seed", type=int, help="随机种子,用于打乱TOML section的顺序"
)
args = parser.parse_args()
csv_to_toml(args.csv_path, args.toml_path, args.random_seed)
if __name__ == "__main__":
main()
main()
+11 -9
View File
@@ -3,6 +3,7 @@ import pickle
import readline
import sys
class DebugClient:
def __init__(self, port=5555):
self.context = zmq.Context()
@@ -12,7 +13,7 @@ class DebugClient:
print("输入Python代码并按回车执行, 输入 'exit' 退出")
print("可用变量: app, logger")
print("-" * 50)
def execute(self, code):
"""执行代码并返回结果"""
try:
@@ -21,7 +22,7 @@ class DebugClient:
return response
except Exception as e:
return f"连接错误: {e}"
def repl(self):
"""交互式REPL循环"""
self.execute('print("test")')
@@ -29,27 +30,28 @@ class DebugClient:
try:
# 获取用户输入
code = input(">>> ").strip()
if not code:
continue
if code.lower() in ['exit', 'quit']:
if code.lower() in ["exit", "quit"]:
print("退出调试客户端")
break
# 执行代码
result = self.execute(code)
print(f"结果: {result}\n")
except KeyboardInterrupt:
print("\n退出调试客户端")
break
except EOFError:
break
if __name__ == "__main__":
# 从命令行参数获取端口
port = int(sys.argv[1]) if len(sys.argv) > 1 else 5555
client = DebugClient(port)
client.repl()
client.repl()