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

[tor-commits] [arm/master] Dropping unused tor_config functions



commit ee7dc7de5faa1b34f1055e59d18f1bf918b5aa16
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Jan 18 21:34:50 2014 -0800

    Dropping unused tor_config functions
    
    Primarily a function that generated a torrc from a template. This is something
    I wrote for our setup wizard which, while actually pretty neat, was unused and
    now removed. Nothing's using these functions so might as well drop 'em.
---
 arm/util/tor_config.py |  185 ------------------------------------------------
 1 file changed, 185 deletions(-)

diff --git a/arm/util/tor_config.py b/arm/util/tor_config.py
index 46db391..84d2882 100644
--- a/arm/util/tor_config.py
+++ b/arm/util/tor_config.py
@@ -1041,191 +1041,6 @@ class Torrc():
         log.warn(msg)
 
 
-def _test_config_descriptions():
-  """
-  Tester for the load_option_descriptions function, fetching the man page
-  contents and dumping its parsed results.
-  """
-
-  load_option_descriptions()
-  sorted_options = CONFIG_DESCRIPTIONS.keys()
-  sorted_options.sort()
-
-  for i in range(len(sorted_options)):
-    option = sorted_options[i]
-    argument, description = get_config_description(option)
-    opt_label = "OPTION: \"%s\"" % option
-    arg_label = "ARGUMENT: \"%s\"" % argument
-
-    print "     %-45s %s" % (opt_label, arg_label)
-    print "\"%s\"" % description
-
-    if i != len(sorted_options) - 1:
-      print "-" * 80
-
-
-def is_root_needed(torrc_path):
-  """
-  Returns True if the given torrc needs root permissions to be ran, False
-  otherwise. This raises an IOError if the torrc can't be read.
-
-  Arguments:
-    torrc_path - torrc to be checked
-  """
-
-  try:
-    torrc_file = open(torrc_path, "r")
-    torrc_lines = torrc_file.readlines()
-    torrc_file.close()
-
-    for line in torrc_lines:
-      line = line.strip()
-
-      is_port_opt = False
-
-      for opt in PORT_OPT:
-        if line.startswith(opt):
-          is_port_opt = True
-          break
-
-      if is_port_opt and " " in line:
-        arg = line.split(" ")[1]
-
-        if arg.isdigit() and int(arg) <= 1024 and int(arg) != 0:
-          return True
-
-    return False
-  except Exception as exc:
-    raise IOError(exc)
-
-
-def render_torrc(template, options, comment_indent = 30):
-  """
-  Uses the given template to generate a nicely formatted torrc with the given
-  options. The tempating language this recognizes is a simple one, recognizing
-  the following options:
-    [IF <option>]         # if <option> maps to true or a non-empty string
-    [IF NOT <option>]     # logical inverse
-    [IF <opt1> | <opt2>]  # logical or of the options
-    [ELSE]          # if the prior conditional evaluated to false
-    [END IF]        # ends the control block
-
-    [<option>]      # inputs the option value, omitting the line if it maps
-                    # to a boolean or empty string
-    [NEWLINE]       # empty line, otherwise templating white space is ignored
-
-  Arguments:
-    template      - torrc template lines used to generate the results
-    options       - mapping of keywords to their given values, with values
-                    being booleans or strings (possibly multi-line)
-    comment_indent - minimum column that comments align on
-  """
-
-  results = []
-  template_iter = iter(template)
-  comment_line_format = "%%-%is%%s" % comment_indent
-
-  try:
-    while True:
-      line = template_iter.next().strip()
-
-      if line.startswith("[IF ") and line.endswith("]"):
-        # checks if any of the conditional options are true or a non-empty string
-
-        evaluates_true = False
-
-        for cond in line[4:-1].split("|"):
-          is_inverse = False
-
-          if cond.startswith("NOT "):
-            is_inverse = True
-            cond = cond[4:]
-
-          if is_inverse != bool(options.get(cond.strip())):
-            evaluates_true = True
-            break
-
-        if evaluates_true:
-          continue
-        else:
-          # skips lines until we come to an else or the end of the block
-          depth = 0
-
-          while depth != -1:
-            line = template_iter.next().strip()
-
-            if line.startswith("[IF ") and line.endswith("]"):
-              depth += 1
-            elif line == "[END IF]":
-              depth -= 1
-            elif depth == 0 and line == "[ELSE]":
-              depth -= 1
-      elif line == "[ELSE]":
-        # an else block we aren't using - skip to the end of it
-        depth = 0
-
-        while depth != -1:
-          line = template_iter.next().strip()
-
-          if line.startswith("[IF "):
-            depth += 1
-          elif line == "[END IF]":
-            depth -= 1
-      elif line == "[NEWLINE]":
-        # explicit newline
-        results.append("")
-      elif line.startswith("#"):
-        # comment only
-        results.append(line)
-      elif line.startswith("[") and line.endswith("]"):
-        # completely dynamic entry
-
-        opt_value = options.get(line[1:-1])
-
-        if opt_value:
-          results.append(opt_value)
-      else:
-        # torrc option line
-
-        option, arg, comment = "", "", ""
-        parsed_line = line
-
-        if "#" in parsed_line:
-          parsed_line, comment = parsed_line.split("#", 1)
-          parsed_line = parsed_line.strip()
-          comment = "# %s" % comment.strip()
-
-        # parses the argument from the option
-
-        if " " in parsed_line.strip():
-          option, arg = parsed_line.split(" ", 1)
-          option = option.strip()
-        else:
-          log.info("torrc template option lacks an argument: '%s'" % line)
-          continue
-
-        # inputs dynamic arguments
-
-        if arg.startswith("[") and arg.endswith("]"):
-          arg = options.get(arg[1:-1])
-
-        # skips argument if it's false or an empty string
-
-        if not arg:
-          continue
-
-        torrc_entry = "%s %s" % (option, arg)
-
-        if comment:
-          results.append(comment_line_format % (torrc_entry + " ", comment))
-        else:
-          results.append(torrc_entry)
-  except StopIteration:
-    pass
-
-  return "\n".join(results)
-
-
 def load_configuration_descriptions(path_prefix):
   """
   Attempts to load descriptions for tor's configuration options, fetching them



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