Include commandline interface too in standalone Windows package.
[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/cmdline/kofoto", "kofoto.py")
21 shutil.copy("src/gkofoto/start-installed.py", "gkofoto.py")
22 console = ["kofoto.py"]
23 windows = ["gkofoto.py"]
24 sys.argv = [sys.argv[0], "py2exe"]
25
26 setup.run(options=options, console=console, windows=windows)
27
28 os.unlink("kofoto.py")
29 os.unlink("gkofoto.py")
30 shutil.rmtree(glob.glob("dist/tcl")[0])
31 os.remove(glob.glob("dist/tcl*.dll")[0])
32 os.remove(glob.glob("dist/tk*.dll")[0])
33
34 k = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\GTK\\2.0")
35 gtkdir = _winreg.QueryValueEx(k, "Path")[0]
36 for dir in ["bin", "etc", "lib", "share"]:
37     for dirpath, dirnames, filenames in os.walk(join(gtkdir, dir)):
38         destdir = join("dist", dirpath[len(gtkdir) + 1:])
39         if not isdir(destdir):
40             os.makedirs(destdir)
41         for filename in filenames:
42             print "copying %s --> %s" % (join(dirpath, filename), destdir)
43             shutil.copy(join(dirpath, filename), destdir)
44
45 shutil.copy("COPYING.txt", "dist/license.txt")
46 license_file = open("dist/license.txt", "a")
47 for x in ["python", "gtk", "pygtk", "pil", "pysqlite"]:
48     f = open("packaging/%s-license.txt" % x)
49     license_file.write("\n")
50     license_file.write(f.read())
51
52 versionDict = {}
53 execfile("src/lib/kofoto/version.py", versionDict)
54
55 print "creating kofoto.iss"
56 template = \
57     open("packaging/windows/kofoto.iss.template").read() \
58         .replace("%version%", versionDict["version"]) \
59         .replace("%licensefile%", join(os.getcwd(), "dist", "license.txt")) \
60         .replace("%distdir%", join(os.getcwd(), "dist"))
61 issfile = open("kofoto.iss", "w")
62 issfile.write(template)