Improved Windows start and build code.
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 10 Feb 2005 21:55:53 +0000 (21:55 +0000)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 10 Feb 2005 21:55:53 +0000 (21:55 +0000)
Created py2exe distribution build script.

14 files changed:
Makefile
build-windows-installer.py [new file with mode: 0755]
build-windows-py2exe-installer.py [new file with mode: 0644]
setup.py
src/gkofoto/gkofoto/environment.py
src/gkofoto/gkofoto/main.py
src/gkofoto/start-in-source.py [new file with mode: 0755]
src/gkofoto/start-in-source.pyw [new file with mode: 0644]
src/gkofoto/start-in-unix-source.py [deleted file]
src/gkofoto/start-in-windows-source.py [deleted file]
src/gkofoto/start-in-windows-source.pyw [deleted file]
src/gkofoto/start-installed.py [new file with mode: 0755]
src/gkofoto/start-on-unix.py [deleted file]
src/gkofoto/start-on-windows.py [deleted file]

index 1ade70f..30f585a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -37,7 +37,7 @@ dist_binary_targz:
        ./setup.py bdist --formats=gztar
 
 dist_windows_installer:
-       ./setup.py windows bdist_wininst --install-script gkofoto-windows-postinstall.py
+       ./build-windows-installer.py
 
 dist_rpm:
        ./setup.py bdist --formats=rpm
diff --git a/build-windows-installer.py b/build-windows-installer.py
new file mode 100755 (executable)
index 0000000..ace9b31
--- /dev/null
@@ -0,0 +1,18 @@
+#! /usr/bin/env python
+
+import setup
+import shutil
+
+shutil.copy("src/gkofoto/start-installed.py", "gkofoto-start.pyw")
+scripts = [
+    "src/cmdline/kofoto",
+    "gkofoto-start.pyw",
+    "src/gkofoto/scripts/gkofoto-windows-postinstall.py",
+    ]
+sys.argv = [
+    sys.argv[0],
+    "bdist_wininst",
+    "--install-script",
+    "gkofoto-windows-postinstall.py"]
+setup.run(scripts=scripts)
+os.unlink("gkofoto-start.pyw")
diff --git a/build-windows-py2exe-installer.py b/build-windows-py2exe-installer.py
new file mode 100644 (file)
index 0000000..c1a5d54
--- /dev/null
@@ -0,0 +1,52 @@
+#! /usr/bin/env python
+
+import glob
+import os
+import py2exe
+import setup
+import shutil
+import sys
+
+def nuke(elements):
+    for element in elements:
+        for dirpath, dirnames, filenames in os.walk(element, topdown=False):
+            for filename in filenames:
+                os.remove(os.path.join(dirpath, filename))
+            for dirname in dirnames:
+                os.rmdir(os.path.join(dirpath, dirname))
+        if os.path.isdir(element):
+            os.rmdir(element)
+        else:
+            os.remove(element)
+
+options = {
+    "py2exe": {
+        "includes": "pango,atk,gobject",
+        "packages": ["encodings"],
+        },
+    }
+
+shutil.copy("src/gkofoto/start-installed.py", "kofoto.py")
+windows = ["kofoto.py"]
+sys.argv = [sys.argv[0], "py2exe"]
+
+setup.run(options=options, windows=windows)
+
+os.unlink("kofoto.py")
+shutil.rmtree(glob.glob(os.path.join("dist", "tcl"))[0])
+os.remove(glob.glob(os.path.join("dist", "tcl*.dll"))[0])
+os.remove(glob.glob(os.path.join("dist", "tk*.dll"))[0])
+
+import _winreg
+import msvcrt
+k = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\GTK\\2.0")
+gtkdir = _winreg.QueryValueEx(k, "Path")[0]
+for dir in ["etc", "lib", "share"]:
+    destdir = os.path.join("dist", dir)
+    if not os.path.isdir(destdir):
+        os.mkdir(destdir)
+    for subdir in glob.glob(os.path.join(gtkdir, dir, "*")):
+        subdestdir = os.path.join(destdir, os.path.basename(subdir))
+        print "%s --> %s" % (subdir, subdestdir)
+        if not os.path.isdir(subdestdir):
+            shutil.copytree(subdir, subdestdir)
index 9d947bd..a7bdc1e 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -6,13 +6,7 @@ import os
 import shutil
 import sys
 
