11#!/usr/bin/env python3
22# -*- coding: iso-8859-1 -*-
3- # Copyright (C) 2008-2010, 2013-2018, 2020-2023 Rocky Bernstein
3+ # Copyright (C) 2008-2010, 2013-2018, 2020-2024 Rocky Bernstein
44# <rocky@gnu.org>
55#
66# This program is free software: you can redistribute it and/or modify
2424
2525import pyficache
2626
27- package = "trepan"
27+ from trepan .client import run
28+ from trepan .clifns import whence_file
29+ from trepan .debugger import Trepan
30+ from trepan .exception import DebuggerQuit , DebuggerRestart
31+ from trepan .interfaces .server import ServerInterface
32+ from trepan .lib .file import is_compiled_py , readable
33+ from trepan .misc import wrapped_lines
34+ from trepan .options import postprocess_options , process_options
35+ from trepan .version import __version__
2836
29- # Our local modules
30- import trepan .client as Mclient
31- import trepan .clifns as Mclifns
32- import trepan .debugger as Mdebugger
33- import trepan .exception as Mexcept
34- import trepan .interfaces .server as Mserver
35- import trepan .lib .file as Mfile
36- import trepan .misc as Mmisc
37- import trepan .options as Moptions
37+ package = "trepan"
3838
3939# The name of the debugger we are currently going by.
4040__title__ = package
4141
42- from trepan .version import __version__
43-
4442
4543def main (dbg = None , sys_argv = list (sys .argv )):
4644 """Routine which gets run if we were invoked directly"""
4745 global __title__
4846
4947 # Save the original just for use in the restart that works via exec.
5048 orig_sys_argv = list (sys_argv )
51- opts , dbg_opts , sys_argv = Moptions .process_options (
52- __title__ , __version__ , sys_argv
53- )
49+ opts , dbg_opts , sys_argv = process_options (__title__ , __version__ , sys_argv )
5450
5551 if opts .server is not None :
5652 if opts .server == "tcp" :
5753 connection_opts = {"IO" : "TCP" , "PORT" : opts .port }
5854 else :
5955 connection_opts = {"IO" : "FIFO" }
60- intf = Mserver . ServerInterface (connection_opts = connection_opts )
56+ intf = ServerInterface (connection_opts = connection_opts )
6157 dbg_opts ["interface" ] = intf
6258 if "FIFO" == intf .server_type :
63- print ("Starting FIFO server for process %s." % os .getpid ())
59+ print (f "Starting FIFO server for process { os .getpid ()} ." )
6460 elif "TCP" == intf .server_type :
65- print ("Starting TCP server listening on port %s." % intf .inout .PORT )
61+ print (f "Starting TCP server listening on port { intf .inout .PORT } ." )
6662 pass
6763 elif opts .client :
68- Mclient . run (opts , sys_argv )
64+ run (opts , sys_argv )
6965 return
7066
7167 dbg_opts ["orig_sys_argv" ] = orig_sys_argv
7268
7369 if dbg is None :
74- dbg = Mdebugger . Trepan (dbg_opts )
70+ dbg = Trepan (dbg_opts )
7571 dbg .core .add_ignore (main )
76- pass
77- Moptions . _postprocess_options (dbg , opts )
72+
73+ postprocess_options (dbg , opts )
7874
7975 # process_options has munged sys.argv to remove any options that
8076 # options that belong to this debugger. The original options to
@@ -87,29 +83,17 @@ def main(dbg=None, sys_argv=list(sys.argv)):
8783 else :
8884 mainpyfile = sys_argv [0 ] # Get script filename.
8985 if not osp .isfile (mainpyfile ):
90- mainpyfile = Mclifns . whence_file (mainpyfile )
91- is_readable = Mfile . readable (mainpyfile )
86+ mainpyfile = whence_file (mainpyfile )
87+ is_readable = readable (mainpyfile )
9288 if is_readable is None :
93- print (
94- "%s: Python script file '%s' does not exist"
95- % (
96- __title__ ,
97- mainpyfile ,
98- )
99- )
89+ print (f"{ __title__ } : Python script file '{ mainpyfile } ' does not exist" )
10090 sys .exit (1 )
10191 elif not is_readable :
102- print (
103- "%s: Can't read Python script file '%s'"
104- % (
105- __title__ ,
106- mainpyfile ,
107- )
108- )
92+ print (f"{ __title__ } : Can't read Python script file '{ mainpyfile } '" )
10993 sys .exit (1 )
11094 return
11195
112- if Mfile . is_compiled_py (mainpyfile ):
96+ if is_compiled_py (mainpyfile ):
11397 try :
11498 from xdis import IS_PYPY , PYTHON_VERSION_TRIPLE , load_module
11599 from xdis .version_info import version_tuple_to_str
@@ -124,7 +108,7 @@ def main(dbg=None, sys_argv=list(sys.argv)):
124108 sip_hash ,
125109 ) = load_module (mainpyfile , code_objects = None , fast_load = False )
126110 if is_pypy != IS_PYPY :
127- print ("Bytecode is pypy %s , but we are %s." % ( is_pypy , IS_PYPY ) )
111+ print (f "Bytecode is pypy { is_pypy } , but we are { IS_PYPY } ." )
128112 print ("For a cross-version debugger, use trepan-xpy with x-python." )
129113 sys .exit (2 )
130114 if python_version [:2 ] != PYTHON_VERSION_TRIPLE [:2 ]:
@@ -146,15 +130,15 @@ def main(dbg=None, sys_argv=list(sys.argv)):
146130 + os .environ ["PATH" ].split (osp .pathsep )
147131 + ["." ]
148132 )
149- try_file = Mclifns . whence_file (py_file , dirnames )
133+ try_file = whence_file (py_file , dirnames )
150134
151135 if osp .isfile (try_file ):
152136 mainpyfile = try_file
153137 pass
154138 else :
155139 # Move onto the except branch
156140 raise IOError (
157- "Python file name embedded in code %s not found" % try_file
141+ f "Python file name embedded in code { try_file } not found"
158142 )
159143 except IOError :
160144 decompiler = "uncompyle6"
@@ -199,7 +183,7 @@ def write_wrapper(*args, **kwargs):
199183 decompile_file (mainpyfile , fd .file , mapstream = fd )
200184 except Exception :
201185 print (
202- "%s : error decompiling '%s'" % ( __title__ , mainpyfile ) ,
186+ f" { __title__ } : error decompiling '{ mainpyfile } '" ,
203187 file = sys .stderr ,
204188 )
205189 sys .exit (1 )
@@ -230,15 +214,9 @@ def write_wrapper(*args, **kwargs):
230214 # If mainpyfile is an optimized Python script try to find and
231215 # use non-optimized alternative.
232216 mainpyfile_noopt = pyficache .resolve_name_to_path (mainpyfile )
233- if mainpyfile != mainpyfile_noopt and Mfile .readable (mainpyfile_noopt ):
234- print ("%s: Compiled Python script given and we can't use that." % __title__ )
235- print (
236- "%s: Substituting non-compiled name: %s"
237- % (
238- __title__ ,
239- mainpyfile_noopt ,
240- )
241- )
217+ if mainpyfile != mainpyfile_noopt and readable (mainpyfile_noopt ):
218+ print (f"{ __title__ } : Compiled Python script given and we can't use that." )
219+ print (f"{ __title__ } : Substituting non-compiled name: { mainpyfile_noopt } " )
242220 mainpyfile = mainpyfile_noopt
243221 pass
244222
@@ -272,17 +250,15 @@ def write_wrapper(*args, **kwargs):
272250 dbg .core .execution_status = "Terminated"
273251 dbg .intf [- 1 ].msg ("The program finished - quit or restart" )
274252 dbg .core .processor .process_commands ()
275- except Mexcept . DebuggerQuit :
253+ except DebuggerQuit :
276254 break
277- except Mexcept . DebuggerRestart :
255+ except DebuggerRestart :
278256 dbg .core .execution_status = "Restart requested"
279257 if dbg .program_sys_argv :
280258 sys .argv = list (dbg .program_sys_argv )
281- part1 = "Restarting %s with arguments:" % dbg .core .filename (mainpyfile )
259+ part1 = f "Restarting { dbg .core .filename (mainpyfile )} with arguments:"
282260 args = " " .join (dbg .program_sys_argv [1 :])
283- dbg .intf [- 1 ].msg (
284- Mmisc .wrapped_lines (part1 , args , dbg .settings ["width" ])
285- )
261+ dbg .intf [- 1 ].msg (wrapped_lines (part1 , args , dbg .settings ["width" ]))
286262 else :
287263 break
288264 except SystemExit :
@@ -298,4 +274,3 @@ def write_wrapper(*args, **kwargs):
298274# When invoked as main program, invoke the debugger on a script
299275if __name__ == "__main__" :
300276 main ()
301- pass
0 commit comments