-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·52 lines (45 loc) · 1.26 KB
/
build.py
File metadata and controls
executable file
·52 lines (45 loc) · 1.26 KB
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, zipfile
def translateUnicode(s):
u = s.decode('utf-8')
if len(u) == len(s):
return s
ret = u''
for ch in u:
ascii = ord(ch)
if ascii > 0x7f:
ret += hex(ascii).replace('0x', '\\u')
else:
ret += ch
return ret.encode('utf-8')
def processPropertiesFile(path):
f = open(path, 'r')
assert f
ret = ''
for line in f.readlines():
ret += translateUnicode(line) + '\n'
f.close()
return ret
def processFile(zip, path_in_zip, path_in_os):
name, ext = os.path.splitext(path_in_os)
if ext == '.properties':
zip.writestr(path_in_zip, processPropertiesFile(path_in_os))
else:
zip.write(path_in_os, path_in_zip)
def processDir(zip, parent_path_in_zip, path_in_fs):
for filename in os.listdir(path_in_fs):
if os.path.isdir(path_in_fs + '/' + filename):
processDir(zip, parent_path_in_zip + filename + '/', path_in_fs + '/' + filename)
else:
name, ext = os.path.splitext(filename)
processFile(zip, parent_path_in_zip + name + '_zh_CN' + ext, path_in_fs + '/' + filename)
def main():
if not os.path.exists('out'):
os.mkdir('out')
zip = zipfile.ZipFile('out/resources_zh_CN.jar', 'w', zipfile.ZIP_STORED)
assert zip
processDir(zip, '', 'resources')
zip.close()
if __name__ == "__main__":
main()