5bf8969adc8ddf589b52c35a4a6b05446816abaa
[joel/kofoto.git] / build-windows-py2exe-installer.py
1 #! /usr/bin/env python
2
3 import glob
4 import os
5 import py2exe
6 import setup
7 import shutil
8 import sys
9 import _winreg
10 import msvcrt
11 from os.path import join, isdir, basename
12
13 options = {
14     "py2exe": {
15         "includes": "pango,atk,gobject",
16         "packages": ["encodings"],
17         },
18     }
19
20 shutil.copy("src/gkofoto/start-installed.py", "kofoto.py")
21 windows = ["kofoto.py"]
22 sys.argv = [sys.argv[0], "py2exe"]
23
24 setup.run(options=options, windows=windows)
25
26 os.unlink("kofoto.py")
27 shutil.rmtree(glob.glob("dist/tcl")[0])
28 os.remove(glob.glob("dist/tcl*.dll")[0])
29 os.remove(glob.glob("dist/tk*.dll")[0])
30
31 k = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\GTK\\2.0")
32 gtkdir = _winreg.QueryValueEx(k, "Path")[0]
33 for dir in ["bin", "etc", "lib", "share"]:
34     for dirpath, dirnames, filenames in os.walk(join(gtkdir, dir)):
35         destdir = join("dist", dirpath[len(gtkdir) + 1:])
36         if not isdir(destdir):
37             os.makedirs(destdir)
38         for filename in filenames:
39             print "copying %s --> %s" % (join(dirpath, filename), destdir)
40             shutil.copy(join(dirpath, filename), destdir)
41
42 shutil.copy("COPYING.txt", "dist/license.txt")
43 license_file = open("dist/license.txt", "a")
44 for x in ["python", "gtk", "pygtk", "pil", "pysqlite"]:
45     f = open("packaging/%s-license.txt" % x)
46     license_file.write("\n")
47     license_file.write(f.read())
48
49 versionDict = {}
50 execfile("src/lib/kofoto/version.py", versionDict)
51
52 print "creating kofoto.iss"
53 template = \
54     open("packaging/windows/kofoto.iss.template").read() \
55         .replace("%version%", versionDict["version"]) \
56         .replace("%licensefile%", join(os.getcwd(), "dist", "license.txt")) \
57         .replace("%distdir%", join(os.getcwd(), "dist"))
58 issfile = open("kofoto.iss", "w")
59 issfile.write(template)