def left_bar(percent, width): ''' Creates the green/left bar from a percentage and width. It uses some unicode vertical-bar characters to get some extra precision on the bar-length. ''' blocks = int(percent * width) remain = (percent * width) - blocks part = int(remain * 8) rpart = unichr(0x258f - 7 + part) # for smooth bar return (' ' * (width - blocks)) + colors.negative(colors.green(rpart)) + colors.green(('+' * (blocks)), bg='green')
def draw_bars(self): up = min(1.0, self._bandwidth[-1][0] / self._max) dn = min(1.0, self._bandwidth[-1][1] / self._max) kbup = self._bandwidth[-1][1] / 1024.0 kbdn = self._bandwidth[-1][0] / 1024.0 status = ' ' + colors.green('%.2f' % kbdn) status += '/' status += colors.red('%.2f' % kbup) # + ' KiB write' status += ' KiB/s' status += ' (%d streams, %d circuits)' % (self.streams(), self.circuits()) # include the paths of any currently-active streams streams = '' for stream in self._state.streams.values(): # ...there's a window during which it may not be attached yet if stream.circuit: circpath = '>'.join( map(lambda r: r.location.countrycode, stream.circuit.path)) streams += ' ' + circpath if len(streams) > 24: streams = streams[:21] + '...' print( left_bar(up, 20) + unichr(0x21f5) + right_bar(dn, 20) + status + streams)
def string_for_stream(state, stream): circ = '' if stream.circuit: circ = ' via circuit %d' % stream.circuit.id proc = txtorcon.util.process_from_address(stream.source_addr, stream.source_port, state) if proc: proc = ' from process "%s"' % (colors.bold(os.path.realpath('/proc/%d/exe' % proc)), ) elif stream.source_addr == '(Tor_internal)': proc = ' for Tor internal use' elif stream.source_addr: proc = ' from remote "%s:%s"' % (str(stream.source_addr), str(stream.source_port)) else: proc = '' hoststring = colors.bold('%s:%d' % (stream.target_host, stream.target_port)) return 'Stream %d to %s %s%s%s' % (stream.id, hoststring, colors.green('attached'), circ, proc)
def draw_bars(self): up = min(1.0, self._bandwidth[-1][0] / self._max) dn = min(1.0, self._bandwidth[-1][1] / self._max) kbup = self._bandwidth[-1][1] / 1024.0 kbdn = self._bandwidth[-1][0] / 1024.0 status = ' ' + colors.green('%.2f' % kbdn) + '/' # + ' KiB read' status += ', ' + colors.red('%.2f' % kbup) # + ' KiB write' status += ' (%d streams, %d circuits)' % (self.streams(), self.circuits()) # include the paths of any currently-active streams streams = '' for stream in self._state.streams.values(): # ...there's a window during which it may not be attached yet if stream.circuit: circpath = '>'.join(map(lambda r: r.location.countrycode, stream.circuit.path)) streams += ' ' + circpath if len(streams) > 24: streams = streams[:21] + '...' print(left_bar(up, 20) + unichr(0x21f5) + right_bar(dn, 20) + status + streams)
def string_for_stream(state, stream): circ = '' if stream.circuit: circ = ' via circuit %d' % stream.circuit.id proc = txtorcon.util.process_from_address(stream.source_addr, stream.source_port, state) if proc: proc = ' from process "%s"' % (colors.bold( os.path.realpath('/proc/%d/exe' % proc)), ) elif stream.source_addr == '(Tor_internal)': proc = ' for Tor internal use' elif stream.source_addr: proc = ' from remote "%s:%s"' % (str( stream.source_addr), str(stream.source_port)) else: proc = '' hoststring = colors.bold('%s:%d' % (stream.target_host, stream.target_port)) return 'Stream %d to %s %s%s%s' % (stream.id, hoststring, colors.green('attached'), circ, proc)