def get_changeset_kwds(cls, obj): k = Dict() k.conf = obj.conf k.estream = obj.estream k.ostream = obj.ostream k.istream = obj.istream k.options = obj.options return k
def run(self): RepositoryCommand.run(self) d = Dict() d.name = self.name d.path = self.path d.hook_dir = self.hook_dir t = dict() for hf in self.hook_files: assert hf.name not in t t[hf.name] = h = Dict() h.name = hf.name h.exists = hf.exists h.remote_debug = hf.is_remote_debug_enabled h.remote_debug_host = hf.remote_debug_host h.remote_debug_port = hf.remote_debug_port h.remote_debug_sessions = hf.remote_debug_sessions h.stale_remote_debug_sessions = hf.remote_debug_sessions h.invalid_remote_debug_sessions = hf.invalid_remote_debug_sessions if not h.exists: continue h.executable = hf.executable h.configured = hf.configured if not h.configured: continue h.enabled = hf.is_enabled d.hook_files = [ RepoHookFileStatus(**k) for k in t.values() ] eh = self.evn_hook_file h = Dict() h.name = eh.name h.exists = eh.exists if h.exists: h.valid = eh.is_valid h.executable = eh.executable d.evn_hook_file = EvnHookFileStatus(**h) self.result = RepoHookFilesStatus(**d)
def repo_kwds(self): k = Dict() k.fs = self.fs k.uri = self.uri k.conf = self.conf k.repo = self.repo k.path = self.path k.name = self.name k.istream = self.istream k.ostream = self.ostream k.estream = self.estream k.options = self.options k.r0_revprop_conf = self.r0_revprop_conf return k
def get_changeset_kwds_for_rev_or_txn(cls, obj, rev_or_txn, pool): k = Dict() k.fs = obj.fs #k.pool = pool k.conf = obj.conf k.estream = obj.estream k.ostream = obj.ostream k.istream = obj.istream k.options = obj.options #args = (k.fs, rev_or_txn, pool) args = (k.fs, rev_or_txn) k.root = ChangeSetCommand.get_root_for_rev_or_txn(*args) return k
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)
def run(self, args): k = Dict() k.prog = self._subcommand if self._usage_: k.usage = self._usage_ elif self._repo_: k.usage = '%prog [ options ] REPO_PATH' if self._description_: k.description = self._description_ if self._epilog_: k.epilog = self._epilog_ k.formatter = CommandHelpFormatter() self.parser = optparse.OptionParser(**k) if self._verbose_: assert self._quiet_ is None self.parser.add_option( '-v', '--verbose', dest='verbose', action='store_true', default=False, help="run in verbose mode [default: %default]" ) if self._quiet_: assert self._verbose_ is None self.parser.add_option( '-q', '--quiet', dest='quiet', action='store_true', default=False, help="run in quiet mode [default: %default]" ) if self._conf_: self.parser.add_option( '-c', '--conf', metavar='FILE', help="use alternate configuration file FILE" ) if self._hook_: self.parser.add_option( '-k', '--hook', #type='string', dest='hook_name', metavar='NAME', action='store', choices=list(self.conf.hook_names), help="hook name (i.e. 'pre-commit')" ) if self._rev_: assert self._rev_range_ is None self.parser.add_option( '-r', '--revision', dest='revision', metavar='ARG', action='store', default=None, help="revision [default: evn:last_rev]" ) if self._rev_range_: assert self._rev_ is None self.parser.add_option( '-r', dest='revision_range', metavar='ARG', action='store', default='0:HEAD', help="revision range [default: %default]" ) self._add_parser_options() (opts, self.args) = self.parser.parse_args(args) # Ignore variable argument commands altogether. if self._vargc_ is not True: arglen = len(self.args) if arglen == 0 and self._argc_ != 0: self.parser.print_help() self.parser.exit(status=1) if len(self.args) != self._argc_ and self._argc_ != 0: self.usage_error("invalid number of arguments") self.options = Options(opts.__dict__) self._pre_process_parser_results() f = None if self._conf_: f = self.options.conf if f and not os.path.exists(f): self.usage_error("configuration file '%s' does not exist" % f) self.conf.load(filename=f) self.command.conf = self.conf if self._repo_: if len(self.args) < 1: self.usage_error("missing REPO_PATH argument") self.command.path = self.args.pop(0) if self._hook_: hn = self.options.hook_name if not hn: self.usage_error("missing option: -k/--hook") self.command.hook_name = hn if self._rev_: self.command.rev_str = self.options.revision if self._rev_range_: assert self.options.revision_range self.command.revision_range = self.options.revision_range self.command.args = self.args self.command.options = self.options self._process_parser_results() with self.command: self.command.run() self._post_run()
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)
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()