11# -*- coding: utf-8 -*-
2- # Copyright (C) 2009-2010, 2012-2013, 2015-2016 Rocky Bernstein
2+ # Copyright (C) 2009-2010, 2012-2013, 2015-2016, 2020 Rocky Bernstein
33#
44# This program is free software: you can redistribute it and/or modify
55# it under the terms of the GNU General Public License as published by
@@ -32,17 +32,17 @@ class DebuggerSubcommand:
3232 """Base Class for Debugger subcommands. We pull in some helper
3333 functions for command from module cmdfns."""
3434
35- in_list = True # Show item in help list of commands
35+ in_list = True # Show item in help list of commands
3636
3737 # Run subcommand for those subcommands like "show"
3838 # which append current settings to list output.
39- run_cmd = True
39+ run_cmd = True
4040
4141 run_in_help = True # Run to get value in 'show' command?
42- min_abbrev = 1
43- min_args = 0
44- max_args = None
45- need_stack = False
42+ min_abbrev = 1
43+ min_args = 0
44+ max_args = None
45+ need_stack = False
4646
4747 def __init__ (self , cmd ):
4848 """cmd contains the command object that this
@@ -55,15 +55,15 @@ def __init__(self, cmd):
5555 # errmsg(), msg(), and msg_nocr() might. (See the note below
5656 # on these latter 3 methods.)
5757 #
58- self .proc = cmd .proc
59- self .core = cmd .core
58+ self .proc = cmd .proc
59+ self .core = cmd .core
6060 self .debugger = cmd .debugger
6161 self .settings = cmd .debugger .settings
6262
63- if not hasattr (self , ' short_help' ):
63+ if not hasattr (self , " short_help" ):
6464 help = self .__doc__ .split ("\n " )
6565 if len (help ) > 0 :
66- if help [0 ][0 ] == '*' and len (help ) > 2 :
66+ if help [0 ][0 ] == "*" and len (help ) > 2 :
6767 self .short_help = help [2 ]
6868 else :
6969 self .short_help = help [0 ]
@@ -75,20 +75,19 @@ def __init__(self, cmd):
7575 # that -- perhaps one may want to put several subcommands into
7676 # a single file. So in those cases, one will have to set self.name
7777 # accordingly by other means.
78- self .name = self .__module__ .split ('.' )[- 1 ]
78+ self .name = self .__module__ .split ("." )[- 1 ]
7979
8080 return
8181
8282 def columnize_commands (self , commands ):
8383 """List commands arranged in an aligned columns"""
8484 commands .sort ()
85- width = self .debugger .settings ['width' ]
86- return columnize .columnize (commands , displaywidth = width ,
87- lineprefix = ' ' )
85+ width = self .debugger .settings ["width" ]
86+ return columnize .columnize (commands , displaywidth = width , lineprefix = " " )
8887
8988 def confirm (self , msg , default = False ):
9089 """ Convenience short-hand for self.debugger.intf.confirm """
91- return ( self .debugger .intf [- 1 ].confirm (msg , default ) )
90+ return self .debugger .intf [- 1 ].confirm (msg , default )
9291
9392 # Note for errmsg, msg, and msg_nocr we don't want to simply make
9493 # an assignment of method names like self.msg = self.debugger.intf.msg,
@@ -98,22 +97,22 @@ def confirm(self, msg, default=False):
9897 # we wouldn't pick up that change in our self.msg
9998 def errmsg (self , msg ):
10099 """ Convenience short-hand for self.debugger.intf[-1].errmsg """
101- return ( self .debugger .intf [- 1 ].errmsg (msg ) )
100+ return self .debugger .intf [- 1 ].errmsg (msg )
102101
103102 def msg (self , msg ):
104103 """ Convenience short-hand for self.debugger.intf[-1].msg """
105- return ( self .debugger .intf [- 1 ].msg (msg ) )
104+ return self .debugger .intf [- 1 ].msg (msg )
106105
107106 def msg_nocr (self , msg ):
108107 """ Convenience short-hand for self.debugger.intf[-1].msg_nocr """
109- return ( self .debugger .intf [- 1 ].msg_nocr (msg ) )
108+ return self .debugger .intf [- 1 ].msg_nocr (msg )
110109
111110 aliases = ()
112- name = ' YourCommandName'
111+ name = " YourCommandName"
113112
114113 def rst_msg (self , text ):
115114 """Convenience short-hand for self.proc.rst_msg(text)"""
116- return ( self .proc .rst_msg (text ) )
115+ return self .proc .rst_msg (text )
117116
118117 def run (self ):
119118 """ The method that implements the debugger command.
@@ -122,54 +121,58 @@ def run(self):
122121 raise NotImplementedError (NotImplementedMessage )
123122
124123 def section (self , message , opts = {}):
125- if ' plain' != self .settings [' highlight' ]:
126- message = colorize (' bold' , message )
124+ if " plain" != self .settings [" highlight" ]:
125+ message = colorize (" bold" , message )
127126 else :
128- message += "\n " + '-' * len (message )
127+ message += "\n " + "-" * len (message )
129128 pass
130129 self .msg (message )
130+
131131 pass
132132
133- from trepan .processor import cmdfns as Mcmdfns
134- from trepan .lib import complete as Mcomplete
133+
134+ from trepan .processor .cmdfns import run_set_bool , run_show_bool , run_show_int
135+ from trepan .lib .complete import complete_token
135136
136137
137138class DebuggerSetBoolSubcommand (DebuggerSubcommand ):
138139 max_args = 1
139140
140141 def complete (self , prefix ):
141- result = Mcomplete . complete_token (('on' , ' off' ), prefix )
142+ result = complete_token (("on" , " off" ), prefix )
142143 return result
143144
144145 def run (self , args ):
145146 # Strip off ReStructuredText tags
146- doc = re .sub (' [*]' , '' , self .short_help ).lstrip ()
147+ doc = re .sub (" [*]" , "" , self .short_help ).lstrip ()
147148 # Take only the first two tokens
148- i = doc .find (' ' )
149+ i = doc .find (" " )
149150 if i > 0 :
150- j = doc .find (' ' , i + 1 )
151- if j > 0 : doc = doc [0 :j ]
151+ j = doc .find (" " , i + 1 )
152+ if j > 0 :
153+ doc = doc [0 :j ]
152154 pass
153- doc = doc .capitalize ().split (' \n ' )[0 ].rstrip ('.' )
154- Mcmdfns . run_set_bool (self , args )
155- Mcmdfns . run_show_bool (self , doc )
155+ doc = doc .capitalize ().split (" \n " )[0 ].rstrip ("." )
156+ run_set_bool (self , args )
157+ run_show_bool (self , doc )
156158 return
157159
158160 def summary_help (self , subcmd_name , subcmd ):
159161 return self .msg_nocr ("%-12s: " % self .short_help )
162+
160163 pass
161164
162165
163166class DebuggerShowIntSubcommand (DebuggerSubcommand ):
164167 max_args = 0
165168
166169 def run (self , args ):
167- if hasattr (self , ' short_help' ):
170+ if hasattr (self , " short_help" ):
168171 short_help = self .short_help
169172 else :
170173 short_help = self .__doc__ [5 :].capitalize ()
171174 pass
172- Mcmdfns . run_show_int (self , short_help )
175+ run_show_int (self , short_help )
173176 return
174177
175178
@@ -178,12 +181,14 @@ class DebuggerShowBoolSubcommand(DebuggerSubcommand):
178181
179182 def run (self , args ):
180183 # Strip off ReStructuredText tags
181- doc = re .sub (' [*]' , '' , self .short_help )
182- doc = doc [5 :].capitalize ().split (' \n ' )[0 ].rstrip ('.' )
183- Mcmdfns . run_show_bool (self , doc )
184+ doc = re .sub (" [*]" , "" , self .short_help )
185+ doc = doc [5 :].capitalize ().split (" \n " )[0 ].rstrip ("." )
186+ run_show_bool (self , doc )
184187 return
185188
186- if __name__ == '__main__' :
187- from trepan .processor .command import mock
188- d , cp = mock .dbg_setup ()
189- dd = DebuggerSubcommand (cp .commands ['quit' ])
189+
190+ if __name__ == "__main__" :
191+ from trepan .processor .command .mock import dbg_setup
192+
193+ d , cp = dbg_setup ()
194+ dd = DebuggerSubcommand (cp .commands ["quit" ])
0 commit comments