]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
make runner find twistd and invoke it with python
authorZooko O'Whielacronx <zooko@zooko.com>
Fri, 27 Apr 2007 06:14:13 +0000 (23:14 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Fri, 27 Apr 2007 06:14:13 +0000 (23:14 -0700)
This makes allmydata-tahoe work on Windows, and probably doesn't make it fail on other platforms.

src/allmydata/scripts/runner.py

index 70d2d997ce77c4da90c237ab645df0fe31322d71..d62656975cb9b826a0a943a2a1432d7e51c6c8f2 100644 (file)
@@ -1,8 +1,47 @@
 #! /usr/bin/env python
 
-import os, sys, signal, time
+import os, subprocess, sys, signal, time
 from twisted.python import usage
 
+from twisted.python.procutils import which
+
+def testtwistd(loc):
+    try:
+        return subprocess.call(["python", loc,], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    except:
+        return -1
+    
+twistd = None
+if not twistd:
+    for maybetwistd in which("twistd"):
+        ret = testtwistd(maybetwistd)
+        if ret == 0:
+            twistd = maybetwistd
+            break
+
+if not twistd:
+    for maybetwistd in which("twistd.py"):
+        ret = testtwistd(maybetwistd)
+        if ret == 0:
+            twistd = maybetwistd
+            break
+
+if not twistd:
+    maybetwistd = os.path.join(sys.prefix, 'Scripts', 'twistd')
+    ret = testtwistd(maybetwistd)
+    if ret == 0:
+        twistd = maybetwistd
+
+if not twistd:
+    maybetwistd = os.path.join(sys.prefix, 'Scripts', 'twistd.py')
+    ret = testtwistd(maybetwistd)
+    if ret == 0:
+        twistd = maybetwistd
+
+if not twistd:
+    print "Can't find twistd (it comes with Twisted).  Aborting."
+    sys.exit(1)
+    
 class StartOptions(usage.Options):
     optParameters = [
         ["basedir", "C", ".", "which directory to start the node in"],
@@ -175,7 +214,7 @@ def start(config):
         print "%s does not look like a node directory" % basedir
         sys.exit(1)
     os.chdir(basedir)
-    rc = os.system("twistd -y %s" % tac)
+    rc = subprocess.call(["python", twistd, "-y", tac,])
     if rc == 0:
         print "%s node probably started" % type
         return 0