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
73
|
#!/usr/bin/env python
# encoding: utf-8
import sys
import re
import os
import zipfile
PACK_FILE_EXTENSIONS = ('.xml', '.bmp')
def buildPack(packName):
if not os.path.isdir(packName):
print ("Invalid pack name: " + packName)
return
zf = zipfile.ZipFile(packName + ".zip", 'w')
print ("Building '" + packName + "' pack:")
os.chdir(packName)
for filename in os.listdir('.'):
if os.path.isfile(filename) and not filename[0] == '.' and filename.endswith(PACK_FILE_EXTENSIONS):
zf.write(filename, './' + filename)
print (" Adding file: " + filename)
os.chdir('../')
zf.close()
def buildAllPacks():
for f in os.listdir('.'):
if os.path.isdir(os.path.join('.', f)) and not f[0] == '.':
buildPack(f)
def parseSTX(pack_file, def_file):
comm = re.compile("<!--(.*?)-->", re.DOTALL)
head = re.compile("<\?(.*?)\?>")
output = ""
for line in pack_file:
output += line.rstrip("\r\n\t ").lstrip() + " \n"
output = re.sub(comm, "", output)
output = re.sub(head, "", output)
output = output.replace("\t", " ").replace(" ", " ").replace("\"", "'")
output = output.replace(" = ", "=").replace(", ", ",")
for line in output.splitlines():
if line and not line.isspace():
def_file.write("\"" + line + "\"\n")
def printUsage():
print ("===============================================")
print ("ScummVM Virtual Keyboard Pack Generation Script")
print ("===============================================")
print ("Usage:")
print ("vkeybdpack.py makeall")
print (" Builds all the available pack.\n")
print ("vkeybdpack.py make [packname]")
print (" Builds the pack called 'packname'.\n")
def main():
if len(sys.argv) == 2 and sys.argv[1] == "makeall":
buildAllPacks()
elif len(sys.argv) == 3 and sys.argv[1] == "make":
buildPack(sys.argv[2])
else:
printUsage()
if __name__ == "__main__":
sys.exit(main())
|