This repository was archived by the owner on Feb 25, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
73 lines (60 loc) · 1.92 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import json
import datetime
import pytz
import hashlib
import sys
m = hashlib.md5()
class NothingChangedException(Exception):
pass
info = json.loads(open('manifest.json').read())
version = '.'.join([str(v) for v in info['header']['version']])
time = datetime.datetime.now(pytz.timezone('UTC')).strftime('%Y-%m-%d %H:%M:%S')
source = open('data/zh_CN.lang').read()
diff = open('data/zh_PC.diff.lang').read()
sweetwinter = open('data/sweetwinter/zh_CN.sweetwinter.lang').read()
sweetwinter_keys = open('data/sweetwinter/zh_CN.sweetwinter.txt').read().splitlines()
sign_str = (diff + sweetwinter + ''.join(sweetwinter_keys)).encode(encoding='utf-8')
m.update(sign_str)
sign = f'Sign: {m.hexdigest()}'
extra = [
sign,
'Github: https://github.com/PoiCraft/zhMC',
f'Version: {version}',
f'BuildAt: {time} UTC'
]
def loadLang(lang_str):
lang_map = {}
lang_list = lang_str.splitlines()
for lang_w in lang_list:
if len(lang_w) == 0:
continue
if (lang_w[0] == '#' or lang_w[0] == ' '):
continue
lang_d = lang_w.split('=')
if len(lang_d) < 2:
continue
if not '.' in lang_d[0]:
continue
lang_map[lang_d[0]] = lang_d[1]
return lang_map
def exportLang(lang_map):
lang_list=[]
for v in extra:
lang_list.append('#'+v)
for k in lang_map:
lang_list.append(k+'='+lang_map[k])
lang_str = '\n'.join(lang_list)
return lang_str
source_map = loadLang(source)
diff_map = loadLang(diff)
sweetwinter_map = loadLang(sweetwinter)
for k in diff_map:
print(k+':'+source_map[k]+' -> '+diff_map[k])
source_map[k]=diff_map[k]
for k in sweetwinter_keys:
print('Thank Coolapk@甜冬SweetWinter')
print(k+':'+source_map[k]+' -> '+sweetwinter_map[k])
source_map[k]=sweetwinter_map[k]
with open('texts/zh_PC.lang','w') as f:
f.write(exportLang(source_map))
f.close()