示例#1
0
    def _post_run(self):
        r = self.command.result

        rows = list()
        found_at_least_one_listening_session = False
        for h in r.hook_files:
            sessions = h.remote_debug_sessions
            if not sessions:
                continue

            for s in sessions:
                state = s.state
                if state == 'listening':
                    found_at_least_one_listening_session = True
                    state = state + '*'

                row = [s.hook_name, s.pid, s.host, s.port, state]

                if s.state == 'connected':
                    row.append('%s:%d' % (s.dst_host, s.dst_port))
                else:
                    row.append('-')

                rows.append(row)

        if not rows:
            m = "No remote debug sessions found for repository '%s'.\n"
            sys.stdout.write(m % r.name)
            return

        header = ('Hook', 'PID', 'Host', 'Port', 'State', 'Connected')
        rows.insert(0, header)

        k = Dict()
        k.banner = (
            "Remote Debug Sessions for Repository '%s'" % r.name,
            "(%s)" % r.path,
        )
        if found_at_least_one_listening_session:
            k.footer = "(*) type 'telnet <host> <port>' to connect to session"

        k.formats = lambda: chain((str.rjust, ), repeat(str.center))
        k.output = sys.stdout
        #k.special = '='
        render_text_table(rows, **k)
示例#2
0
文件: cli.py 项目: smapjb/enversion
    def _post_run(self):
        r = self.command.result

        rows = list()
        found_at_least_one_listening_session = False
        for h in r.hook_files:
            sessions = h.remote_debug_sessions
            if not sessions:
                continue

            for s in sessions:
                state = s.state
                if state == 'listening':
                    found_at_least_one_listening_session = True
                    state = state + '*'

                row = [ s.hook_name, s.pid, s.host, s.port, state ]

                if s.state == 'connected':
                    row.append('%s:%d' % (s.dst_host, s.dst_port))
                else:
                    row.append('-')

                rows.append(row)

        if not rows:
            m = "No remote debug sessions found for repository '%s'.\n"
            sys.stdout.write(m % r.name)
            return

        header = ('Hook', 'PID', 'Host', 'Port', 'State', 'Connected')
        rows.insert(0, header)

        k = Dict()
        k.banner = (
            "Remote Debug Sessions for Repository '%s'" % r.name,
            "(%s)" % r.path,
        )
        if found_at_least_one_listening_session:
            k.footer = "(*) type 'telnet <host> <port>' to connect to session"

        k.formats = lambda: chain((str.rjust,), repeat(str.center))
        k.output = sys.stdout
        #k.special = '='
        render_text_table(rows, **k)
示例#3
0
    def _post_run(self):
        r = self.command.result

        rows = [(
            'Name',
            'Exists?',
            'Valid?',
            'Exe?',
            'Cnfgrd?',
            'Enbld?',
            'Rdb?',
        )]

        def _b(b):
            return 'Y' if bool(b) is True else 'N'

        enabled = 0
        configured = 0
        for h in r.hook_files:
            row = [h.name, _b(h.exists), '-']
            if not h.exists:
                row += ['-', '-', '-', '-']
            else:
                row += [
                    _b(h.executable),
                    _b(h.configured),
                    _b(h.enabled),
                    _b(h.remote_debug),
                ]

            if h.configured:
                configured += 1

            if h.enabled:
                enabled += 1

            rows.append(row)

        rows += [('=', ) * len(rows[0])]
        total = len(r.hook_files)
        eh = r.evn_hook_file
        row = [eh.name, _b(h.exists)]
        if not eh.exists:
            row += ['-', '-']
        else:
            row += [_b(eh.valid), _b(eh.executable)]
        row += [
            '%d/%d' % (configured, total),
            '%d/%d' % (enabled, total),
            '-',
        ]
        rows.append(row)

        k = Dict()
        k.banner = (
            "Repository Hook Status for '%s'" % r.name,
            "(%s)" % r.path,
        )
        if False:
            k.footer = (
                "type 'evn help hook-status' for info on columns",
                "type 'evn help fix-hooks' for info on fixing errors",
            )
        k.formats = lambda: chain((str.rjust, ), repeat(str.center))
        k.output = sys.stdout
        k.special = '='
        render_text_table(rows, **k)
