Esempio n. 1
0
    def test_short_time_label(self):
        """
    Checks the short_time_label() function.
    """

        # test the pydoc examples
        self.assertEqual('01:51', str_tools.short_time_label(111))
        self.assertEqual('6-07:08:20', str_tools.short_time_label(544100))

        self.assertEqual('00:00', str_tools.short_time_label(0))

        self.assertRaises(TypeError, str_tools.short_time_label, None)
        self.assertRaises(TypeError, str_tools.short_time_label, 'hello world')
        self.assertRaises(ValueError, str_tools.short_time_label, -5)
Esempio n. 2
0
  def test_short_time_label(self):
    """
    Checks the short_time_label() function.
    """

    # test the pydoc examples
    self.assertEqual('01:51', str_tools.short_time_label(111))
    self.assertEqual('6-07:08:20', str_tools.short_time_label(544100))

    self.assertEqual('00:00', str_tools.short_time_label(0))

    self.assertRaises(TypeError, str_tools.short_time_label, None)
    self.assertRaises(TypeError, str_tools.short_time_label, 'hello world')
    self.assertRaises(ValueError, str_tools.short_time_label, -5)
Esempio n. 3
0
  def _draw_resource_usage(self, x, y, width, vals):
    """
    System resource usage of the tor process...

      cpu: 0.0% tor, 1.0% nyx    mem: 0 (0.0%)       pid: 16329  uptime: 12-20:42:07
    """

    if vals.start_time:
      if not vals.is_connected:
        now = vals.connection_time
      elif self.is_paused():
        now = self.get_pause_time()
      else:
        now = time.time()

      uptime = str_tools.short_time_label(now - vals.start_time)
    else:
      uptime = ''

    sys_fields = (
      (0, vals.format('cpu: {tor_cpu}% tor, {nyx_cpu}% nyx')),
      (27, vals.format('mem: {memory} ({memory_percent}%)')),
      (47, vals.format('pid: {pid}')),
      (59, 'uptime: %s' % uptime),
    )

    for (start, label) in sys_fields:
      if width >= start + len(label):
        self.addstr(y, x + start, label)
      else:
        break
Esempio n. 4
0
def _draw_accounting_stats(subwindow, y, accounting):
  if tor_controller().is_alive():
    hibernate_color = CONFIG['attr.hibernate_color'].get(accounting.status, RED)

    x = subwindow.addstr(0, y, 'Accounting (', BOLD)
    x = subwindow.addstr(x, y, accounting.status, BOLD, hibernate_color)
    x = subwindow.addstr(x, y, ')', BOLD)

    subwindow.addstr(35, y, 'Time to reset: %s' % str_tools.short_time_label(accounting.time_until_reset))

    subwindow.addstr(2, y + 1, '%s / %s' % (_size_label(accounting.read_bytes), _size_label(accounting.read_limit)), PRIMARY_COLOR)
    subwindow.addstr(37, y + 1, '%s / %s' % (_size_label(accounting.written_bytes), _size_label(accounting.write_limit)), SECONDARY_COLOR)
  else:
    subwindow.addstr(0, y, 'Accounting:', BOLD)
    subwindow.addstr(12, y, 'Connection Closed...')
Esempio n. 5
0
def _draw_accounting_stats(subwindow, y, accounting):
  if tor_controller().is_alive():
    hibernate_color = CONFIG['attr.hibernate_color'].get(accounting.status, RED)

    x = subwindow.addstr(0, y, 'Accounting (', BOLD)
    x = subwindow.addstr(x, y, accounting.status, BOLD, hibernate_color)
    x = subwindow.addstr(x, y, ')', BOLD)

    subwindow.addstr(35, y, 'Time to reset: %s' % str_tools.short_time_label(accounting.time_until_reset))

    subwindow.addstr(2, y + 1, '%s / %s' % (_size_label(accounting.read_bytes), _size_label(accounting.read_limit)), PRIMARY_COLOR)
    subwindow.addstr(37, y + 1, '%s / %s' % (_size_label(accounting.written_bytes), _size_label(accounting.write_limit)), SECONDARY_COLOR)
  else:
    subwindow.addstr(0, y, 'Accounting:', BOLD)
    subwindow.addstr(12, y, 'Connection Closed...')
Esempio n. 6
0
  def _draw_accounting_stats(self, attr):
    y = DEFAULT_CONTENT_HEIGHT + attr.subgraph_height - 2

    if tor_controller().is_alive():
      hibernate_color = CONFIG['attr.hibernate_color'].get(attr.accounting.status, 'red')

      x = self.addstr(y, 0, 'Accounting (', curses.A_BOLD)
      x = self.addstr(y, x, attr.accounting.status, curses.A_BOLD, hibernate_color)
      x = self.addstr(y, x, ')', curses.A_BOLD)

      self.addstr(y, 35, 'Time to reset: %s' % str_tools.short_time_label(attr.accounting.time_until_reset))

      self.addstr(y + 1, 2, '%s / %s' % (attr.accounting.read_bytes, attr.accounting.read_limit), PRIMARY_COLOR)
      self.addstr(y + 1, 37, '%s / %s' % (attr.accounting.written_bytes, attr.accounting.write_limit), SECONDARY_COLOR)
    else:
      self.addstr(y, 0, 'Accounting:', curses.A_BOLD)
      self.addstr(y, 12, 'Connection Closed...')