59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
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")
|
|
Setup.setup(self,
|
|
[{"script": config["init-script"],
|
|
"icon_resources": [(1, config["icon-path"])]
|
|
}],
|
|
{"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):
|
|
for path in chain(*zip(*self.build_data_map())[1]):
|
|
dest = join(self.config.get("setup", "windows-dist-path"),
|
|
dirname(path))
|
|
if not exists(dest):
|
|
makedirs(dest)
|
|
copy(path, dest)
|
|
|
|
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)
|