def RunDebuggee(self): """Run rpdb2args""" flag, localpythonpath = ToolConfig.GetPythonExecutablePath("PyDbg") # TODO: convert errors to error codes and translate to meaningful # messages on main thread. if not flag: # No configured Python return [(u"No Python", localpythonpath, u"NA"),] # No rpdb2 found in plugin if not pkg_resources.resource_exists("rpdb2", "rpdb2.py"): return ["No rpdb2 found"] rpdb2_script = pkg_resources.resource_filename("rpdb2", "rpdb2.py") if wx.Platform == "__WXMSW__": self.rpdb2args += ["--pwd=%s" % RpdbDebugger.password] else: rpdb2_pw = GetPwdFile(RpdbDebugger.password) self.rpdb2args += ["--rid=%s" % rpdb2_pw] childPath, parentPath = PyStudioUtils.get_packageroot(self.filename) # Start rpdb2 cmdargs = "" debuggee = childPath if self.debuggerargs: cmdargs = self.debuggerargs.split(" ") for i, cmd in enumerate(cmdargs): if cmd == "%SCRIPT%": cmdargs[i] = debuggee elif cmd == "%MODULE%": debuggee = PyStudioUtils.get_modulepath(childPath) cmdargs[i] = debuggee cmdargs = self.rpdb2args + cmdargs else: cmdargs = self.rpdb2args + [debuggee,] allargs = cmdargs if self.programargs: allargs = allargs + self.programargs.split(" ") rpdb2_cmd = [localpythonpath, "-u", rpdb2_script] + allargs text = "" if self.pythonpath: text += "Using PYTHONPATH + %s\n" % u", ".join(self.pythonpath) text += "Rpdb2 command line: %s" % " ".join(rpdb2_cmd) text += "\nDirectory Variables file: %s\n\n" % self.dirvarfile self.debuggeewindow.SetText(_(text)) self.debuggeewindow.calldebugger = self.RunDebugger RpdbDebugger().do_abort() RpdbDebugger().debuggerattachedtext = self.debuggerattachedtext RpdbDebugger().debuggerdetachedtext = self.debuggerdetachedtext RpdbDebugger().remoteprocess = False self.processcreator = AsyncProcessCreator(self.debuggeewindow, self.UpdateOutput, "PyDbg", parentPath, rpdb2_cmd, self.pythonpath) self.processcreator.start() util.Log("[PyDbg][info] Rpdb2 command running")
def RunSyntaxCheck(self): """Run pylint""" flag, localpythonpath = ToolConfig.GetPythonExecutablePath("PyLint") if not flag: # No configured Python return ([(u"No Python", localpythonpath, u"NA")], u"None") childPath, parentPath = PyStudioUtils.get_packageroot(self.filename) # Start pylint modpath = PyStudioUtils.get_modulepath(childPath) allargs = self.pylintargs + [modpath,] pythoncode = "from pylint import lint;lint.Run(%s)" % repr(allargs) plint_cmd = [localpythonpath, "-c", pythoncode] processcreator = ProcessCreator("Pylint", parentPath, plint_cmd, self.pythonpath) process = processcreator.createprocess() stdoutdata, stderrdata = process.communicate() processcreator.restorepath() util.Log("[Pylint][info] stdout %s" % stdoutdata) util.Log("[Pylint][info] stderr %s" % stderrdata) stderrlower = stderrdata.lower() ind = stderrlower.find("importerror") if ind != -1: if stderrlower.find("pylint", ind) != -1: return ([(u"No Pylint", self.nopylinterror, u"NA")], u"None") # The parseable line format is: # '%(path)s:%(line)s: [%(sigle)s%(obj)s] %(msg)s' regex = re.compile(r"(.*):(.*): \[([A-Z])[, ]*(.*)\] (.*)%s" % os.linesep) rows = [] # TODO: returned messages need to be translatable if self.pythonpath: rows.append((u"***", u"Using PYTHONPATH + %s"\ % u", ".join(self.pythonpath), u"NA")) rows.append((u"***", u"Pylint command line: %s" % " ".join(plint_cmd), u"NA")) rows.append((u"***", u"Directory Variables file: %s" % self.dirvarfile, u"NA")) rowsdict = {} lastmatchindex = 0 for matcher in regex.finditer(stdoutdata): if matcher is None: continue mtypeabr = matcher.group(3) linenostr = matcher.group(2) classmeth = matcher.group(4) mtext = matcher.group(5) lastmatchindex = matcher.end(5) if mtypeabr in (u"E", u"F"): mtype = u"Error" elif mtypeabr == u"C": mtype = u"Convention" elif mtypeabr == u"R": mtype = u"Refactor" else: # TODO: add more specific filtering? / do translations on display mtype = u"Warning" outtext = mtext if classmeth: outtext = u"[%s] %s" % (classmeth, outtext) try: lineno = int(linenostr) mtyperows = rowsdict.get(mtype) if not mtyperows: mtyperows = {} rowsdict[mtype] = mtyperows linenorows = mtyperows.get(lineno) if not linenorows: linenorows = set() mtyperows[lineno] = linenorows linenorows.add(outtext) except: rows.append((mtype, outtext, linenostr)) for mtype in sorted(rowsdict): mtyperows = rowsdict[mtype] for lineno in sorted(mtyperows): linenorows = mtyperows[lineno] for outtext in sorted(linenorows): rows.append((mtype, outtext, lineno)) index = stdoutdata.find("Report", lastmatchindex) util.Log("[PyLint][info] Pylint command finished running") if index == -1: return (rows, "") return (rows, stdoutdata[index:].replace("\r", ""))
def OnCopyModulePath(self, editor, evt): path = os.path.normcase(editor.GetFileName()) if path is not None: childPath, foo = PyStudioUtils.get_packageroot(path) modulepath = PyStudioUtils.get_modulepath(childPath) util.SetClipboardText(modulepath)
def RunDebuggee(self): """Run rpdb2args""" flag, localpythonpath = ToolConfig.GetPythonExecutablePath("PyDbg") # TODO: convert errors to error codes and translate to meaningful # messages on main thread. if not flag: # No configured Python return [ (u"No Python", localpythonpath, u"NA"), ] # No rpdb2 found in plugin if not pkg_resources.resource_exists("rpdb2", "rpdb2.py"): return ["No rpdb2 found"] rpdb2_script = pkg_resources.resource_filename("rpdb2", "rpdb2.py") if wx.Platform == "__WXMSW__": self.rpdb2args += ["--pwd=%s" % RpdbDebugger.password] else: rpdb2_pw = GetPwdFile(RpdbDebugger.password) self.rpdb2args += ["--rid=%s" % rpdb2_pw] childPath, parentPath = PyStudioUtils.get_packageroot(self.filename) # Start rpdb2 cmdargs = "" debuggee = childPath if self.debuggerargs: cmdargs = self.debuggerargs.split(" ") for i, cmd in enumerate(cmdargs): if cmd == "%SCRIPT%": cmdargs[i] = debuggee elif cmd == "%MODULE%": debuggee = PyStudioUtils.get_modulepath(childPath) cmdargs[i] = debuggee cmdargs = self.rpdb2args + cmdargs else: cmdargs = self.rpdb2args + [ debuggee, ] allargs = cmdargs if self.programargs: allargs = allargs + self.programargs.split(" ") rpdb2_cmd = [localpythonpath, "-u", rpdb2_script] + allargs text = "" if self.pythonpath: text += "Using PYTHONPATH + %s\n" % u", ".join(self.pythonpath) text += "Rpdb2 command line: %s" % " ".join(rpdb2_cmd) text += "\nDirectory Variables file: %s\n\n" % self.dirvarfile self.debuggeewindow.SetText(_(text)) self.debuggeewindow.calldebugger = self.RunDebugger RpdbDebugger().do_abort() RpdbDebugger().debuggerattachedtext = self.debuggerattachedtext RpdbDebugger().debuggerdetachedtext = self.debuggerdetachedtext RpdbDebugger().remoteprocess = False self.processcreator = AsyncProcessCreator(self.debuggeewindow, self.UpdateOutput, "PyDbg", parentPath, rpdb2_cmd, self.pythonpath) self.processcreator.start() util.Log("[PyDbg][info] Rpdb2 command running")
def RunSyntaxCheck(self): """Run pylint""" flag, localpythonpath = ToolConfig.GetPythonExecutablePath("PyLint") if not flag: # No configured Python return ([(u"No Python", localpythonpath, u"NA")], u"None") childPath, parentPath = PyStudioUtils.get_packageroot(self.filename) # Start pylint modpath = PyStudioUtils.get_modulepath(childPath) allargs = self.pylintargs + [ modpath, ] pythoncode = "from pylint import lint;lint.Run(%s)" % repr(allargs) plint_cmd = [localpythonpath, "-c", pythoncode] processcreator = ProcessCreator("Pylint", parentPath, plint_cmd, self.pythonpath) process = processcreator.createprocess() stdoutdata, stderrdata = process.communicate() processcreator.restorepath() util.Log("[Pylint][info] stdout %s" % stdoutdata) util.Log("[Pylint][info] stderr %s" % stderrdata) stderrlower = stderrdata.lower() ind = stderrlower.find("importerror") if ind != -1: if stderrlower.find("pylint", ind) != -1: return ([(u"No Pylint", self.nopylinterror, u"NA")], u"None") # The parseable line format is: # '%(path)s:%(line)s: [%(sigle)s%(obj)s] %(msg)s' regex = re.compile(r"(.*):(.*): \[([A-Z])[, ]*(.*)\] (.*)%s" % os.linesep) rows = [] # TODO: returned messages need to be translatable if self.pythonpath: rows.append((u"***", u"Using PYTHONPATH + %s"\ % u", ".join(self.pythonpath), u"NA")) rows.append( (u"***", u"Pylint command line: %s" % " ".join(plint_cmd), u"NA")) rows.append( (u"***", u"Directory Variables file: %s" % self.dirvarfile, u"NA")) rowsdict = {} lastmatchindex = 0 for matcher in regex.finditer(stdoutdata): if matcher is None: continue mtypeabr = matcher.group(3) linenostr = matcher.group(2) classmeth = matcher.group(4) mtext = matcher.group(5) lastmatchindex = matcher.end(5) if mtypeabr in (u"E", u"F"): mtype = u"Error" elif mtypeabr == u"C": mtype = u"Convention" elif mtypeabr == u"R": mtype = u"Refactor" else: # TODO: add more specific filtering? / do translations on display mtype = u"Warning" outtext = mtext if classmeth: outtext = u"[%s] %s" % (classmeth, outtext) try: lineno = int(linenostr) mtyperows = rowsdict.get(mtype) if not mtyperows: mtyperows = {} rowsdict[mtype] = mtyperows linenorows = mtyperows.get(lineno) if not linenorows: linenorows = set() mtyperows[lineno] = linenorows linenorows.add(outtext) except: rows.append((mtype, outtext, linenostr)) for mtype in sorted(rowsdict): mtyperows = rowsdict[mtype] for lineno in sorted(mtyperows): linenorows = mtyperows[lineno] for outtext in sorted(linenorows): rows.append((mtype, outtext, lineno)) index = stdoutdata.find("Report", lastmatchindex) util.Log("[PyLint][info] Pylint command finished running") if index == -1: return (rows, "") return (rows, stdoutdata[index:].replace("\r", ""))
def OnCopyModulePath(self, editor, evt): path = os.path.normcase(editor.GetFileName()) if path is not None: childPath, foo = PyStudioUtils.get_packageroot(path) modulepath = PyStudioUtils.get_modulepath(childPath) util.SetClipboardText(modulepath)