Example #1
0
    def __init__(self):
        nyx.panel.Panel.__init__(self)

        self._contents = []
        self._scroller = nyx.curses.CursorScroller()
        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(DATA_DIR, 'manual')

        if os.path.exists(cached_manual_path):
            manual = stem.manual.Manual.from_cache(cached_manual_path)
        else:
            try:
                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 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():
                # Lines of the form "<option> <type>[ <documentation>]". Documentation
                # was apparently only in old tor versions like 0.2.1.25.

                if ' ' not in line:
                    continue

                line_comp = line.split()
                name, value_type = line_comp[0], line_comp[1]

                # skips private and virtual entries if not configured to show them

                if name.startswith('__') and not CONFIG[
                        'features.config.state.showPrivateOptions']:
                    continue
                elif value_type == 'Virtual' and not CONFIG[
                        'features.config.state.showVirtualOptions']:
                    continue

                self._contents.append(ConfigEntry(name, value_type, manual))

            self._contents = sorted(
                self._contents,
                key=lambda entry:
                [entry.sort_value(field) for field in self._sort_order])
        except stem.ControllerError as exc:
            log.warn(
                'Unable to determine the configuration options tor supports: %s'
                % exc)
Example #2
0
    def test_saving_manual(self):
        """
    Check that we can save and reload manuals.
    """

        manual = stem.manual.Manual.from_man(EXAMPLE_MAN_PATH)

        with tempfile.NamedTemporaryFile(prefix='saved_test_manual.') as tmp:
            manual.save(tmp.name)
            loaded_manual = stem.manual.Manual.from_cache(tmp.name)
            self.assertEqual(manual, loaded_manual)
Example #3
0
  def test_saving_manual(self):
    """
    Check that we can save and reload manuals.
    """

    manual = stem.manual.Manual.from_man(EXAMPLE_MAN_PATH)

    with tempfile.NamedTemporaryFile(prefix = 'saved_test_manual.') as tmp:
      manual.save(tmp.name)
      loaded_manual = stem.manual.Manual.from_cache(tmp.name)
      self.assertEqual(manual, loaded_manual)
Example #4
0
    def test_saving_manual_as_config(self):
        """
    Check that we can save and reload manuals as a config.
    """

        if not stem.manual.HAS_ENCODING_ARG:
            self.skipTest(
                '(man lacks --encoding arg on OSX, BSD and Slackware, #18660)')

        manual = stem.manual.Manual.from_man(EXAMPLE_MAN_PATH)

        with tempfile.NamedTemporaryFile(prefix='saved_test_manual.') as tmp:
            manual.save(tmp.name)
            loaded_manual = stem.manual.Manual.from_cache(tmp.name)
            self.assertEqual(manual, loaded_manual)
Example #5
0
    def test_saving_manual(self):
        """
    Check that we can save and reload manuals.
    """

        if not stem.util.system.is_available('man'):
            test.runner.skip(self, '(require man command)')
            return

        manual = stem.manual.Manual.from_man(EXAMPLE_MAN_PATH)

        with tempfile.NamedTemporaryFile(prefix='saved_test_manual.') as tmp:
            manual.save(tmp.name)
            loaded_manual = stem.manual.Manual.from_cache(tmp.name)
            self.assertEqual(manual, loaded_manual)
Example #6
0
  def test_saving_manual(self):
    """
    Check that we can save and reload manuals.
    """

    if not stem.util.system.is_available('man'):
      test.runner.skip(self, '(require man command)')
      return

    manual = stem.manual.Manual.from_man(EXAMPLE_MAN_PATH)

    with tempfile.NamedTemporaryFile(prefix = 'saved_test_manual.') as tmp:
      manual.save(tmp.name)
      loaded_manual = stem.manual.Manual.from_cache(tmp.name)
      self.assertEqual(manual, loaded_manual)
Example #7
0
  def __init__(self):
    nyx.panel.Panel.__init__(self)

    self._contents = []
    self._scroller = nyx.curses.CursorScroller()
    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(DATA_DIR, 'manual')

    if os.path.exists(cached_manual_path):
      manual = stem.manual.Manual.from_cache(cached_manual_path)
    else:
      try:
        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 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():
        # Lines of the form "<option> <type>[ <documentation>]". Documentation
        # was apparently only in old tor versions like 0.2.1.25.

        if ' ' not in line:
          continue

        line_comp = line.split()
        name, value_type = line_comp[0], line_comp[1]

        # skips private and virtual entries if not configured to show them

        if name.startswith('__') and not CONFIG['features.config.state.showPrivateOptions']:
          continue
        elif value_type == 'Virtual' and not CONFIG['features.config.state.showVirtualOptions']:
          continue

        self._contents.append(ConfigEntry(name, value_type, manual))

      self._contents = sorted(self._contents, key = lambda entry: [entry.sort_value(field) for field in self._sort_order])
    except stem.ControllerError as exc:
      log.warn('Unable to determine the configuration options tor supports: %s' % exc)