[tor-commits] [nyx/master] Using blank ConfigOption when unavailable

atagar at torproject.org atagar at torproject.org
Mon Jan 4 17:43:06 UTC 2016


commit 0c93c14b64a46d464a39bce24a986b8a09a9fe93
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Jan 1 16:31:56 2016 -0800

    Using blank ConfigOption when unavailable
    
    Making a blank ConfigOption rather than a bunch of 'if defined' checks.
---
 nyx/__init__.py         |    6 +++---
 nyx/config_panel.py     |   40 +++++++++++-----------------------------
 nyx/connection_panel.py |    4 +++-
 nyx/util/__init__.py    |   18 +++++++++---------
 nyx/util/tor_config.py  |    1 -
 test/settings.cfg       |    1 +
 6 files changed, 27 insertions(+), 43 deletions(-)

diff --git a/nyx/__init__.py b/nyx/__init__.py
index 078955d..4d58435 100644
--- a/nyx/__init__.py
+++ b/nyx/__init__.py
@@ -2,6 +2,9 @@
 Tor curses monitoring application.
 """
 
+import distutils.spawn
+import sys
+
 __version__ = '1.4.6-dev'
 __release_date__ = 'April 28, 2011'
 __author__ = 'Damian Johnson'
@@ -21,9 +24,6 @@ __all__ = [
   'torrc_panel',
 ]
 
-import distutils.spawn
-import sys
-
 
 def main():
   try:
diff --git a/nyx/config_panel.py b/nyx/config_panel.py
index c2fe11a..ef80a59 100644
--- a/nyx/config_panel.py
+++ b/nyx/config_panel.py
@@ -59,16 +59,7 @@ class ConfigEntry():
   def __init__(self, option, entry_type):
     self._option = option
     self._value_type = entry_type
-    self._man_entry = tor_manual().config_options.get(option)
-
-  def category(self):
-    """
-    Provides the category of this configuration option.
-
-    :returns: **Category** this option belongs to
-    """
-
-    return self._man_entry.category if self._man_entry else stem.manual.Category.UNKNOWN
+    self._man_entry = tor_manual().config_options.get(option, stem.manual.ConfigOption(option))
 
   def option(self):
     """
@@ -110,15 +101,6 @@ class ConfigEntry():
 
     return self._value_type  # TODO: should this be an enum instead?
 
-  def summary(self):
-    """
-    Provides a summery of this configuration option.
-
-    :returns: short **str** description of the option
-    """
-
-    return self._man_entry.summary if self._man_entry else ''
-
   def manual_entry(self):
     """
     Provides the entry's man page entry.
@@ -147,7 +129,7 @@ class ConfigEntry():
     """
 
     if attr == SortAttr.CATEGORY:
-      return self.category()
+      return self.manual_entry().category
     elif attr == SortAttr.OPTION:
       return self.option()
     elif attr == SortAttr.VALUE:
@@ -155,11 +137,11 @@ class ConfigEntry():
     elif attr == SortAttr.VALUE_TYPE:
       return self.value_type()
     elif attr == SortAttr.USAGE:
-      return self._man_entry.usage if self._man_entry else ''
+      return self._man_entry.usage
     elif attr == SortAttr.SUMMARY:
-      return self.summary()
+      return self.manual_entry().summary
     elif attr == SortAttr.DESCRIPTION:
-      return self._man_entry.description if self._man_entry else ''
+      return self._man_entry.description
     elif attr == SortAttr.MAN_PAGE_ENTRY:
       return tor_manual().config_options.keys().index(self.option()) if self.option() in tor_manual().config_options else 99999  # sorts non-man entries last
     elif attr == SortAttr.IS_SET:
@@ -447,14 +429,14 @@ class ConfigPanel(panel.Panel):
       draw_line = line_number + DETAILS_HEIGHT + 2 - scroll_location
 
       line_format = [curses.A_BOLD if entry.is_set() else curses.A_NORMAL]
-      line_format += [CONFIG['attr.config.category_color'].get(entry.category(), 'white')]
+      line_format += [CONFIG['attr.config.category_color'].get(entry.manual_entry().category, 'white')]
 
       if entry == cursor_selection:
         line_format += [curses.A_STANDOUT]
 
       option_label = str_tools.crop(entry.option(), OPTION_WIDTH)
       value_label = str_tools.crop(entry.value(), value_width)
