示例#1
0
文件: graph.py 项目: special/carml
def right_bar(percent, width):
    '''
    See left_bar(); inverse and in red instead.
    '''
    blocks = int(percent * width)
    remain = (percent * width) - blocks

    part = int(remain * 8)
    rpart = unichr(0x258f - part) # for smooth bar
    if part == 0:
        rpart = ' '

    return colors.red('+' * (blocks), bg='red') + (colors.red(rpart)) + (' ' * (width - blocks))
示例#2
0
    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)
示例#3
0
文件: monitor.py 项目: david415/carml
def string_for_circuit(state, circuit):
    # path = '->'.join(map(lambda x: x.location.countrycode or '??', circuit.path))
    path = '->'.join(map(lambda x: x.name, circuit.path))
    state = circuit.state
    if state.lower() == 'failed':
        state = colors.red(state)
    return 'Circuit %d (%s) is %s for purpose "%s"' % (circuit.id, path, state, circuit.purpose)
示例#4
0
def string_for_circuit(state, circuit):
    # path = '->'.join(map(lambda x: x.location.countrycode or '??', circuit.path))
    path = '->'.join(map(lambda x: x.name, circuit.path))
    state = circuit.state
    if state.lower() == 'failed':
        state = colors.red(state)
    return 'Circuit %d (%s) is %s for purpose "%s"' % (circuit.id, path, state,
                                                       circuit.purpose)
示例#5
0
文件: graph.py 项目: david415/carml
    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)
示例#6
0
文件: monitor.py 项目: david415/carml
 def stream_failed(self, stream, remote_reason='', **kw):
     print('Stream %d %s because "%s"' % (stream.id, colors.red('failed'),
                                          colors.red(remote_reason)))
示例#7
0
文件: monitor.py 项目: david415/carml
 def error(fail):
     print(colors.red('Error:'), fail.getErrorMessage())
示例#8
0
文件: monitor.py 项目: david415/carml
 def circuit_closed(self, circuit, **kw):
     print('Circuit %d %s lasted %s (%s).' % (circuit.id,
                                              colors.red('closed'),
                                              humanize.time.naturaldelta(circuit.age()),
                                              flags(kw)))
示例#9
0
 def stream_failed(self, stream, remote_reason='', **kw):
     print('Stream %d %s because "%s"' %
           (stream.id, colors.red('failed'), colors.red(remote_reason)))
示例#10
0
 def error(fail):
     print(colors.red('Error:'), fail.getErrorMessage())
示例#11
0
 def circuit_closed(self, circuit, **kw):
     print('Circuit %d %s lasted %s (%s).' %
           (circuit.id, colors.red('closed'),
            humanize.time.naturaldelta(circuit.age()), flags(kw)))