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 setFileName(self, path, fromHistory=False): """Sets the file name""" try: content = getFileContent(path) except Exception as exc: logging.error(str(exc)) return renderedText, errors, warnings = renderMarkdown( self.getUUID(), content, path) if errors: for error in errors: logging.error(error) return if not fromHistory: # Need to add an entry for the new item newEntry = ViewEntry(path, (0, 0)) self.viewerHistory.addEntry(newEntry) self.__fName = path self.__viewer.setHtml(renderedText) if warnings: for warning in warnings: logging.warning(warning) mainWindow = GlobalData().mainWindow mainWindow.em.setTabText(mainWindow.em.currentIndex(), self.getShortName()) mainWindow.em.updateStatusBar()
def getGraphFromPlainDotFile(fName): """Parses file and builds a normalized graph""" if not os.path.exists(fName): raise Exception("Cannot open " + fName) # Not optimal however I don't care at the moment. # In most of the cases this will be an interactive call. return getGraphFromPlainDotData(getFileContent(fName))
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 getBreakpointLines(fileName, srcCode, enforceRecalc=False, saveToCache=True): """Provides a set of breakable lines""" global validBreakPointLinesCache if not enforceRecalc: if fileName in validBreakPointLinesCache: return validBreakPointLinesCache[fileName] try: if srcCode is None: srcCode = getFileContent(fileName) lines = calcBreakpointLines(srcCode) if saveToCache: validBreakPointLinesCache[fileName] = lines return lines except: return None
def getOccurrences(editor, fileName, line=None, pos=None): """Provides occurences for the current editor position""" if editor is not None: line, pos = editor.cursorPosition line += 1 text = editor.text else: if pos > 0: pos -= 1 try: text = getFileContent(fileName) except Exception as exc: logging.error('Cannot read file ' + fileName + ': ' + str(exc)) return [] try: script = getJediScript(text, fileName) return script.get_references(line=line, column=pos) except Exception as exc: logging.error('jedi library failed to provide usages: ' + str(exc)) return []