Created .iss file template and added code for generating .iss file from
[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 ["etc", "lib", "share"]:
34     destdir = join("dist", dir)
35     if not isdir(destdir):
36         os.mkdir(destdir)
37     for subdir in glob.glob(join(gtkdir, dir, "*")):
38         subdestdir = join(destdir, basename(subdir))
39         print "copying %s --> %s" % (subdir, subdestdir)
40         if not isdir(subdestdir):
41             shutil.copytree(subdir, subdestdir)
42
43 shutil.copy("COPYING.txt", "dist/license.txt")
44 license_file = open("dist/license.txt", "a")
45 for x in ["python", "gtk", "pygtk", "pil", "pysqlite"]:
46     f = open("packaging/%s-license.txt" % x)
47     license_file.write("\n")
48     license_file.write(f.read())
49
50 versionDict = {}
51 execfile("src/lib/kofoto/version.py", versionDict)
52
53 print "creating kofoto.iss"
54 template = \
55     open("packaging/windows/kofoto.iss.template").read() \
56         .replace("%version%", versionDict["version"]) \
57         .replace("%licensefile%", join(os.getcwd(), "dist", "license.txt")) \
58         .replace("%distdir%", join(os.getcwd(), "dist"))
59 issfile = open("kofoto.iss", "w")
60 issfile.write(template)