diff options
author | Vicent Marti | 2008-10-09 11:49:35 +0000 |
---|---|---|
committer | Vicent Marti | 2008-10-09 11:49:35 +0000 |
commit | 1f2ce8b1881078b3de82b63f8ecdc1777f4ab9d1 (patch) | |
tree | 3b454a1b1e0dca09eada21287ed7b7e8a7cf4226 /gui/themes/scummtheme.py | |
parent | 5dd381932f3ed501a27fe97f48ef30331b2924d5 (diff) | |
parent | 000eedb0737dbe400d016edf213928dbb1a227d3 (diff) | |
download | scummvm-rg350-1f2ce8b1881078b3de82b63f8ecdc1777f4ab9d1.tar.gz scummvm-rg350-1f2ce8b1881078b3de82b63f8ecdc1777f4ab9d1.tar.bz2 scummvm-rg350-1f2ce8b1881078b3de82b63f8ecdc1777f4ab9d1.zip |
Manual merge of the GSoC2008 GUI branch. (71 files)
svn-id: r34757
Diffstat (limited to 'gui/themes/scummtheme.py')
-rw-r--r-- | gui/themes/scummtheme.py | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/gui/themes/scummtheme.py b/gui/themes/scummtheme.py new file mode 100644 index 0000000000..6199289e66 --- /dev/null +++ b/gui/themes/scummtheme.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python +# encoding: utf-8 +import sys +import re +import os +import zipfile + +THEME_FILE_EXTENSIONS = ('.stx', '.bmp', '.fcc') + +def buildTheme(themeName): + if not os.path.isdir(themeName) or not os.path.isfile(os.path.join(themeName, "THEMERC")): + print "Invalid theme name: " + themeName + return + + zf = zipfile.ZipFile(themeName + ".zip", 'w') + + print "Building '" + themeName + "' theme:" + os.chdir(themeName) + + zf.write('THEMERC', './THEMERC') + + for filename in os.listdir('.'): + if os.path.isfile(filename) and not filename[0] == '.' and filename.endswith(THEME_FILE_EXTENSIONS): + zf.write(filename, './' + filename) + print " Adding file: " + filename + + os.chdir('../') + + zf.close() + +def buildAllThemes(): + for f in os.listdir('.'): + if os.path.isdir(os.path.join('.', f)) and not f[0] == '.': + buildTheme(f) + +def parseSTX(theme_file, def_file): + comm = re.compile("\/\*(.*?)\*\/", re.DOTALL) + + output = "" + for line in theme_file: + output += line.rstrip("\r\n\t ").lstrip() + " \n" + + output = re.sub(comm, "", output).replace("\t", " ").replace(" ", " ").replace("\"", "'").splitlines() + + for line in output: + if line and not line.isspace(): + def_file.write("\"" + line + "\"\n") + +def buildDefTheme(themeName): + def_file = open("default.inc", "w") + + if not os.path.isdir(themeName): + print "Cannot open default theme dir." + + for filename in os.listdir(themeName): + filename = os.path.join(themeName, filename) + if os.path.isfile(filename) and filename.endswith(".stx"): + theme_file = open(filename, "r") + parseSTX(theme_file, def_file) + theme_file.close() + + def_file.close() + +def printUsage(): + print "===============================" + print "ScummVM Theme Generation Script" + print "===============================" + print "Usage:" + print "scummtheme.py makeall" + print " Builds all the available themes.\n" + print "scummtheme.py make [themename]" + print " Builds the theme called 'themename'.\n" + print "scummtheme.py default [themename]" + print " Creates a 'default.inc' file to embed the given theme in the source code.\n" + +def main(): + + if len(sys.argv) == 2 and sys.argv[1] == "makeall": + buildAllThemes() + + elif len(sys.argv) == 3 and sys.argv[1] == "make": + buildTheme(sys.argv[2]) + + elif len(sys.argv) == 3 and sys.argv[1] == "default": + buildDefTheme(sys.argv[2]) + + else: + printUsage() + +if __name__ == "__main__": + sys.exit(main()) |