-      summary_label = str_tools.crop(entry.summary(), description_width, None)
+      summary_label = str_tools.crop(entry.manual_entry().summary, description_width, None)
       line_text_layout = '%%-%is %%-%is %%-%is' % (OPTION_WIDTH, value_width, description_width)
       line_text = line_text_layout % (option_label, value_label, summary_label)
 
@@ -479,12 +461,12 @@ class ConfigPanel(panel.Panel):
     if is_scrollbar_visible:
       self.addch(detail_panel_height, 1, curses.ACS_TTEE)
 
-    selection_format = (curses.A_BOLD, CONFIG['attr.config.category_color'].get(selection.category(), 'white'))
+    selection_format = (curses.A_BOLD, CONFIG['attr.config.category_color'].get(selection.manual_entry().category, 'white'))
 
     # first entry:
     # <option> (<category> Option)
 
-    option_label = ' (%s Option)' % selection.category()
+    option_label = ' (%s Option)' % selection.manual_entry().category
     self.addstr(1, 2, selection.option() + option_label, *selection_format)
 
     # second entry:
@@ -494,7 +476,7 @@ class ConfigPanel(panel.Panel):
       value_attr_label = ', '.join([
         'custom' if selection.is_set() else 'default',
         selection.value_type(),
-        'usage: %s' % (selection.manual_entry().usage if selection.manual_entry() else '')
+        'usage: %s' % (selection.manual_entry().usage)
       ])
 
       value_label_width = max(0, width - 12 - len(value_attr_label))
@@ -505,7 +487,7 @@ class ConfigPanel(panel.Panel):
     # remainder is filled with the man page description
 
     description_height = max(0, detail_panel_height - 3)
-    description_content = 'Description: %s' % (selection.manual_entry().description if selection.manual_entry() else '')
+    description_content = 'Description: %s' % (selection.manual_entry().description)
 
     for i in range(description_height):
       if not description_content:
diff --git a/nyx/connection_panel.py b/nyx/connection_panel.py
index 42ddebd..cf4286c 100644
--- a/nyx/connection_panel.py
+++ b/nyx/connection_panel.py
@@ -350,8 +350,10 @@ class ConnectionPanel(panel.Panel, threading.Thread):
         if not selection:
           break
 
+        def is_close_key(key):
+          return key.is_selection() or key.match('d') or key.match('left') or key.match('right')
+
         color = CONFIG['attr.connection.category_color'].get(selection.entry.get_type(), 'white')
-        is_close_key = lambda key: key.is_selection() or key.match('d') or key.match('left') or key.match('right')
         key = nyx.popups.show_descriptor_popup(selection.fingerprint, color, self.max_x, is_close_key)
 
         if not key or key.is_selection() or key.match('d'):
diff --git a/nyx/util/__init__.py b/nyx/util/__init__.py
index 13cb6db..c19b9c7 100644
--- a/nyx/util/__init__.py
+++ b/nyx/util/__init__.py
@@ -3,15 +3,6 @@ General purpose utilities for a variety of tasks supporting nyx features and
 safely working with curses (hiding some of the gory details).
 """
 
-__all__ = [
-  'log',
-  'panel',
-  'text_input',
-  'tor_config',
-  'tracker',
-  'ui_tools',
-]
-
 import os
 import sys
 
@@ -21,6 +12,15 @@ import stem.util.log
 
 from nyx.util import log
 
+__all__ = [
+  'log',
+  'panel',
+  'text_input',
+  'tor_config',
+  'tracker',
+  'ui_tools',
+]
+
 TOR_CONTROLLER = None
 BASE_DIR = os.path.sep.join(__file__.split(os.path.sep)[:-2])
 TESTING = False
diff --git a/nyx/util/tor_config.py b/nyx/util/tor_config.py
index f404d3d..dea1f09 100644
--- a/nyx/util/tor_config.py
+++ b/nyx/util/tor_config.py
@@ -4,7 +4,6 @@ Helper functions for working with tor's configuration file.
 
 import os
 import time
-import socket
 import threading
 
 import stem.version
diff --git a/test/settings.cfg b/test/settings.cfg
index d4aff84..21679cd 100644
--- a/test/settings.cfg
+++ b/test/settings.cfg
@@ -1,6 +1,7 @@
 # PEP8 compliance issues that we're ignoreing.
 
 pep8.ignore E111
+pep8.ignore E114
 pep8.ignore E121
 pep8.ignore E501
 pep8.ignore E251





More information about the tor-commits mailing list