update build script

This commit is contained in:
Jiting 2019-02-09 20:49:43 +08:00
parent a0d49a6832
commit 031ac4cc41
No known key found for this signature in database
GPG Key ID: B68ED772995769D6
2 changed files with 29 additions and 12 deletions

View File

@ -13,7 +13,6 @@ branches:
before_install: before_install:
- export TZ=Asia/Shanghai - export TZ=Asia/Shanghai
- mkdir dist -p
- sudo apt-get update -q - sudo apt-get update -q
install: install:

View File

@ -15,62 +15,80 @@ 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)") translated = re.compile(r"(?:Generated\s)(\d+)(?: translation)")
untranslated = re.compile(r"(?:Ignored\s)(\d+)(?:\suntranslated)") untranslated = re.compile(r"(?:Ignored\s)(\d+)(?: untranslated)")
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'
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]
if len(source_file) == 0:
print("Input file not found. Exit.")
release_file = [] release_file = []
translated_count = 0 translated_count = 0
total_count = 0 total_count = 0
if not os.path.exists(dist):
print("Warning: \"dist\" folder not found. Creating folder...\n")
os.makedirs(dist)
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)
try:
result_info = result.stdout.decode("utf-8") result_info = result.stdout.decode("utf-8")
except UnicodeDecodeError:
result_info = result.stdout.decode("gbk") # 中文系统可能会遇到编码问题
print(result_info) print(result_info)
if result.returncode == 0: if result.returncode == 0:
release_file.append(i+".qm") release_file.append(f"{i}.qm")
if i != "qt_zh": if i != "qt_zh":
translated_count += int(translated.findall(result_info)[0]) translated_count += int(translated.findall(result_info)[0])
total_count += int(translated.findall(result_info)[0]) total_count += int(translated.findall(result_info)[0])
untranslated_count = untranslated.findall(result_info) untranslated_count = untranslated.findall(result_info)
total_count += int(untranslated_count[0]) if len(untranslated_count) != 0 else 0 total_count += int(untranslated_count[0]) if len(untranslated_count) != 0 else 0
else: else:
try:
print(result.stderr.decode("utf-8")) print(result.stderr.decode("utf-8"))
except UnicodeDecodeError:
print(result.stderr.decode("gbk")) # 中文系统可能会遇到编码问题
# 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) send_progress(translated_count, total_count)
return release_file return release_file
def send_progress(done, total): def send_progress(done, total):
percentage = round(done*100/total, 2) percentage = round(done*100/total, 2)
output = f"当前进度:\n{done}/{total}\n{percentage}%" output = f"当前进度:\n{done}/{total}\n{percentage}%\n"
print(output) print(output)
try: try:
telegram_push(output) assert 0 == telegram_push(output)
print("\n推送完毕\n") print("推送成功\n")
except AssertionError:
print("推送被取消\n")
except Exception as err: except Exception as err:
print(f"\n{err}\n推送失败\n") print(f"发生错误,推送失败\n错误信息:{err}\n")
def telegram_push(string): def telegram_push(string):
querystring = parse.urlencode({"text": string.encode('utf-8')}) querystring = parse.urlencode({"text": string.encode('utf-8')})
tg_api = os.getenv('TG_API') tg_api = os.getenv('TG_API')
group_id = os.getenv('TG_GROUP_ID') group_id = os.getenv('TG_GROUP_ID')
if tg_api == "" or group_id == "":
print("未检测到Telegram Api Key或Group ID")
print("需要在环境变量中设置api key和Group ID")
return 1
url = f"https://api.telegram.org/bot{tg_api}/sendMessage?chat_id={group_id}&" url = f"https://api.telegram.org/bot{tg_api}/sendMessage?chat_id={group_id}&"
request.urlopen(url + querystring) request.urlopen(url + querystring)
return 0
def make_package(release_list): def make_package(release_list):