#!/usr/bin/env python from fnmatch import fnmatch from glob import glob import os, os.path from functools import partial import re import zipfile extradist = [ glob(os.path.join( "C:\\", "Program Files", "Microsoft Visual Studio 8", "VC", "redist", "x86", "Microsoft.VC80.CRT", "*" )) # Visual C++ C Standard Library ] # where the various files will be inside of the archive EngineDir = os.path.join("lib", "gtk-2.0", "2.10.0", "engines") ThemeDir = os.path.join("share") # needed for partials fmatch = lambda pattern, filename: fnmatch(filename, pattern) # ignore the dirs CVS, .svn, _svn, and .bzr matchers = [partial(fmatch, "CVS"), re.compile(r"[._]svn").match, partial(fmatch, ".bzr")] def getEngines(dirs=None): """returns a set of engine dll's from the specified dirs currently we return all dlls, however later we may add a check to see if some functions are exported""" if dirs == None: dirs = ["release", "debug"] ret = set() dlls = set() basenames = set() for dir in dirs: files = set(glob(os.path.join(dir, "*.dll"))) tbn = set(os.path.basename(file) for file in files) - basenames for basename in tbn: dlls.add(os.path.join(dir, basename)) basenames.add(basename) ret = dlls return ret def getThemes(dir=os.path.join("gtk-engines", "themes")): """returns a list of gtkrc files to add as themes""" ret = [] for dir, dirs, files in os.walk(dir): # filter out dirs you don't want [dirs.remove(d) for d in dirs if any([matcher(d) for matcher in matchers])] if "gtkrc" in files: ret += [os.path.join(dir, "gtkrc")] return ret def addExtras(z): for collection in extradist: for f in collection: z.write(f, os.path.join(EngineDir, os.path.basename(f))) def addEngines(files, z): """add engine files specified by files to the zip file z""" for f in files: z.write(f, os.path.join(EngineDir, os.path.basename(f))) def addThemes(files, z): """add theme files specified by files to the zip file z""" for f in files: n = f if n.startswith("gtk-engines"): n = n.replace("gtk-engines", "", 1) n = n.lstrip("\\/") z.write(f, os.path.join(ThemeDir, n)) if __name__ == "__main__": # TODO: Make this suck less z = zipfile.ZipFile("gtk-engines.zip", "w") addEngines(getEngines(), z) addThemes(getThemes(), z) addExtras(z) z.close()