mirror of
https://github.com/VigorousPro/TS3-Translation_zh-CN
synced 2025-01-31 02:02:47 +08:00
添加进度推送通知
This commit is contained in:
parent
d08acba6f8
commit
a0882296d2
37
maker.py
37
maker.py
@ -2,9 +2,11 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import zipfile
|
import zipfile
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from urllib import request, parse
|
||||||
from time import strftime, localtime
|
from time import strftime, localtime
|
||||||
|
|
||||||
target_version = "3.2.3"
|
target_version = "3.2.3"
|
||||||
@ -13,34 +15,57 @@ cwd = sys.path[0]
|
|||||||
src = f"{cwd + os.sep}src{os.sep}"
|
src = f"{cwd + os.sep}src{os.sep}"
|
||||||
dist = f"{cwd + os.sep}dist{os.sep}"
|
dist = f"{cwd + os.sep}dist{os.sep}"
|
||||||
ini = f"{dist}package.ini"
|
ini = f"{dist}package.ini"
|
||||||
|
translated = re.compile(r"(?:Generated\s)(\d+)(?:\stranslation)")
|
||||||
|
untranslated = re.compile(r"(?:Ignored\s)(\d+)(?:\suntranslated)")
|
||||||
|
|
||||||
|
|
||||||
def make_release():
|
def make_release():
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
lrelease = 'C:/Qt/Qt5.6.3/5.6.3/msvc2015_64/bin/lrelease.exe' # On my laptop.
|
lrelease = 'C:/Qt/Qt5.6.3/5.6.3/msvc2015_64/bin/lrelease.exe' # On my laptop.
|
||||||
else: # os.name == 'posix'
|
else: # os.name == 'posix'
|
||||||
# result = subprocess.run(['whereis', 'lrelease', '-b'], stdout=subprocess.PIPE).stdout.decode("utf-8")
|
lrelease = 'lrelease'
|
||||||
lrelease = 'lrelease'
|
|
||||||
# source_file = [f[:-3] for f in os.listdir(src) if os.path.isfile(os.path.join(src, f)) and f[-5:-3] == language]
|
# source_file = [f[:-3] for f in os.listdir(src) if os.path.isfile(os.path.join(src, f)) and f[-5:-3] == language]
|
||||||
source_file = [f[:-3] for f in os.listdir(src) if f[-5:-3] == language]
|
source_file = [f[:-3] for f in os.listdir(src) if f[-5:-3] == language]
|
||||||
release_file = []
|
release_file = []
|
||||||
|
translated_count = 0
|
||||||
|
total_count = 0
|
||||||
|
|
||||||
for i in source_file:
|
for i in source_file:
|
||||||
print(i)
|
print(i)
|
||||||
result = subprocess.run([lrelease, f'{src+i}.ts', '-qm', f'{dist+i}.qm'],
|
result = subprocess.run([lrelease, f'{src+i}.ts', '-qm', f'{dist+i}.qm'],
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
print(result.stdout.decode("utf-8"))
|
result_info = result.stdout.decode("utf-8")
|
||||||
|
print(result_info)
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
release_file.append(i+".qm")
|
release_file.append(i+".qm")
|
||||||
|
if i != "qt_zh":
|
||||||
|
translated_count += int(translated.findall(result_info)[0])
|
||||||
|
total_count += int(translated.findall(result_info)[0])
|
||||||
|
untranslated_count = untranslated.findall(result_info)
|
||||||
|
total_count += int(untranslated_count[0]) if len(untranslated_count) != 0 else 0
|
||||||
else:
|
else:
|
||||||
print(result.stderr.decode("utf-8"))
|
print(result.stderr.decode("utf-8"))
|
||||||
|
|
||||||
#except subprocess.CalledProcessError as err:
|
# except subprocess.CalledProcessError as err:
|
||||||
# print("lrelease error:")
|
# print("lrelease error:")
|
||||||
# print(err)'''
|
# print(err)'''
|
||||||
|
send_progress(translated_count, total_count)
|
||||||
|
|
||||||
return release_file
|
return release_file
|
||||||
|
|
||||||
|
|
||||||
|
def send_progress(done, total):
|
||||||
|
tg_api = os.getenv('TG_API')
|
||||||
|
group_id = os.getenv('TG_GROUP_ID')
|
||||||
|
url = f"https://api.telegram.org/bot{tg_api}/sendMessage?chat_id={group_id}&"
|
||||||
|
percentage = round(done*100/total, 2)
|
||||||
|
output = f"当前进度:\n{done}/{total}\n{percentage}%".encode("utf-8")
|
||||||
|
querystring = parse.urlencode({"text": output})
|
||||||
|
request.urlopen(url + querystring)
|
||||||
|
print(output.decode("utf-8"))
|
||||||
|
print("进度消息推送完毕\n")
|
||||||
|
|
||||||
|
|
||||||
def make_package(release_list):
|
def make_package(release_list):
|
||||||
timestamp = strftime("%Y%m%d%H%M%S", localtime())
|
timestamp = strftime("%Y%m%d%H%M%S", localtime())
|
||||||
print("Write package info to package.ini ...")
|
print("Write package info to package.ini ...")
|
||||||
@ -48,9 +73,9 @@ def make_package(release_list):
|
|||||||
package_info = [f"Name = TeamSpeak 3 简体中文汉化包 软件版本:{target_version}",
|
package_info = [f"Name = TeamSpeak 3 简体中文汉化包 软件版本:{target_version}",
|
||||||
"Type = Translation",
|
"Type = Translation",
|
||||||
"Author = 寂听",
|
"Author = 寂听",
|
||||||
f"Version = Beta-{timestamp}",
|
f"Version = {timestamp}",
|
||||||
"Platforms = ",
|
"Platforms = ",
|
||||||
'Description = Source Code: https://github.com/jitingcn/TS3-Translation_zh-CN']
|
'Description = 源代码: https://github.com/jitingcn/TS3-Translation_zh-CN']
|
||||||
f.write("\n".join(package_info))
|
f.write("\n".join(package_info))
|
||||||
|
|
||||||
file_name = 'Chinese_Translation_zh-CN.ts3_translation'
|
file_name = 'Chinese_Translation_zh-CN.ts3_translation'
|
||||||
|
Loading…
Reference in New Issue
Block a user