64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""OneBot rebrand helper: logo 生成 + 语言文件品牌名替换"""
|
||
import base64
|
||
import re
|
||
import glob
|
||
import os
|
||
import shutil
|
||
|
||
root = r"d:\开发\leantime-master\leantime-master"
|
||
img_dir = os.path.join(root, "public", "assets", "images")
|
||
bt = os.path.join(root, "bt.png")
|
||
|
||
# 1. 生成内嵌 bt.png 的 logo.svg / logo_blue.svg(保持现有 .svg 引用不变,最小改动)
|
||
with open(bt, "rb") as f:
|
||
b64 = base64.b64encode(f.read()).decode()
|
||
|
||
svg = ('<svg xmlns="http://www.w3.org/2000/svg" width="108" height="98" '
|
||
'viewBox="0 0 108 98"><image width="108" height="98" '
|
||
'href="data:image/png;base64,{}"/></svg>').format(b64)
|
||
|
||
for name in ("logo.svg", "logo_blue.svg"):
|
||
with open(os.path.join(img_dir, name), "w", encoding="utf-8") as f:
|
||
f.write(svg)
|
||
|
||
# printLogoURL 指向 logo.jpg(原本缺失),复制 bt.png 补齐
|
||
shutil.copyfile(bt, os.path.join(img_dir, "logo.jpg"))
|
||
|
||
# 2. 语言文件:仅替换 value 中的 Leantime/leantime,保留翻译 key 与 *.leantime.io 域名
|
||
def repl(m):
|
||
s = m.group(0)
|
||
return "OneBot" if s[0].isupper() else "onebot"
|
||
|
||
# 匹配 Leantime(不区分大小写),排除后面紧跟 .io(域名)或字母(更大单词)
|
||
pat = re.compile(r"(?i)leantime(?!(\.io|[a-z]))")
|
||
|
||
changed_files = 0
|
||
changed_lines = 0
|
||
for ini in glob.glob(os.path.join(root, "app", "Language", "*.ini")):
|
||
with open(ini, "r", encoding="utf-8") as f:
|
||
lines = f.readlines()
|
||
out = []
|
||
file_changed = False
|
||
for line in lines:
|
||
if line.lstrip().startswith(("#", ";")):
|
||
out.append(line)
|
||
continue
|
||
if "=" not in line:
|
||
out.append(line)
|
||
continue
|
||
idx = line.index("=")
|
||
key, val = line[:idx], line[idx:]
|
||
new_val, n = pat.subn(repl, val)
|
||
if n:
|
||
file_changed = True
|
||
changed_lines += n
|
||
out.append(key + new_val)
|
||
if file_changed:
|
||
with open(ini, "w", encoding="utf-8") as f:
|
||
f.writelines(out)
|
||
changed_files += 1
|
||
|
||
print("logo.svg/logo_blue.svg/logo.jpg written")
|
||
print("language files changed:", changed_files, "| line replacements:", changed_lines)
|