from os import makedirs, walk, sep, remove from os.path import join, dirname, basename, exists from shutil import rmtree, copy, rmtree from itertools import chain from zipfile import ZipFile import py2exe from Setup import Setup class SetupWin(Setup): def __init__(self): Setup.__init__(self) self.replace_isSystemDLL() def replace_isSystemDLL(self): origIsSystemDLL = py2exe.build_exe.isSystemDLL def isSystemDLL(pathname): if basename(pathname).lower() in ("libogg-0.dll", "sdl_ttf.dll"): return 0 return origIsSystemDLL(pathname) py2exe.build_exe.isSystemDLL = isSystemDLL def setup(self): config = self.config.get_section("setup") windows = [{}] if config["init-script"]: windows[0]["script"] = config["init-script"] if config["windows-icon-path"]: windows[0]["icon-resources"] = [(1, config["windows-icon-path"])] Setup.setup(self, windows, {"py2exe": {"packages": self.build_package_list(), "dist_dir": config["windows-dist-path"]}}) rmtree("build") self.copy_data_files() self.create_archive() def copy_data_files(self): root = self.config.get("setup", "windows-dist-path") for path in chain(*zip(*self.build_data_map())[1]): dest = join(root, dirname(path)) if not exists(dest): makedirs(dest) copy(path, dest) self.include_readme(root) def include_readme(self, root): name = "README" if exists(name): readme = open(name, "r") reformatted = open(join(root, name + ".txt"), "w") for line in open(name, "r"): reformatted.write(line.rstrip() + "\r\n") def create_archive(self): config = self.config.get_section("setup") title = self.translate_title() + "-" + config["version"] + "-win" archive_name = title + ".zip" archive = ZipFile(archive_name, "w") destination = config["windows-dist-path"] for root, dirs, names in walk(destination): for name in names: path = join(root, name) archive.write(path, path.replace(destination, title + sep)) archive.close() copy(archive_name, "dist") remove(archive_name) rmtree(destination)