scummvm/backends/vkeybd/packs/vkeybdpack.py

64 lines
1.5 KiB
Python
Raw Normal View History

2009-10-04 10:31:37 +00:00
#!/usr/bin/env python
# encoding: utf-8
import sys
import re
import os
import zipfile
try:
import zlib
compression = zipfile.ZIP_DEFLATED
except:
compression = zipfile.ZIP_STORED
PACK_FILE_EXTENSIONS = ('.xml', '.bmp')
def buildPack(packName):
if not os.path.isdir(packName):
print ("Invalid pack name: " + packName)
return
2011-04-14 12:41:26 +02:00
2009-10-04 10:31:37 +00:00
zf = zipfile.ZipFile(packName + ".zip", 'w')
2011-04-14 12:41:26 +02:00
2009-10-04 10:31:37 +00:00
zf.compress_type = zipfile.ZIP_DEFLATED
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, compress_type=compression)
print (" Adding file: " + filename)
2011-04-14 12:41:26 +02:00
2009-10-04 10:31:37 +00:00
os.chdir('../')
2011-04-14 12:41:26 +02:00
2009-10-04 10:31:37 +00:00
zf.close()
def buildAllPacks():
for f in os.listdir('.'):
if os.path.isdir(os.path.join('.', f)) and not f[0] == '.':
buildPack(f)
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():
2011-04-14 12:41:26 +02:00
2009-10-04 10:31:37 +00:00
if len(sys.argv) == 2 and sys.argv[1] == "makeall":
buildAllPacks()
2011-04-14 12:41:26 +02:00
2009-10-04 10:31:37 +00:00
elif len(sys.argv) == 3 and sys.argv[1] == "make":
buildPack(sys.argv[2])
2011-04-14 12:41:26 +02:00
2009-10-04 10:31:37 +00:00
else:
printUsage()
if __name__ == "__main__":
sys.exit(main())