ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

scummtheme.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # encoding: utf-8
00003 import sys
00004 import re
00005 import os
00006 import zipfile
00007 
00008 THEME_FILE_EXTENSIONS = ('.stx', '.bmp', '.fcc', '.ttf', '.png')
00009 
00010 def buildTheme(themeName):
00011     if not os.path.isdir(themeName) or not os.path.isfile(os.path.join(themeName, "THEMERC")):
00012         print ("Invalid theme name: " + themeName)
00013         return
00014 
00015     zf = zipfile.ZipFile(themeName + ".zip", 'w')
00016 
00017     print ("Building '" + themeName + "' theme:")
00018     os.chdir(themeName)
00019 
00020     zf.write('THEMERC', './THEMERC')
00021 
00022     filenames = os.listdir('.')
00023     filenames.sort()
00024     for filename in filenames:
00025         if os.path.isfile(filename) and not filename[0] == '.' and filename.endswith(THEME_FILE_EXTENSIONS):
00026             zf.write(filename, './' + filename)
00027             print ("    Adding file: " + filename)
00028 
00029     os.chdir('../')
00030 
00031     zf.close()
00032 
00033 def buildAllThemes():
00034     for f in os.listdir('.'):
00035         if os.path.isdir(os.path.join('.', f)) and not f[0] == '.':
00036             buildTheme(f)
00037 
00038 def parseSTX(theme_file, def_file, subcount):
00039     comm = re.compile("<!--(.*?)-->", re.DOTALL)
00040     head = re.compile("<\?(.*?)\?>")
00041 
00042     strlitcount = 0
00043     subcount += 1
00044 
00045     def_file.write(";\n const char *defaultXML" + str(subcount) + " = ")
00046 
00047     output = ""
00048     for line in theme_file:
00049         output +=  line.rstrip("\r\n\t ").lstrip()
00050         if not output.endswith('>'):
00051             output += ' '
00052         output += "\n"
00053 
00054     output = re.sub(comm, "", output)
00055     output = re.sub(head, "", output)
00056     output = output.replace("\t", " ").replace("  ", " ").replace("\"", "'")
00057     output = output.replace(" = ", "=").replace(", ", ",")
00058 
00059     for line in output.splitlines():
00060         if line and not line.isspace():
00061             strlitcount += len(line)
00062             if strlitcount > 65535:
00063                 subcount += 1
00064                 def_file.write(";\n const char *defaultXML" + str(subcount) + " = ")
00065                 strlitcount = len(line)
00066             def_file.write("\"" + line + "\"\n")
00067     return subcount
00068 
00069 def buildDefTheme(themeName):
00070     def_file = open("default.inc", "w")
00071 
00072     if not os.path.isdir(themeName):
00073         print ("Cannot open default theme dir.")
00074 
00075     def_file.write("""const char *defaultXML1 = "<?xml version = '1.0'?>"\n""")
00076     subcount = 1
00077 
00078     filenames = os.listdir(themeName)
00079     filenames.sort()
00080     for filename in filenames:
00081         filename = os.path.join(themeName, filename)
00082         if os.path.isfile(filename) and filename.endswith(".stx"):
00083             theme_file = open(filename, "r")
00084             subcount = parseSTX(theme_file, def_file, subcount)
00085             theme_file.close()
00086 
00087     def_file.write(";\nconst char *defaultXML[] = { defaultXML1")
00088     for sub in range(2, subcount + 1):
00089         def_file.write(", defaultXML" + str(sub))
00090 
00091     def_file.write(" };\n")
00092 
00093     def_file.close()
00094 
00095 def printUsage():
00096     print ("===============================")
00097     print ("ScummVM Theme Generation Script")
00098     print ("===============================")
00099     print ("Usage:")
00100     print ("scummtheme.py makeall")
00101     print ("    Builds all the available themes.\n")
00102     print ("scummtheme.py make [themename]")
00103     print ("    Builds the theme called 'themename'.\n")
00104     print ("scummtheme.py default [themename]")
00105     print ("    Creates a 'default.inc' file to embed the given theme in the source code.\n")
00106 
00107 def main():
00108 
00109     if len(sys.argv) == 2 and sys.argv[1] == "makeall":
00110         buildAllThemes()
00111 
00112     elif len(sys.argv) == 3 and sys.argv[1] == "make":
00113         buildTheme(sys.argv[2])
00114 
00115     elif len(sys.argv) == 3 and sys.argv[1] == "default":
00116         buildDefTheme(sys.argv[2])
00117 
00118     else:
00119         printUsage()
00120 
00121 if __name__ == "__main__":
00122     sys.exit(main())


Generated on Sat Aug 17 2019 05:00:46 for ResidualVM by doxygen 1.7.1
curved edge   curved edge