-if len(sys.argv) > 0 and sys.argv[1] == "windows":
-    windows_mode = True
-    del sys.argv[1]
-else:
-    windows_mode = False
-
-package_dir = {
+package_dirs = {
     "kofoto": "src/lib/kofoto",
     "gkofoto": "src/gkofoto/gkofoto",
     }
@@ -25,44 +19,40 @@ data_files = [
     ("share/gkofoto/glade", ["src/gkofoto/glade/gkofoto.glade"]),
     ("share/gkofoto/icons", glob.glob("src/gkofoto/icons/*.png")),
     ]
-
-if windows_mode:
-    shutil.copy("src/gkofoto/start-on-windows.py",
-                "src/gkofoto/scripts/gkofoto-start.pyw")
-    scripts = [
-        "src/cmdline/kofoto",
-        "src/gkofoto/scripts/gkofoto-start.pyw",
-        "src/gkofoto/scripts/gkofoto-windows-postinstall.py",
-        ]
-else:
-    shutil.copy("src/gkofoto/start-on-unix.py", "src/gkofoto/scripts/gkofoto")
-    scripts = [
-        "src/cmdline/kofoto",
-        "src/gkofoto/scripts/gkofoto",
-        ]
-
 versionDict = {}
 execfile("src/lib/kofoto/version.py", versionDict)
+common_setup_options = {
+    "name": "kofoto",
+    "version": versionDict["version"],
+    "description": "A tool for organizing and viewing images.",
+    "package_dir": package_dirs,
+    "packages": packages,
+    "data_files": data_files,
+    "author": "Joel Rosdahl and Ulrik Svensson",
+    "author_email": "kofoto@rosdahl.net",
+    "maintainer": "Joel Rosdahl and Ulrik Svensson",
+    "maintainer_email": "kofoto@rosdahl.net",
+    "url": "http://kofoto.rosdahl.net",
+    "license": "BSD",
+    "group": "Applications/Graphics",
+    "requires": "python >= 2.3, gtk+ >= 2.2, glade >= 2.0, pygtk, sqlite >= 2.8, pysqlite, PIL",
+}
+
+def run(**setup_options):
+    options = common_setup_options.copy()
+    options.update(setup_options)
+    setup(**options)
 
-setup(
-    name="kofoto",
-    version=versionDict["version"],
-    description="A tool for organizing and viewing images.",
-    package_dir=package_dir,
-    packages=packages,
-    scripts=scripts,
-    data_files=data_files,
-    author="Joel Rosdahl and Ulrik Svensson",
-    author_email="kofoto@rosdahl.net",
-    maintainer="Joel Rosdahl and Ulrik Svensson",
-    maintainer_email="kofoto@rosdahl.net",
-    url="http://kofoto.rosdahl.net",
-    license="BSD",
-    group="Applications/Graphics",
-    requires="python >= 2.3, gtk+ >= 2.2, glade >= 2.0, pygtk, sqlite >= 2.8, pysqlite, PIL",
-    )
+def unix_install():
+    shutil.copy("src/gkofoto/start-installed.py", "gkofoto")
+    setup_options = {
+        "scripts": [
+            "src/cmdline/kofoto",
+            "gkofoto",
+            ]
+        }
+    run(setup_options)
+    os.unlink("gkofoto")
 
-if windows_mode:
-    os.unlink("src/gkofoto/scripts/gkofoto-start.pyw")
-else:
-    os.unlink("src/gkofoto/scripts/gkofoto")
+if __name__ == "__main__":
+    unix_install()
index c804fd2..a2ad5d2 100644 (file)
@@ -5,7 +5,8 @@ import locale
 import re
 
 import pygtk
-pygtk.require('2.0')
+if sys.platform != "win32":
+    pygtk.require('2.0')
 import gtk
 import gobject
 import gtk.gdk
@@ -52,9 +53,14 @@ class Environment(ClientEnvironment):
         self.rotateLeftCommand = self.config.get(
             "gkofoto", "rotate_left_command", True)
 
+        # Case 1: Running from normal UNIX or Windows non-py2exe installation.
         dataDir = os.path.join(bindir, "..", "share", "gkofoto")
-        if not os.path.exists(dataDir):
-            dataDir = bindir
+        if not os.path.isdir(dataDir):
+            # Case 2: Running from Windows py2exe installation.
+            dataDir = os.path.join(bindir, "share", "gkofoto")
+            if not os.path.isdir(dataDir):
+                # Case 3: Running from source code.
+                dataDir = bindir
         self.iconDir = os.path.join(dataDir, "icons")
         self.gladeFile = os.path.join(dataDir, "glade", "gkofoto.glade")
         self.albumIconFileName = os.path.join(self.iconDir, "album.png")
index e5dd7b8..a258268 100644 (file)
@@ -1,9 +1,58 @@
+import os
 import sys
 from kofoto.clientenvironment import DEFAULT_CONFIGFILE_LOCATION
 from gkofoto.environment import env
 from gkofoto.controller import Controller
 from optparse import OptionParser
 
+def setupWindowsEnvironment(bindir):
+    import _winreg
+    import msvcrt
+
+    if  os.path.isdir(os.path.join(bindir, "etc")):
+        # Case 1: Bundled GTK+ runtime.
+        pass
+    else:
+        # Case 2: Separately installed GTK+ runtime.
+        try:
+            k = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\GTK\\2.0")
+        except EnvironmentError:
+            print "You must install the GTK+ 2.2 Runtime Environment to run this",
+            print "program."
+            while not msvcrt.kbhit():
+                pass
+            sys.exit(1)
+        else:
+            gtkdir = _winreg.QueryValueEx(k, "Path")
+            os.environ["PATH"] += ";%s/lib;%s/bin" % (gtkdir[0], gtkdir[0])
+
+    # Allow (default) datafile location to be determined under Windows 98.
+    if os.path.expanduser("~") == "~":
+        # Probably running under Windows 98 or similar OS where the
+        # environment variables HOMEPATH and HOMEDRIVE (and HOME) are not
+        # set. We have to fake it instead.
+        try:
+            # Look up where "My Documents" lives.
+            key = _winreg.OpenKey(
+                _winreg.HKEY_CURRENT_USER,
+                "Software\\Microsoft\\Windows\\CurrentVersion"
+                "\\Explorer\\Shell Folders")
+            home, dummy = _winreg.QueryValueEx(key, "Personal")
+            # At this point home is _probably_ a Unicode string.
+        except EnvironmentError:
+            home = None
+
+        if home == None:
+            # Unable to look up the location so just make one up, however
+            # nasty that location may be. We do output where the data
+            # location is on gkofoto startup.
+            home = "C:\\"
+
+        os.environ["HOME"] = home
+        # Note: Use os.environ as os.putenv() at least in Windows 98 only
+        # changes variable for sub processes; this process would not see
+        # the change.
+
 def main(bindir, argv):
     parser = OptionParser(version=env.version)
     parser.add_option(
@@ -29,6 +78,9 @@ def main(bindir, argv):
     if len(args) != 0:
         parser.error("incorrect number of arguments")
 
+    if sys.platform == "win32":
+        setupWindowsEnvironment(bindir)
+
     setupOk = env.setup(
         bindir, options.debug, options.configfile, options.database)
     env.controller = Controller()
diff --git a/src/gkofoto/start-in-source.py b/src/gkofoto/start-in-source.py
new file mode 100755 (executable)
index 0000000..ef2de91
--- /dev/null
@@ -0,0 +1,19 @@
+#! /usr/bin/env python
+
+import os
+import sys
+
+# Find bindir when started via a symlink.
+if os.path.islink(sys.argv[0]):
+    link = os.readlink(sys.argv[0])
+    absloc = os.path.normpath(
+        os.path.join(os.path.dirname(sys.argv[0]), link))
+    bindir = os.path.dirname(absloc)
+else:
+    bindir = os.path.dirname(sys.argv[0])
+
+# Find kofoto libraries (../lib) in the source tree.
+sys.path.insert(0, os.path.join(bindir, "..", "lib"))
+
+from gkofoto.main import main
+main(bindir, sys.argv)
diff --git a/src/gkofoto/start-in-source.pyw b/src/gkofoto/start-in-source.pyw
new file mode 100644 (file)
index 0000000..e5ef810
--- /dev/null
@@ -0,0 +1,5 @@
+# This file makes it possible to run GKofoto in Windows directly from
+# the source directory by double-clicking on it. No console window is
+# created.
+
+execfile("start-in-source.py")
diff --git a/src/gkofoto/start-in-unix-source.py b/src/gkofoto/start-in-unix-source.py
deleted file mode 100755 (executable)
index ef2de91..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#! /usr/bin/env python
-
-import os
-import sys
-
-# Find bindir when started via a symlink.
-if os.path.islink(sys.argv[0]):
-    link = os.readlink(sys.argv[0])
-    absloc = os.path.normpath(
-        os.path.join(os.path.dirname(sys.argv[0]), link))
-    bindir = os.path.dirname(absloc)
-else:
-    bindir = os.path.dirname(sys.argv[0])
-
-# Find kofoto libraries (../lib) in the source tree.
-sys.path.insert(0, os.path.join(bindir, "..", "lib"))
-
-from gkofoto.main import main
-main(bindir, sys.argv)
diff --git a/src/gkofoto/start-in-windows-source.py b/src/gkofoto/start-in-windows-source.py
deleted file mode 100644 (file)
index b03364e..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-# This file makes it possible to run GKofoto in Windows directly from
-# the source directory by double-clicking on it. A console window is
-# also created.
-
-import os
-import sys
-import _winreg
-import msvcrt
-
-try:
-    k = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\GTK\\2.0")
-except EnvironmentError:
-    print "You must install the GTK+ 2.2 Runtime Environment to run this program."
-    while not msvcrt.kbhit():
-        pass
-    sys.exit(1)
-else:
-    gtkdir = _winreg.QueryValueEx(k, "Path")
-    os.environ["PATH"] += ";%s/lib;%s/bin" % (gtkdir[0], gtkdir[0])
-
-# Allow (default) datafile location to be determined under Windows 98.
-if os.path.expanduser("~") == "~":
-    # Probably running under Windows 98 or similar OS where the
-    # environment variables HOMEPATH and HOMEDRIVE (and HOME) are not
-    # set. We have to fake it instead.
-    try:
-        # Look up where "My Documents" lives.
-        key = _winreg.OpenKey(
-            _winreg.HKEY_CURRENT_USER,
-            "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders")
-        home, dummy = _winreg.QueryValueEx(key, "Personal")
-        # At this point home is _probably_ a Unicode string.
-    except EnvironmentError:
-        home = None
-
-    if home == None:
-        # Unable to look up the location so just make one up, however
-        # nasty that location may be. We do output where the data
-        # location is on gkofoto startup.
-        home = "C:\\"
-
-    os.environ["HOME"] = home
-    # Note: Use os.environ as os.putenv() at least in Windows 98 only
-    # changes variable for sub processes; this process would not see
-    # the change.
-
-execfile("start-in-unix-source.py")
diff --git a/src/gkofoto/start-in-windows-source.pyw b/src/gkofoto/start-in-windows-source.pyw
deleted file mode 100644 (file)
index 84be09b..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-# This file makes it possible to run GKofoto in Windows directly from
-# the source directory by double-clicking on it. No console window is
-# created.
-
-execfile("start-in-windows-source.py")
diff --git a/src/gkofoto/start-installed.py b/src/gkofoto/start-installed.py
new file mode 100755 (executable)
index 0000000..8527580
--- /dev/null
@@ -0,0 +1,16 @@
+#! /usr/bin/env python
+
+import os
+import sys
+
+# Find bindir when started via a symlink.
+if os.path.islink(sys.argv[0]):
+    link = os.readlink(sys.argv[0])
+    absloc = os.path.normpath(
+        os.path.join(os.path.dirname(sys.argv[0]), link))
+    bindir = os.path.dirname(absloc)
+else:
+    bindir = os.path.dirname(sys.argv[0])
+
+from gkofoto.main import main
+main(bindir, sys.argv)
diff --git a/src/gkofoto/start-on-unix.py b/src/gkofoto/start-on-unix.py
deleted file mode 100755 (executable)
index 8527580..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#! /usr/bin/env python
-
-import os
-import sys
-
-# Find bindir when started via a symlink.
-if os.path.islink(sys.argv[0]):
-    link = os.readlink(sys.argv[0])
-    absloc = os.path.normpath(
-        os.path.join(os.path.dirname(sys.argv[0]), link))
-    bindir = os.path.dirname(absloc)
-else:
-    bindir = os.path.dirname(sys.argv[0])
-
-from gkofoto.main import main
-main(bindir, sys.argv)
diff --git a/src/gkofoto/start-on-windows.py b/src/gkofoto/start-on-windows.py
deleted file mode 100644 (file)
index 5e14ef4..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-import os
-import sys
-import _winreg
-import msvcrt
-
-try:
-    k = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\GTK\\2.0")
-except EnvironmentError:
-    print "You must install the GTK+ 2.2 Runtime Environment to run this program."
-    while not msvcrt.kbhit():
-        pass
-    sys.exit(1)
-else:
-    gtkdir = _winreg.QueryValueEx(k, "Path")
-    os.environ["PATH"] += ";%s/lib;%s/bin" % (gtkdir[0], gtkdir[0])
-
-# Allow (default) datafile location to be determined under Windows 98.
-if os.path.expanduser("~") == "~":
-    # Probably running under Windows 98 or similar OS where the
-    # environment variables HOMEPATH and HOMEDRIVE (and HOME) are not
-    # set. We have to fake it instead.
-    try:
-        # Look up where "My Documents" lives.
-        key = _winreg.OpenKey(
-            _winreg.HKEY_CURRENT_USER,
-            "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders")
-        home, dummy = _winreg.QueryValueEx(key, "Personal")
-        # At this point home is _probably_ a Unicode string.
-    except EnvironmentError:
-        home = None
-
-    if home == None:
-        # Unable to look up the location so just make one up, however
-        # nasty that location may be. We do output where the data
-        # location is on gkofoto startup.
-        home = "C:\\"
-
-    os.environ["HOME"] = home
-    # Note: Use os.environ as os.putenv() at least in Windows 98 only
-    # changes variable for sub processes; this process would not see
-    # the change.
-
-bindir = os.path.dirname(sys.argv[0])
-
-from gkofoto.main import main
-main(bindir, sys.argv)