[tor-commits] [nyx/master] Let users disable on-disk caching

atagar at torproject.org atagar at torproject.org
Wed Oct 26 16:16:54 UTC 2016


commit 774ed43694a0130c55b750fad581532c55d44364
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Oct 22 12:16:15 2016 -0700

    Let users disable on-disk caching
    
    Some users may not want us to cache information to disk. Including a nyxrc
    option to disable this.
    
    Also shortening these option names. Plan is for user-facing nyxrc options to be
    short, while internal options use namespacing.
---
 nyx/__init__.py     |  7 ++++++-
 nyx/arguments.py    |  4 ++--
 nyx/panel/config.py | 28 +++++++++++++++-------------
 nyx/panel/log.py    |  4 ++--
 nyx/starter.py      |  2 +-
 nyxrc.sample        | 12 +++++++++---
 6 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/nyx/__init__.py b/nyx/__init__.py
index 75dde99..a66c95b 100644
--- a/nyx/__init__.py
+++ b/nyx/__init__.py
@@ -85,7 +85,6 @@ CONFIG = stem.util.conf.config_dict('nyx', {
 NYX_INTERFACE = None
 TOR_CONTROLLER = None
 BASE_DIR = os.path.sep.join(__file__.split(os.path.sep)[:-1])
-DEFAULT_DATA_DIR = os.path.expanduser('~/.nyx')
 TESTING = False
 
 # technically can change but we use this query a *lot* so needs to be cached
@@ -238,6 +237,12 @@ def init_controller(*args, **kwargs):
 
 
 @uses_settings
+def data_directory(config):
+  path = config.get('data_directory', '~/.nyx')
+  return None if path == 'disabled' else os.path.expanduser(path)
+
+
+ at uses_settings
 def expand_path(path, config):
   """
   Expands relative paths and include our chroot if one was set.
diff --git a/nyx/arguments.py b/nyx/arguments.py
index 9b53e35..efb95ee 100644
--- a/nyx/arguments.py
+++ b/nyx/arguments.py
@@ -14,7 +14,7 @@ import nyx.log
 
 import stem.util.connection
 
-from nyx import DEFAULT_DATA_DIR, msg
+from nyx import msg
 
 DEFAULT_ARGS = {
   'control_address': '127.0.0.1',
@@ -22,7 +22,7 @@ DEFAULT_ARGS = {
   'user_provided_port': False,
   'control_socket': '/var/run/tor/control',
   'user_provided_socket': False,
-  'config': os.path.join(DEFAULT_DATA_DIR, 'nyxrc'),
+  'config': os.path.join(os.path.expanduser('~/.nyx'), 'nyxrc'),
   'debug_path': None,
   'logged_events': 'NOTICE,WARN,ERR,NYX_NOTICE,NYX_WARNING,NYX_ERROR',
   'print_version': False,
diff --git a/nyx/panel/config.py b/nyx/panel/config.py
index 8390ac5..0f454f3 100644
--- a/nyx/panel/config.py
+++ b/nyx/panel/config.py
@@ -19,7 +19,7 @@ import stem.util.connection
 
 from nyx.curses import WHITE, NORMAL, BOLD, HIGHLIGHT
 from nyx.menu import MenuItem, Submenu
-from nyx import DEFAULT_DATA_DIR, tor_controller, input_prompt, show_message
+from nyx import tor_controller, data_directory, input_prompt, show_message
 
 from stem.util import conf, enum, log, str_tools
 
@@ -41,7 +41,6 @@ CONFIG = conf.config_dict('nyx', {
   'features.config.order': [SortAttr.MAN_PAGE_ENTRY, SortAttr.NAME, SortAttr.IS_SET],
   'features.config.state.showPrivateOptions': False,
   'features.config.state.showVirtualOptions': False,
-  'startup.data_directory': DEFAULT_DATA_DIR,
 }, conf_handler)
 
 
@@ -131,21 +130,24 @@ class ConfigPanel(nyx.panel.Panel):
     self._sort_order = CONFIG['features.config.order']
     self._show_all = False  # show all options, or just the important ones
 
-    cached_manual_path = os.path.join(CONFIG['startup.data_directory'], 'manual')
+    data_dir = data_directory()
 
-    if os.path.exists(cached_manual_path):
-      manual = stem.manual.Manual.from_cache(cached_manual_path)
-    else:
-      try:
-        manual = stem.manual.Manual.from_man()
+    if data_dir:
+      cached_manual_path = os.path.join(data_dir, 'manual')
 
+      if os.path.exists(cached_manual_path):
+        manual = stem.manual.Manual.from_cache(cached_manual_path)
+      else:
         try:
-          manual.save(cached_manual_path)
+          manual = stem.manual.Manual.from_man()
+
+          try:
+            manual.save(cached_manual_path)
+          except IOError as exc:
+            log.debug("Unable to cache manual information to '%s'. This is fine, but means starting Nyx takes a little longer than usual: " % (cached_manual_path, exc))
         except IOError as exc:
-          log.debug("Unable to cache manual information to '%s'. This is fine, but means starting Nyx takes a little longer than usual: " % (cached_manual_path, exc))
-      except IOError as exc:
-        log.debug("Unable to use 'man tor' to get information about config options (%s), using bundled information instead" % exc)
-        manual = stem.manual.Manual.from_cache()
+          log.debug("Unable to use 'man tor' to get information about config options (%s), using bundled information instead" % exc)
+          manual = stem.manual.Manual.from_cache()
 
     try:
       for line in tor_controller().get_info('config/names').splitlines():
diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index 10e2645..6e1d14d 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -40,7 +40,7 @@ CONFIG = conf.config_dict('nyx', {
   'features.log.prepopulate': True,
   'features.log.prepopulateReadLimit': 5000,
   'features.log.regex': [],
-  'startup.events': 'NOTICE,WARN,ERR,NYX_NOTICE,NYX_WARNING,NYX_ERROR',
+  'logged_events': 'NOTICE,WARN,ERR,NYX_NOTICE,NYX_WARNING,NYX_ERROR',
 }, conf_handler)
 
 UPDATE_RATE = 0.3
@@ -69,7 +69,7 @@ class LogPanel(nyx.panel.DaemonPanel):
   def __init__(self):
     nyx.panel.DaemonPanel.__init__(self, UPDATE_RATE)
 
-    logged_events = CONFIG['startup.events'].split(',')
+    logged_events = CONFIG['logged_events'].split(',')
     tor_events = tor_controller().get_info('events/names', '').split()
     invalid_events = list(filter(lambda event: not event.startswith('NYX_') and event not in tor_events, logged_events))
 
diff --git a/nyx/starter.py b/nyx/starter.py
index dbb6d8c..d23e157 100644
--- a/nyx/starter.py
+++ b/nyx/starter.py
@@ -32,7 +32,7 @@ def main(config):
 
   try:
     args = nyx.arguments.parse(sys.argv[1:])
-    config.set('startup.events', args.logged_events)
+    config.set('logged_events', args.logged_events)
   except ValueError as exc:
     print(exc)
     sys.exit(1)
diff --git a/nyxrc.sample b/nyxrc.sample
index c9ff604..bbce437 100644
--- a/nyxrc.sample
+++ b/nyxrc.sample
@@ -1,6 +1,12 @@
-# Startup options
-startup.events N3
-startup.dataDirectory ~/.nyx
+# Events that are shown by default in the log. You can also set these with
+# 'nyx --log <events>'.
+
+logged_events NOTICE,WARN,ERR,NYX_NOTICE,NYX_WARNING,NYX_ERROR
+
+# Location where information is cached. You can disable caching by setting this
+# to 'disabled'.
+
+data_directory ~/.nyx
 
 # Seconds between querying information
 





More information about the tor-commits mailing list