Commits

Anthony Tuininga committed c59dc97

Correct the paths for scripts during installation instead of during the build
as the paths I use on my machine are non-standard and, even if they were, may
not match the ones that are used on the target machine.

Comments (0)

Files changed (3)

cxfreeze-postinstall

+#------------------------------------------------------------------------------
+# cxfreeze-postinstall
+#   Script run after installation on Windows to fix up the Python location in
+# the script as well as create batch files.
+#------------------------------------------------------------------------------
+
+import distutils.sysconfig
+import glob
+import os
+
+vars = distutils.sysconfig.get_config_vars()
+prefix = vars["prefix"]
+python = os.path.join(prefix, "python.exe")
+scriptDir = os.path.join(prefix, "Scripts")
+for fileName in glob.glob(os.path.join(scriptDir, "cxfreeze*")):
+
+    # skip already created batch files if they exist
+    name, ext = os.path.splitext(os.path.basename(fileName))
+    if name == "cxfreeze-postinstall" or ext:
+        continue
+
+    # copy the file with the first line replaced with the correct python
+    fullName = os.path.join(scriptDir, fileName)
+    lines = open(fullName).readlines()
+    outFile = open(fullName, "w")
+    print >> outFile, "#!" + python
+    outFile.writelines(lines[1:])
+    outFile.close()
+
+    # create the batch file
+    batchFileName = fullName + ".bat"
+    command = "%s %s %%*" % (python, fullName)
+    open(batchFileName, "w").write("@echo off\n\n%s" % command)
+

doc/releasenotes.rst

 * Freezing a script using PyQt on a Mac failed with a type error.
 * Version number reported was incorrect.
 (`Issue #7 <https://bitbucket.org/anthony_tuininga/cx_freeze/issue/7/bad-version-for-43>`_)
+* Correct paths during installation on Windows.
+(`Issue #11 <https://bitbucket.org/anthony_tuininga/cx_freeze/issue/11/incorrect-paths-in-installed-cxfreeze#comment-2425986>`_)
 
 
 Version 4.3
 import cx_Freeze
 import distutils.command.bdist_rpm
 import distutils.command.build_ext
-import distutils.command.build_scripts
 import distutils.command.install
 import distutils.command.install_data
 import distutils.sysconfig
 import os
 import sys
 
+
 from distutils.core import setup
 from distutils.extension import Extension
 
+if sys.platform == "win32":
+    import msilib
+    import distutils.command.bdist_msi
+
+    class bdist_msi(distutils.command.bdist_msi.bdist_msi):
+
+        def add_scripts(self):
+            distutils.command.bdist_msi.bdist_msi.add_scripts(self)
+            msilib.add_data(self.db, "RemoveFile",
+                    [("cxFreezeBatch", "cx_Freeze", "cxfreeze*.bat", "Scripts",
+                        2)])
+
+
 class bdist_rpm(distutils.command.bdist_rpm.bdist_rpm):
 
     # rpm automatically byte compiles all Python files in a package but we
         return fileName[:-len(soExt)] + ext
 
 
-class build_scripts(distutils.command.build_scripts.build_scripts):
-
-    def copy_scripts(self):
-        distutils.command.build_scripts.build_scripts.copy_scripts(self)
-        if sys.platform == "win32":
-            for script in self.scripts:
-                batFileName = os.path.join(self.build_dir, script + ".bat")
-                fullScriptName = r"%s\Scripts\%s" % \
-                        (os.path.dirname(sys.executable), script)
-                command = "%s %s %%*" % (sys.executable, fullScriptName)
-                open(batFileName, "w").write("@echo off\n\n%s" % command)
-
-
 class install(distutils.command.install.install):
 
     def get_sub_commands(self):
 
 commandClasses = dict(
         build_ext = build_ext,
-        build_scripts = build_scripts,
         bdist_rpm = bdist_rpm,
         install = install,
         install_packagedata = install_packagedata)
+if sys.platform == "win32":
+    commandClasses["bdist_msi"] = bdist_msi
 
 # generate C source for base frozen modules
 subDir = "temp.%s-%s" % (distutils.util.get_platform(), sys.version[:3])
         libraries = libraries)
 
 # build base executables
+docFiles = "README.txt"
+scripts = ["cxfreeze", "cxfreeze-quickstart"]
+options = dict(bdist_rpm = dict(doc_files = docFiles),
+        install = dict(optimize = 1))
 depends = ["source/bases/Common.c"]
 fullDepends = depends + [baseModulesFileName]
 includeDirs = [baseModulesDir]
         ["source/bases/ConsoleKeepPath.c"], depends = depends)
 extensions = [utilModule, console, consoleKeepPath]
 if sys.platform == "win32":
+    scripts.append("cxfreeze-postinstall")
+    options["bdist_msi"] = dict(install_script = "cxfreeze-postinstall")
     gui = Extension("cx_Freeze.bases.Win32GUI", ["source/bases/Win32GUI.c"],
             include_dirs = includeDirs, depends = fullDepends,
             libraries = ["user32"])
                 include_dirs = includeDirs)
         extensions.append(service)
 
-docFiles = "README.txt"
-
 classifiers = [
         "Development Status :: 5 - Production/Stable",
         "Intended Audience :: Developers",
         long_description = "create standalone executables from Python scripts",
         version = "4.3.1",
         cmdclass = commandClasses,
-        options = dict(bdist_rpm = dict(doc_files = docFiles),
-                install = dict(optimize = 1)),
+        options = options,
         ext_modules = extensions,
         packages = ['cx_Freeze'],
         maintainer="Anthony Tuininga",
         maintainer_email="anthony.tuininga@gmail.com",
         url = "http://cx-freeze.sourceforge.net",
-        scripts = ["cxfreeze", "cxfreeze-quickstart"],
+        scripts = scripts,
         classifiers = classifiers,
         keywords = "freeze",
         license = "Python Software Foundation License")