summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamian Johnson <atagar@torproject.org>2019-11-18 17:17:59 -0800
committerDamian Johnson <atagar@torproject.org>2019-11-18 17:17:59 -0800
commitadbc54bcb090bca82bbf59847dec47ac84c3dfa8 (patch)
treec3b58752f493d86de45f1b4f4899ad2494c99ba7
parentec6966df3ae9397c50996f7dc096707deedfa37b (diff)
parent30d5fa3b206ff9227a0c34a553b53dd8951b1241 (diff)
Provide stem installation instructions
Oops! We used stem's is_available() to provide installation instructions for... stem. Thanks to bounteous17 for fixing this chicken-and-egg... https://trac.torproject.org/projects/tor/ticket/32538
-rw-r--r--nyx/__init__.py54
1 files changed, 33 insertions, 21 deletions
diff --git a/nyx/__init__.py b/nyx/__init__.py
index f58a33d..9861687 100644
--- a/nyx/__init__.py
+++ b/nyx/__init__.py
@@ -42,7 +42,9 @@ Tor curses monitoring application.
+- halt - stops daemon panels
"""
+import collections
import contextlib
+import distutils.spawn
import getpass
import os
import platform
@@ -50,14 +52,36 @@ import sys
import threading
import time
-import stem
-import stem.connection
-import stem.control
-import stem.util.conf
-import stem.util.connection
-import stem.util.log
-import stem.util.system
-import stem.util.tor_tools
+# mapping of package managers to their stem installation command
+
+PACKAGE_MANAGERS = collections.OrderedDict((
+ ('apt-get', 'sudo apt-get install python-stem'), # Debian
+ ('dnf', 'sudo dnf install python-stem'), # Redhat
+ ('pacman', 'sudo pacman -S python-stem'), # Archlinux
+ ('emerge', 'sudo emerge stem'), # Gentoo
+ ('pkg', 'pkg install security/py-stem'), # FreeBSD
+ ('pkg_add', 'pkg_add py-stem'), # OpenBSD
+ ('pip', 'pip install stem'), # PyPI
+))
+
+try:
+ import stem
+ import stem.connection
+ import stem.control
+ import stem.util.conf
+ import stem.util.connection
+ import stem.util.log
+ import stem.util.system
+ import stem.util.tor_tools
+except ImportError:
+ for cmd, stem_install in PACKAGE_MANAGERS.items():
+ if distutils.spawn.find_executable(cmd):
+ print("nyx requires stem, try running '%s'" % stem_install)
+ sys.exit(1)
+
+ print('nyx requires stem, you can find it at https://stem.torproject.org/download.html')
+ sys.exit(1)
+
SQLITE_UNAVAILABLE = """\
Python's sqlite3 module is unavailable. Unfortunately some platforms
@@ -114,7 +138,6 @@ def conf_handler(key, value):
if key == 'redraw_rate':
return max(1, value)
-
CONFIG = stem.util.conf.config_dict('nyx', {
'confirm_quit': True,
'redraw_rate': 5,
@@ -175,18 +198,7 @@ def main():
try:
nyx.starter.main()
except ImportError as exc:
- if exc.message == 'No module named stem':
- if stem.util.system.is_available('pip'):
- advice = ", try running 'sudo pip install stem'"
- elif stem.util.system.is_available('apt-get'):
- advice = ", try running 'sudo apt-get install python-stem'"
- else:
- advice = ', you can find it at https://stem.torproject.org/download.html'
-
- print('nyx requires stem' + advice)
- else:
- print('Unable to start nyx: %s' % exc)
-
+ print('Unable to start nyx: %s' % exc)
sys.exit(1)