示例#4
0
文件: cli.py 项目: smapjb/enversion
    def _post_run(self):
        r = self.command.result

        rows = [(
            'Name',
            'Exists?',
            'Valid?',
            'Exe?',
            'Cnfgrd?',
            'Enbld?',
            'Rdb?',
        )]

        def _b(b): return 'Y' if bool(b) is True else 'N'

        enabled = 0
        configured = 0
        for h in r.hook_files:
            row = [ h.name, _b(h.exists), '-' ]
            if not h.exists:
                row += [ '-', '-', '-', '-' ]
            else:
                row += [
                    _b(h.executable),
                    _b(h.configured),
                    _b(h.enabled),
                    _b(h.remote_debug),
                ]

            if h.configured:
                configured += 1

            if h.enabled:
                enabled += 1

            rows.append(row)

        rows += [ ('=',) * len(rows[0]) ]
        total = len(r.hook_files)
        eh = r.evn_hook_file
        row = [ eh.name, _b(h.exists) ]
        if not eh.exists:
            row += [ '-', '-' ]
        else:
            row += [ _b(eh.valid), _b(eh.executable) ]
        row += [
            '%d/%d' % (configured, total),
            '%d/%d' % (enabled, total),
            '-',
        ]
        rows.append(row)

        k = Dict()
        k.banner = (
            "Repository Hook Status for '%s'" % r.name,
            "(%s)" % r.path,
        )
        if False:
            k.footer = (
                "type 'evn help hook-status' for info on columns",
                "type 'evn help fix-hooks' for info on fixing errors",
            )
        k.formats = lambda: chain((str.rjust,), repeat(str.center))
        k.output = sys.stdout
        k.special = '='
        render_text_table(rows, **k)
示例#5
0
文件: cli.py 项目: tpn/enversion
    def _post_run(self):
        r = self.command.result

        i = count()
        rows = list()
        listening = list()
        for h in r.hook_files:
            sessions = h.remote_debug_sessions
            if not sessions:
                continue

            for s in sessions:
                state = s.state
                is_listening = False
                if state == 'listening':
                    is_listening = True
                    if not self._debug_:
                        state = state + '*'

                row = [ i.next(), s.hook_name, s.pid, s.host, s.port, state ]

                if s.state == 'connected':
                    row.append('%s:%d' % (s.dst_host, s.dst_port))
                else:
                    row.append('-')

                rows.append(row)

                if is_listening:
                    listening.append(row)

        if not rows:
            m = "No remote debug sessions found for repository '%s'.\n"
            sys.stdout.write(m % r.name)
            return

        header = ('ID', 'Hook', 'PID', 'Host', 'Port', 'State', 'Connected')
        rows.insert(0, header)

        k = Dict()
        k.banner = (
            "Remote Debug Sessions for Repository '%s'" % r.name,
            "(%s)" % r.path,
        )
        if not self._debug_:
            if len(listening) == 1:
                k.footer = (
                    "(*) type 'evnadmin debug %s' "
                    "to debug this session" % self.command.name
                )
            elif len(listening) > 1:
                # Ugh, this is highly unlikely and I can't think of a good way
                # to handle it at the moment.
                k.footer = '(*) multiple listeners?!'

        k.formats = lambda: chain((str.rjust,), repeat(str.center))
        k.output = sys.stdout
        #k.special = '='
        render_text_table(rows, **k)

        if not self._debug_:
            return

        if len(listening) != 1:
            return

        from telnetlib import Telnet
        listen = listening[0]
        host = listen[3]
        port = listen[4]
        t = Telnet(host, port)
        t.interact()