[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [nyx/master] Remove 'Save as...' option for saving torrc



commit daa1fb1bcbe3f8cfad4a19b420e88e2fe58163a3
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Jan 2 20:03:13 2016 -0800

    Remove 'Save as...' option for saving torrc
    
    If there's one thing I've learned after years of hearing from arm users it's
    that unnecessary options only breeds confusion. Why would someone want to
    persist their configuration to a different location? Could happen, but doubt an
    arm user's ever done it.
    
    Kinda impressed how much code went into supporting that. :P
---
 nyx/config_panel.py    |   38 ++++++------------
 nyx/util/tor_config.py |  103 ------------------------------------------------
 2 files changed, 11 insertions(+), 130 deletions(-)

diff --git a/nyx/config_panel.py b/nyx/config_panel.py
index 0083923..669e50e 100644
--- a/nyx/config_panel.py
+++ b/nyx/config_panel.py
@@ -11,7 +11,7 @@ import nyx.popups
 import stem.control
 import stem.manual
 
-from nyx.util import panel, tor_config, tor_controller, ui_tools
+from nyx.util import panel, tor_controller, ui_tools
 
 from stem.util import conf, enum, log, str_tools
 
@@ -197,7 +197,7 @@ class ConfigPanel(panel.Panel):
       self.redraw(True)
     elif key.match('s'):
       self.show_sort_dialog()
-    elif key.match('v'):
+    elif key.match('w'):
       self.show_write_dialog()
     else:
       return False
@@ -224,12 +224,11 @@ class ConfigPanel(panel.Panel):
         popup.redraw(True)  # recreates the window instance
         height = popup.get_preferred_size()[0]
 
-      selection = 2
+      selection = 1
 
       while True:
         height, width = popup.get_preferred_size()  # allow us to be resized
         popup.win.erase()
-        popup.addstr(0, 0, 'Configuration being saved:', curses.A_STANDOUT)
 
         for i, full_line in enumerate(config_lines):
           line = str_tools.crop(full_line, width - 2)
@@ -240,7 +239,7 @@ class ConfigPanel(panel.Panel):
 
         # selection options (drawn right to left)
 
-        selection_options = ('Save', 'Save As...', 'Cancel')
+        selection_options = ('Save', 'Cancel')
         draw_x = width - 1
 
         for option in reversed(selection_options):
@@ -257,6 +256,7 @@ class ConfigPanel(panel.Panel):
           draw_x -= 1  # gap between options
 
         popup.win.box()
+        popup.addstr(0, 0, 'Torrc configuration to save:', curses.A_STANDOUT)
         popup.win.refresh()
 
         key = nyx.controller.get_controller().key_input()
@@ -268,29 +268,13 @@ class ConfigPanel(panel.Panel):
         elif key.is_selection():
           break
 
-      if selection in (0, 1):
-        loaded_torrc, prompt_canceled = tor_config.get_torrc(), False
-
+      if selection == 0:
         try:
-          config_location = loaded_torrc.get_config_location()
-        except IOError:
-          config_location = ''
-
-        if selection == 1:
-          # prompts user for a configuration location
-          config_location = nyx.popups.input_prompt('Save to (esc to cancel): ', config_location)
-
-          if not config_location:
-            prompt_canceled = True
-
-        if not prompt_canceled:
-          try:
-            tor_config.save_conf(config_location, config_lines)
-            msg = 'Saved configuration to %s' % config_location
-          except IOError as exc:
-            msg = 'Unable to save configuration (%s)' % exc.strerror
+          tor_controller().save_conf()
+          nyx.popups.show_msg('Saved configuration to %s' % controller.get_info('config-file', '<unknown>'), 2)
+        except IOError as exc:
+          nyx.popups.show_msg('Unable to save configuration (%s)' % exc.strerror, 2)
 
-          nyx.popups.show_msg(msg, 2)
 
   def get_help(self):
     return [
@@ -299,7 +283,7 @@ class ConfigPanel(panel.Panel):
       ('page up', 'scroll up a page', None),
       ('page down', 'scroll down a page', None),
       ('enter', 'edit configuration option', None),
-      ('v', 'save configuration', None),
+      ('w', 'write torrc', None),
       ('a', 'toggle option filtering', None),
       ('s', 'sort ordering', None),
     ]
diff --git a/nyx/util/tor_config.py b/nyx/util/tor_config.py
index dea1f09..56c6a7f 100644
--- a/nyx/util/tor_config.py
+++ b/nyx/util/tor_config.py
@@ -125,109 +125,6 @@ def get_multiline_parameters():
   return tuple(MULTILINE_PARAM)
 
 
-def save_conf(destination = None, contents = None):
-  """
-  Saves the configuration to the given path. If this is equivilant to
-  issuing a SAVECONF (the contents and destination match what tor's using)
-  then that's done. Otherwise, this writes the contents directly. This raises
-  an IOError if unsuccessful.
-
-  Arguments:
-    destination - path to be saved to, the current config location if None
-    contents    - configuration to be saved, the current config if None
-  """
-
-  if destination:
-    destination = os.path.abspath(destination)
-
-  # fills default config values, and sets is_saveconf to false if they differ
-  # from the arguments
-
-  is_saveconf, start_time = True, time.time()
-
-  config_text = tor_controller().get_info('config-text', None)
-  current_config = config_text.splitlines() if config_text else []
-
-  if not contents:
-    contents = current_config
-  else:
-    is_saveconf &= contents == current_config
-
-  # The "GETINFO config-text" option was introduced in Tor version 0.2.2.7. If
-  # we're writing custom contents then this is fine, but if we're trying to
-  # save the current configuration then we need to fail if it's unavailable.
-  # Otherwise we'd write a blank torrc as per...
-  # https://trac.torproject.org/projects/tor/ticket/3614
-
-  if contents == ['']:
-    # double check that "GETINFO config-text" is unavailable rather than just
-    # giving an empty result
-
-    if tor_controller().get_info('config-text', None) is None:
-      raise IOError('determining the torrc requires Tor version 0.2.2.7')
-
-  current_location = None
-
-  try:
-    current_location = get_config_location()
-
-    if not destination:
-      destination = current_location
-    else:
-      is_saveconf &= destination == current_location
-  except IOError:
-    pass
-
-  if not destination:
-    raise IOError("unable to determine the torrc's path")
-
-  log_msg = 'Saved config by %%s to %s (runtime: %%0.4f)' % destination
-
-  # attempts SAVECONF if we're updating our torrc with the current state
-
-  if is_saveconf:
-    try:
-      tor_controller().save_conf()
-
-      try:
-        get_torrc().load()
-      except IOError:
-        pass
-
-      log.debug(log_msg % ('SAVECONF', time.time() - start_time))
-      return  # if successful then we're done
-    except:
-      pass
-
-  # if the SAVECONF fails or this is a custom save then write contents directly
-
-  try:
-    # make dir if the path doesn't already exist
-
-    base_dir = os.path.dirname(destination)
-
-    if not os.path.exists(base_dir):
-      os.makedirs(base_dir)
-
-    # saves the configuration to the file
-
-    config_file = open(destination, 'w')
-    config_file.write('\n'.join(contents))
-    config_file.close()
-  except (IOError, OSError) as exc:
-    raise IOError(exc)
-
-  # reloads the cached torrc if overwriting it
-
-  if destination == current_location:
-    try:
-      get_torrc().load()
-    except IOError:
-      pass
-
-  log.debug(log_msg % ('directly writing', time.time() - start_time))
-
-
 def validate(contents = None):
   """
   Performs validation on the given torrc contents, providing back a listing of



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits