[tor-commits] [arm/master] Putting TorCtl install prompt in its own function

sebastian at torproject.org sebastian at torproject.org
Sun Apr 24 05:55:01 UTC 2011


commit 6534807224d5f88b0c5450e996e5fa1f8c470763
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu Apr 21 08:52:36 2011 -0700

    Putting TorCtl install prompt in its own function
---
 src/prereq.py |   41 ++++++++++++++++++++++++++---------------
 1 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/src/prereq.py b/src/prereq.py
index ee5c768..50aaa91 100644
--- a/src/prereq.py
+++ b/src/prereq.py
@@ -20,6 +20,30 @@ def isTorCtlAvailable():
   except ImportError:
     return False
 
+def promptTorCtlInstall():
+  """
+  Asks the user to install TorCtl. This returns True if it was installed and
+  False otherwise (if it was either declined or failed to be fetched.
+  """
+  
+  userInput = raw_input("Arm requires TorCtl to run, but it's unavailable. Would you like to install it? (y/n): ")
+  
+  # if user says no then terminate
+  if not userInput.lower() in ("y", "yes"): return False
+  
+  # attempt to install TorCtl, printing the issue if unsuccessful
+  try:
+    installTorCtl()
+    
+    if not isTorCtlAvailable():
+      raise IOError("Unable to install TorCtl, sorry")
+    
+    print "TorCtl successfully installed"
+    return True
+  except IOError, exc:
+    print exc
+    return False
+
 def installTorCtl():
   """
   Checks out the current git head release for TorCtl and bundles it with arm.
@@ -65,19 +89,6 @@ if __name__ == '__main__':
     sys.exit(1)
   
   if not isTorCtlAvailable():
-    userInput = raw_input("Arm requires TorCtl to run, but it's unavailable. Would you like to install it? (y/n): ")
-    
-    # if user says no then terminate
-    if not userInput.lower() in ("y", "yes"):
-      sys.exit(1)
-    
-    # attempt to install TorCtl, printing the issue if unsuccessful
-    try:
-      installTorCtl()
-      
-      if not isTorCtlAvailable():
-        raise IOError("Unable to install TorCtl, sorry")
-    except IOError, exc:
-      print exc
-      sys.exit(1)
+    isInstalled = promptTorCtlInstall()
+    if not isInstalled: sys.exit(1)
 





More information about the tor-commits mailing list