From a0882296d2af1079f82e97497e1574e2b558182e Mon Sep 17 00:00:00 2001 From: Jiting Date: Fri, 1 Feb 2019 15:07:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BF=9B=E5=BA=A6=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maker.py | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/maker.py b/maker.py index 21b1809..45f2d51 100644 --- a/maker.py +++ b/maker.py @@ -2,9 +2,11 @@ # -*- coding: utf-8 -*- import os +import re import sys import zipfile import subprocess +from urllib import request, parse from time import strftime, localtime target_version = "3.2.3" @@ -13,34 +15,57 @@ cwd = sys.path[0] src = f"{cwd + os.sep}src{os.sep}" dist = f"{cwd + os.sep}dist{os.sep}" ini = f"{dist}package.ini" +translated = re.compile(r"(?:Generated\s)(\d+)(?:\stranslation)") +untranslated = re.compile(r"(?:Ignored\s)(\d+)(?:\suntranslated)") def make_release(): if os.name == 'nt': lrelease = 'C:/Qt/Qt5.6.3/5.6.3/msvc2015_64/bin/lrelease.exe' # On my laptop. 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 f[-5:-3] == language] release_file = [] + translated_count = 0 + total_count = 0 + for i in source_file: print(i) result = subprocess.run([lrelease, f'{src+i}.ts', '-qm', f'{dist+i}.qm'], 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: 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: print(result.stderr.decode("utf-8")) - #except subprocess.CalledProcessError as err: + # except subprocess.CalledProcessError as err: # print("lrelease error:") # print(err)''' + send_progress(translated_count, total_count) 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): timestamp = strftime("%Y%m%d%H%M%S", localtime()) print("Write package info to package.ini ...") @@ -48,9 +73,9 @@ def make_package(release_list): package_info = [f"Name = TeamSpeak 3 简体中文汉化包 软件版本:{target_version}", "Type = Translation", "Author = 寂听", - f"Version = Beta-{timestamp}", + f"Version = {timestamp}", "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)) file_name = 'Chinese_Translation_zh-CN.ts3_translation'