From d8a878da863ce33cf1846e0a8957a45f4aa0eeb7 Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@lothar.com>
Date: Tue, 10 Jul 2007 19:13:55 -0700
Subject: [PATCH] startstop_node.py: refactor find_twistd() out so it is only
 run when you need to start a node

---
 src/allmydata/scripts/startstop_node.py | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/allmydata/scripts/startstop_node.py b/src/allmydata/scripts/startstop_node.py
index 5f73cd64..f2197853 100644
--- a/src/allmydata/scripts/startstop_node.py
+++ b/src/allmydata/scripts/startstop_node.py
@@ -30,40 +30,32 @@ def testtwistd(loc):
         return subprocess.call(["python", loc,], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     except:
         return -1
-    
-twistd = None
-if not twistd:
+
+def find_twistd():
     for maybetwistd in which("twistd"):
         ret = testtwistd(maybetwistd)
         if ret == 0:
-            twistd = maybetwistd
-            break
+            return maybetwistd
 
-if not twistd:
     for maybetwistd in which("twistd.py"):
         ret = testtwistd(maybetwistd)
         if ret == 0:
-            twistd = maybetwistd
-            break
+            return maybetwistd
 
-if not twistd:
     maybetwistd = os.path.join(sys.prefix, 'Scripts', 'twistd')
     ret = testtwistd(maybetwistd)
     if ret == 0:
-        twistd = maybetwistd
+        return maybetwistd
 
-if not twistd:
     maybetwistd = os.path.join(sys.prefix, 'Scripts', 'twistd.py')
     ret = testtwistd(maybetwistd)
     if ret == 0:
-        twistd = maybetwistd
+        return maybetwistd
 
-if not twistd:
     print "Can't find twistd (it comes with Twisted).  Aborting."
     sys.exit(1)
 
 
-
 def do_start(basedir, config, out=sys.stdout, err=sys.stderr):
     print >>out, "STARTING", basedir
     if os.path.exists(os.path.join(basedir, "client.tac")):
@@ -77,6 +69,7 @@ def do_start(basedir, config, out=sys.stdout, err=sys.stderr):
         if not os.path.isdir(basedir):
             print >>err, " in fact, it doesn't look like a directory at all!"
         sys.exit(1)
+    twistd = find_twistd()
     rc = subprocess.call(["python", twistd, "-y", tac,], cwd=basedir)
     if rc == 0:
         print >>out, "%s node probably started" % type
-- 
2.45.2