def __errorActivated( self, item, column ): " Handles the double click (or Enter) on the item " linePos = str( item.text( 1 ) ) if ":" in linePos: parts = linePos.split( ":" ) lineNumber = int( parts[ 0 ] ) pos = int( parts[ 1 ] ) else: lineNumber = int( linePos ) pos = 0 if self.__reportOption in [ self.SingleFile, self.DirectoryFiles, self.ProjectFiles ]: fileName = str( item.text( 0 ) ) else: # SingleBuffer if self.__reportFileName != "": if os.path.isabs( self.__reportFileName ): fileName = self.__reportFileName else: # Could be unsaved buffer, so try to search by the mainWindow = GlobalData().mainWindow widget = mainWindow.getWidgetByUUID( self.__reportUUID ) if widget is None: logging.error( "The unsaved buffer has been closed" ) return # The widget was found, so jump to the required editor = widget.getEditor() editor.gotoLine( lineNumber, pos ) editor.setFocus() return GlobalData().mainWindow.openFile( fileName, lineNumber, pos ) return
def search(self, expression): """Perform search within this item""" self.matches = [] if self.bufferUUID != "": # Search item is the currently loaded buffer mainWindow = GlobalData().mainWindow widget = mainWindow.getWidgetByUUID(self.bufferUUID) if widget is not None: # Search in the buffer self.__lookThroughLines(widget.getEditor().lines, expression) return # Here: there were no buffer or have not found it # try searching in a file if not isabs(self.fileName) or not exists(self.fileName): # Unfortunately not all network file systems report the # fact that a file has been deleted from the disk so # let's simply ignore such files return # File exists, search in the file try: content = getFileContent(self.fileName).splitlines() self.__lookThroughLines(content, expression) except Exception as exc: logging.error('Error searching in ' + self.fileName + ': ' + str(exc))
def search(self, expression): " Perform search within this item " self.matches = [] if self.bufferUUID != "": # Search item is the currently loaded buffer mainWindow = GlobalData().mainWindow widget = mainWindow.getWidgetByUUID(self.bufferUUID) if widget is not None: # Search in the buffer content = widget.getEditor().text().splitlines() self.__lookThroughLines(content, expression) return # Here: there were no buffer or have not found it # try searching in a file if not os.path.isabs( self.fileName ) or \ not os.path.exists( self.fileName ): # Unfortunately not all network file systems report the # fact that a file has been deleted from the disk so # let's simply ignore such files return # File exists, search in the file try: f = open(self.fileName) content = f.read().split("\n") f.close() self.__lookThroughLines(content, expression) except: logging.error("Cannot read " + self.fileName) return
def search( self, expression ): " Perform search within this item " self.matches = [] if self.bufferUUID != "": # Search item is the currently loaded buffer mainWindow = GlobalData().mainWindow widget = mainWindow.getWidgetByUUID( self.bufferUUID ) if widget is not None: # Search in the buffer content = widget.getEditor().text().splitlines() self.__lookThroughLines( content, expression ) return # Here: there were no buffer or have not found it # try searching in a file if not os.path.isabs( self.fileName ) or \ not os.path.exists( self.fileName ): # Unfortunately not all network file systems report the # fact that a file has been deleted from the disk so # let's simply ignore such files return # File exists, search in the file try: f = open( self.fileName ) content = f.read().split( "\n" ) f.close() self.__lookThroughLines( content, expression ) except: logging.error( "Cannot read " + self.fileName ) return
def __allItemActivated(self, item, column): " Handles the double click (or Enter) in the total results tree " # We process only the error messages and McCabe items hiddenColumnText = str(item.text(2)) if not hiddenColumnText in ["M", "E"]: return fileName = self.__getTreeItemFileName(item) lineNumber = 0 if hiddenColumnText == "M": # This is McCabe item objName = str(item.text(0)) self.__onMcCabeObject(objName, fileName) return elif hiddenColumnText == "E": # This is an error message message = str(item.text(0)) pos = message.find("at line") if pos == -1: logging.error("Unknown format of the message. " "Please inform the developers.") return parts = message[pos:].split() try: lineNumber = int(parts[2].replace(',', '')) except: logging.error("Unknown format of the message. " "Please inform the developers.") return if fileName == "": # This is an unsaved buffer, try to find the editor by UUID mainWindow = GlobalData().mainWindow widget = mainWindow.getWidgetByUUID(self.__reportUUID) if widget is None: logging.error("The unsaved buffer has been closed") return # The widget was found, so jump to the required editor = widget.getEditor() editor.gotoLine(lineNumber) editor.setFocus() return GlobalData().mainWindow.openFile(fileName, lineNumber) return
def __allItemActivated( self, item, column ): " Handles the double click (or Enter) in the total results tree " # We process only the error messages and McCabe items hiddenColumnText = str( item.text( 2 ) ) if not hiddenColumnText in [ "M", "E" ]: return fileName = self.__getTreeItemFileName( item ) lineNumber = 0 if hiddenColumnText == "M": # This is McCabe item objName = str( item.text( 0 ) ) self.__onMcCabeObject( objName, fileName ) return elif hiddenColumnText == "E": # This is an error message message = str( item.text( 0 ) ) pos = message.find( "at line" ) if pos == -1: logging.error( "Unknown format of the message. " "Please inform the developers." ) return parts = message[ pos: ].split() try: lineNumber = int( parts[ 2 ].replace( ',', '' ) ) except: logging.error( "Unknown format of the message. " "Please inform the developers." ) return if fileName == "": # This is an unsaved buffer, try to find the editor by UUID mainWindow = GlobalData().mainWindow widget = mainWindow.getWidgetByUUID( self.__reportUUID ) if widget is None: logging.error( "The unsaved buffer has been closed" ) return # The widget was found, so jump to the required editor = widget.getEditor() editor.gotoLine( lineNumber ) editor.setFocus() return GlobalData().mainWindow.openFile( fileName, lineNumber ) return
def addMatch(self, name, lineNumber, customMessage=None): """Used to add a match which was found outside of find in files""" match = Match(lineNumber, 0, 0) # Load the file and identify matched line and tooltip try: if self.bufferUUID != "": mainWindow = GlobalData().mainWindow widget = mainWindow.getWidgetByUUID(self.bufferUUID) if widget is not None: content = widget.getEditor().lines else: raise Exception('Inconsistency. Buffer disappeared.') else: content = getFileContent(self.fileName).splitlines() self.__fillInMatch(match, content, name, lineNumber, customMessage) except Exception as exc: logging.error('Error adding match: ' + str(exc)) self.matches.append(match)
def addMatch(self, name, lineNumber): " Used to add a match which was found outside of find in files " match = Match(lineNumber, 0, 0) # Load the file and identify matched line and tooltip try: if self.bufferUUID != "": mainWindow = GlobalData().mainWindow widget = mainWindow.getWidgetByUUID(self.bufferUUID) if widget is not None: content = widget.getEditor().text().splitlines() else: raise Exception("Inconsistency. Buffer disappeared.") else: f = open(self.fileName) content = f.read().split("\n") f.close() self.__fillInMatch(match, content, name, lineNumber) except: pass self.matches.append(match) return
def __errorActivated(self, item, column): " Handles the double click (or Enter) on the item " linePos = str(item.text(1)) if ":" in linePos: parts = linePos.split(":") lineNumber = int(parts[0]) pos = int(parts[1]) else: lineNumber = int(linePos) pos = 0 if self.__reportOption in [ self.SingleFile, self.DirectoryFiles, self.ProjectFiles ]: fileName = str(item.text(0)) else: # SingleBuffer if self.__reportFileName != "": if os.path.isabs(self.__reportFileName): fileName = self.__reportFileName else: # Could be unsaved buffer, so try to search by the mainWindow = GlobalData().mainWindow widget = mainWindow.getWidgetByUUID(self.__reportUUID) if widget is None: logging.error("The unsaved buffer has been closed") return # The widget was found, so jump to the required editor = widget.getEditor() editor.gotoLine(lineNumber, pos) editor.setFocus() return GlobalData().mainWindow.openFile(fileName, lineNumber, pos) return
def addMatch( self, name, lineNumber ): " Used to add a match which was found outside of find in files " match = Match( lineNumber, 0, 0 ) # Load the file and identify matched line and tooltip try: if self.bufferUUID != "": mainWindow = GlobalData().mainWindow widget = mainWindow.getWidgetByUUID( self.bufferUUID ) if widget is not None: content = widget.getEditor().text().splitlines() else: raise Exception( "Inconsistency. Buffer disappeared." ) else: f = open( self.fileName ) content = f.read().split( "\n" ) f.close() self.__fillInMatch( match, content, name, lineNumber ) except: pass self.matches.append( match ) return
def __onMcCabeObject(self, objName, fileName): " Called when the user activated McCabe item " info = None mainWindow = GlobalData().mainWindow widget = mainWindow.getWidgetByUUID(self.__reportUUID) if widget is None: if fileName == "": logging.error("The unsaved buffer has been closed") return # No widget, but we know the file name info = getBriefModuleInfoFromFile(fileName) else: # The widget was found editor = widget.getEditor() # The editor content has been modified, so re-parse the buffer info = getBriefModuleInfoFromMemory(editor.text()) parts = objName.split('.') currentIndex = 0 functionsContainer = info.functions classesContainer = info.classes line = -1 if objName == "__main__" and len(parts) == 1: # Special case - global file scope line = 1 currentIndex = 1 while currentIndex < len(parts): found = False for func in functionsContainer: if func.name == parts[currentIndex]: if currentIndex == len(parts) - 1: # Found, jump to the line line = func.line break functionsContainer = func.functions classesContainer = func.classes found = True break if line != -1: break if found: currentIndex += 1 continue for klass in classesContainer: if klass.name == parts[currentIndex]: if currentIndex == len(parts) - 1: # Found, jump to the line line = klass.line break functionsContainer = klass.functions classesContainer = klass.classes found = True if line != -1: break if found: currentIndex += 1 continue # Not found logging.error("Cannot find the " + objName) return # Here we have the line number if widget is None: GlobalData().mainWindow.openFile(fileName, line) else: editor = widget.getEditor() editor.gotoLine(line) editor.setFocus() return
def __onMcCabeObject( self, objName, fileName ): " Called when the user activated McCabe item " info = None mainWindow = GlobalData().mainWindow widget = mainWindow.getWidgetByUUID( self.__reportUUID ) if widget is None: if fileName == "": logging.error( "The unsaved buffer has been closed" ) return # No widget, but we know the file name info = getBriefModuleInfoFromFile( fileName ) else: # The widget was found editor = widget.getEditor() # The editor content has been modified, so re-parse the buffer info = getBriefModuleInfoFromMemory( editor.text() ) parts = objName.split( '.' ) currentIndex = 0 functionsContainer = info.functions classesContainer = info.classes line = -1 if objName == "__main__" and len( parts ) == 1: # Special case - global file scope line = 1 currentIndex = 1 while currentIndex < len( parts ): found = False for func in functionsContainer: if func.name == parts[ currentIndex ]: if currentIndex == len( parts ) - 1: # Found, jump to the line line = func.line break functionsContainer = func.functions classesContainer = func.classes found = True break if line != -1: break if found: currentIndex += 1 continue for klass in classesContainer: if klass.name == parts[ currentIndex ]: if currentIndex == len( parts ) - 1: # Found, jump to the line line = klass.line break functionsContainer = klass.functions classesContainer = klass.classes found = True if line != -1: break if found: currentIndex += 1 continue # Not found logging.error( "Cannot find the " + objName ) return # Here we have the line number if widget is None: GlobalData().mainWindow.openFile( fileName, line ) else: editor = widget.getEditor() editor.gotoLine( line ) editor.setFocus() return