Debugger/DebuggerInterfacePython.py

branch
maintenance
changeset 6646
51eefa621de4
parent 6645
ad476851d7e0
child 6716
1c9d3b369ea8
equal deleted inserted replaced
6603:77189681b787 6646:51eefa621de4
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 # Copyright (c) 2009 - 2018 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2009 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Module implementing the Python3 debugger interface for the debug server. 7 Module implementing the Python3 debugger interface for the debug server.
8 """ 8 """
107 if remote2local: 107 if remote2local:
108 return fn.replace(self.translateRemote, self.translateLocal) 108 return fn.replace(self.translateRemote, self.translateLocal)
109 else: 109 else:
110 return fn.replace(self.translateLocal, self.translateRemote) 110 return fn.replace(self.translateLocal, self.translateRemote)
111 111
112 def __startProcess(self, program, arguments, environment=None): 112 def __startProcess(self, program, arguments, environment=None,
113 workingDir=None):
113 """ 114 """
114 Private method to start the debugger client process. 115 Private method to start the debugger client process.
115 116
116 @param program name of the executable to start (string) 117 @param program name of the executable to start
117 @param arguments arguments to be passed to the program (list of string) 118 @type str
119 @param arguments arguments to be passed to the program
120 @type list of str
118 @param environment dictionary of environment settings to pass 121 @param environment dictionary of environment settings to pass
119 (dict of string) 122 @type dict of str
120 @return the process object (QProcess) or None 123 @param workingDir directory to start the debugger client in
124 @type str
125 @return the process object
126 @rtype QProcess or None
121 """ 127 """
122 proc = QProcess() 128 proc = QProcess()
123 if environment is not None: 129 if environment is not None:
124 env = QProcessEnvironment() 130 env = QProcessEnvironment()
125 for key, value in list(environment.items()): 131 for key, value in list(environment.items()):
126 env.insert(key, value) 132 env.insert(key, value)
127 proc.setProcessEnvironment(env) 133 proc.setProcessEnvironment(env)
128 args = arguments[:] 134 args = arguments[:]
135 if workingDir:
136 proc.setWorkingDirectory(workingDir)
129 proc.start(program, args) 137 proc.start(program, args)
130 if not proc.waitForStarted(10000): 138 if not proc.waitForStarted(10000):
131 proc = None 139 proc = None
132 140
133 return proc 141 return proc
134 142
135 def startRemote(self, port, runInConsole, venvName, originalPathString): 143 def startRemote(self, port, runInConsole, venvName, originalPathString,
144 workingDir=None):
136 """ 145 """
137 Public method to start a remote Python interpreter. 146 Public method to start a remote Python interpreter.
138 147
139 @param port port number the debug server is listening on 148 @param port port number the debug server is listening on
140 @type int 149 @type int
142 console window 151 console window
143 @type bool 152 @type bool
144 @param venvName name of the virtual environment to be used 153 @param venvName name of the virtual environment to be used
145 @type str 154 @type str
146 @param originalPathString original PATH environment variable 155 @param originalPathString original PATH environment variable
156 @type str
157 @param workingDir directory to start the debugger client in
147 @type str 158 @type str
148 @return client process object, a flag to indicate a network connection 159 @return client process object, a flag to indicate a network connection
149 and the name of the interpreter in case of a local execution 160 and the name of the interpreter in case of a local execution
150 @rtype tuple of (QProcess, bool, str) 161 @rtype tuple of (QProcess, bool, str)
151 """ 162 """
208 if rexec: 219 if rexec:
209 args = Utilities.parseOptionString(rexec) + \ 220 args = Utilities.parseOptionString(rexec) + \
210 [rhost, interpreter, debugClient, 221 [rhost, interpreter, debugClient,
211 noencoding, str(port), redirect, ipaddr] 222 noencoding, str(port), redirect, ipaddr]
212 args[0] = Utilities.getExecutablePath(args[0]) 223 args[0] = Utilities.getExecutablePath(args[0])
213 process = self.__startProcess(args[0], args[1:]) 224 process = self.__startProcess(args[0], args[1:],
225 workingDir=workingDir)
214 if process is None: 226 if process is None:
215 E5MessageBox.critical( 227 E5MessageBox.critical(
216 None, 228 None,
217 self.tr("Start Debugger"), 229 self.tr("Start Debugger"),
218 self.tr( 230 self.tr(
263 if ccmd: 275 if ccmd:
264 args = Utilities.parseOptionString(ccmd) + \ 276 args = Utilities.parseOptionString(ccmd) + \
265 [interpreter, os.path.abspath(debugClient), 277 [interpreter, os.path.abspath(debugClient),
266 noencoding, str(port), '0', ipaddr] 278 noencoding, str(port), '0', ipaddr]
267 args[0] = Utilities.getExecutablePath(args[0]) 279 args[0] = Utilities.getExecutablePath(args[0])
268 process = self.__startProcess(args[0], args[1:], clientEnv) 280 process = self.__startProcess(args[0], args[1:], clientEnv,
281 workingDir=workingDir)
269 if process is None: 282 if process is None:
270 E5MessageBox.critical( 283 E5MessageBox.critical(
271 None, 284 None,
272 self.tr("Start Debugger"), 285 self.tr("Start Debugger"),
273 self.tr( 286 self.tr(
276 return process, self.__isNetworked, interpreter 289 return process, self.__isNetworked, interpreter
277 290
278 process = self.__startProcess( 291 process = self.__startProcess(
279 interpreter, 292 interpreter,
280 [debugClient, noencoding, str(port), redirect, ipaddr], 293 [debugClient, noencoding, str(port), redirect, ipaddr],
281 clientEnv) 294 clientEnv,
295 workingDir=workingDir)
282 if process is None: 296 if process is None:
283 self.__startedVenv = "" 297 self.__startedVenv = ""
284 E5MessageBox.critical( 298 E5MessageBox.critical(
285 None, 299 None,
286 self.tr("Start Debugger"), 300 self.tr("Start Debugger"),
290 self.__startedVenv = venvName 304 self.__startedVenv = venvName
291 305
292 return process, self.__isNetworked, interpreter 306 return process, self.__isNetworked, interpreter
293 307
294 def startRemoteForProject(self, port, runInConsole, venvName, 308 def startRemoteForProject(self, port, runInConsole, venvName,
295 originalPathString): 309 originalPathString, workingDir=None):
296 """ 310 """
297 Public method to start a remote Python interpreter for a project. 311 Public method to start a remote Python interpreter for a project.
298 312
299 @param port port number the debug server is listening on 313 @param port port number the debug server is listening on
300 @type int 314 @type int
302 console window 316 console window
303 @type bool 317 @type bool
304 @param venvName name of the virtual environment to be used 318 @param venvName name of the virtual environment to be used
305 @type str 319 @type str
306 @param originalPathString original PATH environment variable 320 @param originalPathString original PATH environment variable
321 @type str
322 @param workingDir directory to start the debugger client in
307 @type str 323 @type str
308 @return client process object, a flag to indicate a network connection 324 @return client process object, a flag to indicate a network connection
309 and the name of the interpreter in case of a local execution 325 and the name of the interpreter in case of a local execution
310 @rtype tuple of (QProcess, bool, str) 326 @rtype tuple of (QProcess, bool, str)
311 """ 327 """
354 if rexec: 370 if rexec:
355 args = Utilities.parseOptionString(rexec) + \ 371 args = Utilities.parseOptionString(rexec) + \
356 [rhost, interpreter, os.path.abspath(debugClient), 372 [rhost, interpreter, os.path.abspath(debugClient),
357 noencoding, str(port), redirect, ipaddr] 373 noencoding, str(port), redirect, ipaddr]
358 args[0] = Utilities.getExecutablePath(args[0]) 374 args[0] = Utilities.getExecutablePath(args[0])
359 process = self.__startProcess(args[0], args[1:]) 375 process = self.__startProcess(args[0], args[1:],
376 workingDir=workingDir)
360 if process is None: 377 if process is None:
361 E5MessageBox.critical( 378 E5MessageBox.critical(
362 None, 379 None,
363 self.tr("Start Debugger"), 380 self.tr("Start Debugger"),
364 self.tr( 381 self.tr(
409 if ccmd: 426 if ccmd:
410 args = Utilities.parseOptionString(ccmd) + \ 427 args = Utilities.parseOptionString(ccmd) + \
411 [interpreter, os.path.abspath(debugClient), 428 [interpreter, os.path.abspath(debugClient),
412 noencoding, str(port), '0', ipaddr] 429 noencoding, str(port), '0', ipaddr]
413 args[0] = Utilities.getExecutablePath(args[0]) 430 args[0] = Utilities.getExecutablePath(args[0])
414 process = self.__startProcess(args[0], args[1:], clientEnv) 431 process = self.__startProcess(args[0], args[1:], clientEnv,
432 workingDir=workingDir)
415 if process is None: 433 if process is None:
416 E5MessageBox.critical( 434 E5MessageBox.critical(
417 None, 435 None,
418 self.tr("Start Debugger"), 436 self.tr("Start Debugger"),
419 self.tr( 437 self.tr(
422 return process, self.__isNetworked, interpreter 440 return process, self.__isNetworked, interpreter
423 441
424 process = self.__startProcess( 442 process = self.__startProcess(
425 interpreter, 443 interpreter,
426 [debugClient, noencoding, str(port), redirect, ipaddr], 444 [debugClient, noencoding, str(port), redirect, ipaddr],
427 clientEnv) 445 clientEnv,
446 workingDir=workingDir)
428 if process is None: 447 if process is None:
429 self.__startedVenv = "" 448 self.__startedVenv = ""
430 E5MessageBox.critical( 449 E5MessageBox.critical(
431 None, 450 None,
432 self.tr("Start Debugger"), 451 self.tr("Start Debugger"),
976 self.tr("""<p>The response received from the debugger""" 995 self.tr("""<p>The response received from the debugger"""
977 """ backend could not be decoded. Please report""" 996 """ backend could not be decoded. Please report"""
978 """ this issue with the received data to the""" 997 """ this issue with the received data to the"""
979 """ eric bugs email address.</p>""" 998 """ eric bugs email address.</p>"""
980 """<p>Error: {0}</p>""" 999 """<p>Error: {0}</p>"""
981 """<p>Data:<br/>{0}</p>""").format( 1000 """<p>Data:<br/>{1}</p>""").format(
982 str(err), Utilities.html_encode(jsonStr.strip())), 1001 str(err), Utilities.html_encode(jsonStr.strip())),
983 E5MessageBox.StandardButtons( 1002 E5MessageBox.StandardButtons(
984 E5MessageBox.Ok)) 1003 E5MessageBox.Ok))
985 return 1004 return
986 1005

eric ide

mercurial