commit b69a5c8eff299c75617ee76cb5354825c36c9ffa Author: Damian Johnson atagar@torproject.org Date: Mon Dec 10 09:03:12 2012 -0800
Auto-installing stem when it's unavailable
Replacing TorCtl's git-based autoinstaller with one for stem. The installTorCtl() function was unused in favor of fetchLibrary() but a git based installer is perfect right now for stem since it doesn't yet have tarball releases. --- src/prereq.py | 65 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 52 insertions(+), 13 deletions(-)
diff --git a/src/prereq.py b/src/prereq.py index 8641057..c007c8c 100644 --- a/src/prereq.py +++ b/src/prereq.py @@ -18,7 +18,7 @@ CAGRAPH_ARCHIVE = "http://www.atagar.com/arm/resources/deps/11-06-10/cagraph.tar CAGRAPH_SIG = "1439acd40ce016f4329deb216d86f36a749e4b8bf73a313a757396af6f95310d"
# optionally we can do an unverified fetch from the library's sources -TORCTL_REPO = "git://git.torproject.org/pytorctl.git" +STEM_REPO = "git://git.torproject.org/stem.git" CAGRAPH_TARBALL_URL = "http://cagraph.googlecode.com/files/cagraph-1.2.tar.gz" CAGRAPH_TARBALL_NAME = "cagraph-1.2.tar.gz" CAGRAPH_TARBALL_ROOT = "cagraph-1.2" @@ -34,6 +34,17 @@ def isTorCtlAvailable(): except ImportError: return False
+def isStemAvailable(): + """ + True if stem is already available on the platform, false otherwise. + """ + + try: + import stem + return True + except ImportError: + return False + def isCagraphAvailable(): """ True if cagraph is already available on the platform, false otherwise. @@ -68,6 +79,30 @@ def promptTorCtlInstall(): print exc return False
+def promptStemInstall(): + """ + Asks the user to install stem. 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 stem 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 stem, printing the issue if unsuccessful + try: + installStem() + + if not isStemAvailable(): + raise IOError("Unable to install stem, sorry") + + print "Stem successfully installed" + return True + except IOError, exc: + print exc + return False + def promptCagraphInstall(): """ Asks the user to install cagraph. This returns True if it was installed and @@ -129,28 +164,28 @@ def fetchLibrary(url, sig): # clean up the temporary contents (fails quietly if unsuccessful) shutil.rmtree(destination, ignore_errors=True)
-def installTorCtl(): +def installStem(): """ - Checks out the current git head release for TorCtl and bundles it with arm. + Checks out the current git head release for stem and bundles it with arm. This raises an IOError if unsuccessful. """
- if isTorCtlAvailable(): return + if isStemAvailable(): return
- # temporary destination for TorCtl's git clone, guarenteed to be unoccupied + # temporary destination for stem's git clone, guarenteed to be unoccupied # (to avoid conflicting with files that are already there) - tmpFilename = tempfile.mktemp("/torctl") + tmpFilename = tempfile.mktemp("/stem")
- # fetches TorCtl - exitStatus = os.system("git clone --quiet %s %s > /dev/null" % (TORCTL_REPO, tmpFilename)) - if exitStatus: raise IOError("Unable to get TorCtl from %s. Is git installed?" % TORCTL_REPO) + # fetches stem + exitStatus = os.system("git clone --quiet %s %s > /dev/null" % (STEM_REPO, tmpFilename)) + if exitStatus: raise IOError("Unable to get stem from %s. Is git installed?" % STEM_REPO)
- # the destination for TorCtl will be our directory + # the destination for stem will be our directory ourDir = os.path.dirname(os.path.realpath(__file__))
- # exports TorCtl to our location - exitStatus = os.system("(cd %s && git archive --format=tar --prefix=TorCtl/ master) | (cd %s && tar xf - 2> /dev/null)" % (tmpFilename, ourDir)) - if exitStatus: raise IOError("Unable to install TorCtl to %s" % ourDir) + # exports stem to our location + exitStatus = os.system("(cd %s && git archive --format=tar master stem) | (cd %s && tar xf - 2> /dev/null)" % (tmpFilename, ourDir)) + if exitStatus: raise IOError("Unable to install stem to %s" % ourDir)
# Clean up the temporary contents. This isn't vital so quietly fails in case # of errors. @@ -199,6 +234,10 @@ def allPrereq(): if not isTorCtlAvailable(): isInstalled = promptTorCtlInstall() if not isInstalled: sys.exit(1) + + if not isStemAvailable(): + isInstalled = promptStemInstall() + if not isInstalled: sys.exit(1)
def cliPrereq(): """
tor-commits@lists.torproject.org