]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
fix bin/tahoe executable for Windows
authorcgalvan <cgalvan@mail.utexas.edu>
Fri, 9 Jan 2009 19:42:22 +0000 (12:42 -0700)
committercgalvan <cgalvan@mail.utexas.edu>
Fri, 9 Jan 2009 19:42:22 +0000 (12:42 -0700)
bin/tahoe
setup.py

index 45fb1e22e55484702ae7af0bb4d52aff774dae07..7299407e30f78100bbe1786c384529faa85f4631 100644 (file)
--- a/bin/tahoe
+++ b/bin/tahoe
@@ -41,7 +41,11 @@ else:
     pp = supportdir
 os.environ["PYTHONPATH"] = pp
 
-executable = os.path.join(base, "support", "bin", "tahoe")
+# find the location of the tahoe executable.
+bin_dir = "bin"
+if sys.platform == "win32":
+    bin_dir = "Scripts"
+executable = os.path.join(base, "support", bin_dir, "tahoe")
 
 try:
     subprocess.call([executable] + sys.argv[1:], env=os.environ)
index 778bb004382e5f25ce099064d775f621a081a7c2..913c0ccd9974cb0a1439dea4b89494535bd8f771 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -8,7 +8,7 @@
 #
 # See the docs/about.html file for licensing information.
 
-import os, re, sys, stat, subprocess
+import os, re, shutil, stat, subprocess, sys, zipfile
 
 ##### sys.path management
 
@@ -84,6 +84,7 @@ else:
 from setuptools import find_packages, setup
 from setuptools.command import sdist
 from distutils.core import Command
+from pkg_resources import require
 
 import pkg_resources
 pkg_resources.require('setuptools_trial')
@@ -255,6 +256,39 @@ class BuildTahoe(Command):
     def finalize_options(self):
         pass
     def run(self):
+        # On Windows, create the 'tahoe-script.py' file based on the 'tahoe'
+        # executable script under the 'bin' directory so that the tahoe.exe
+        # will work correctly.  The 'tahoe-script.py' file is exactly the same
+        # as the 'tahoe' script except that we need to update the she-bang
+        # line.  The tahoe.exe will be copied from the setuptools egg's cli.exe
+        # and this will work from a zip-safe and non-zip-safe setuptools egg.
+        if sys.platform == "win32":
+            setuptools_egg = require("setuptools")[0].location
+            if os.path.isfile(setuptools_egg):
+                z = zipfile.ZipFile(setuptools_egg, 'r')
+                for filename in z.namelist():
+                    if 'cli.exe' in filename:
+                        cli_exe = z.read(filename)
+            else:
+                cli_exe = os.path.join(setuptools_egg, 'setuptools', 'cli.exe')
+            tahoe_exe = os.path.join("bin", "tahoe.exe")
+            if os.path.isfile(setuptools_egg):
+                f = open(tahoe_exe, 'wb')
+                f.write(cli_exe)
+                f.close()
+            else:
+                shutil.copy(cli_exe, tahoe_exe)
+            bin_tahoe = os.path.join("bin", "tahoe")
+            f = open(bin_tahoe, "r")
+            script_lines = f.readlines()
+            f.close()
+            script_lines[0] = "#!%s\n" % sys.executable
+            tahoe_script = os.path.join("bin", "tahoe-script.py")
+            f = open(tahoe_script, "w")
+            for line in script_lines:
+                f.write(line)
+            f.close()
+
         command = [sys.executable, "setup.py", "develop", "--prefix", "support"]
         print "Command:", " ".join(command)
         rc = subprocess.call(command)