コード例 #1
0
    def onFSChanged(self, items):
        """Triggered when filesystem has changes"""
        addedPythonFiles = []
        deletedPythonFiles = []

        for path in items:
            path = str(path)
            if path.endswith(os.path.sep):
                continue  # dirs are out of interest
            if path.startswith('+'):
                path = path[1:]
                if not isPythonFile(path):
                    continue
                addedPythonFiles.append(path)
            else:
                path = path[1:]
                if not isPythonFile(path):
                    continue
                deletedPythonFiles.append(path)
        if addedPythonFiles or deletedPythonFiles:
            if self.__model.onFSChanged(addedPythonFiles, deletedPythonFiles):
                # Need resort and counter updates
                self.layoutDisplay()
                self.updateCounter()
                self.model().setFilterRegExp("")
                self.sigModelFilesChanged.emit()
コード例 #2
0
 def __onSavedBufferAs(self, fileName, uuid):
     """Triggered when a file is saved with a new name"""
     if uuid in self.__flakesResults:
         if not isPythonFile(fileName):
             # It's not a python file anymore
             self.__currentUUID = None
             del self.__flakesResults[uuid]
             self.setFlakesNotAvailable(self.__uiLabel)
コード例 #3
0
 def __getFileTooltip(path):
     """Provides the python file docstring for a tooltip"""
     path = os.path.normpath(path)
     if os.path.exists(path):
         if isPythonFile(path):
             modInfo = GlobalData().briefModinfoCache.get(path)
             if modInfo.docstring is not None:
                 return modInfo.docstring.text
     return ''
コード例 #4
0
 def __getSytemWideImportDocstring(self, path):
     """Provides the system wide module docstring"""
     if isPythonFile(path):
         try:
             info = GlobalData().briefModinfoCache.get(path)
             if info.docstring is not None:
                 return info.docstring.text
         except:
             pass
     return ''
コード例 #5
0
 def __scanDirForPythonFiles(self, path):
     """Scans the directory for the python files recursively"""
     for item in os.listdir(path):
         if item in [".svn", ".cvs", '.git', '.hg']:
             continue
         if os.path.isdir(path + item):
             self.__scanDirForPythonFiles(path + item + os.path.sep)
             continue
         if isPythonFile(path + item):
             self.__participantFiles.append(os.path.realpath(path + item))
コード例 #6
0
ファイル: findinfiles.py プロジェクト: gridl/codimension
    def __extractDocstring(self, content):
        """Extracts a docstring and sets it as a tooltip if needed"""
        if self.tooltip != "":
            return

        if isPythonFile(self.fileName):
            info = getBriefModuleInfoFromMemory("\n".join(content))
            self.tooltip = ""
            if info.docstring is not None:
                self.tooltip = info.docstring.text
コード例 #7
0
 def __populateFromOpened(self):
     """Populates the name dialog from the opened files"""
     mainWindow = GlobalData().mainWindow
     editorsManager = mainWindow.editorsManagerWidget.editorsManager
     for record in editorsManager.getTextEditors():
         # uuid = record[0]
         fname = record[1]
         widget = record[2]
         if isPythonFile(fname):
             content = widget.getEditor().text()
             info = getBriefModuleInfoFromMemory(content)
             self.__populateInfo(info, fname)
コード例 #8
0
 def __populateFromProject(self):
     """Populates find name dialog from the project files"""
     mainWindow = GlobalData().mainWindow
     for fname in GlobalData().project.filesList:
         if isPythonFile(fname):
             widget = mainWindow.getWidgetForFileName(fname)
             if widget is None:
                 info = GlobalData().briefModinfoCache.get(fname)
             else:
                 info = getBriefModuleInfoFromMemory(
                     widget.getEditor().text)
             self.__populateInfo(info, fname)
コード例 #9
0
    def populateFileItem(self, parentItem, repopulate=False):
        """Populate a file item's subtree"""
        path = parentItem.getPath()
        if not isPythonFile(path):
            return

        parentItem.populated = True
        modInfo = self.globalData.briefModinfoCache.get(path)

        # Count the number of rows to insert
        count = 0
        if modInfo.encoding is not None:
            count += 1
        if modInfo.imports:
            count += 1
        if modInfo.globals:
            count += 1
        if modInfo.functions:
            count += 1
        if modInfo.classes:
            count += 1

        if count == 0:
            return

        # Insert rows
        if repopulate:
            self.beginInsertRows(
                self.createIndex(parentItem.row(), 0, parentItem), 0,
                count - 1)
        if modInfo.encoding is not None:
            node = TreeViewCodingItem(parentItem, modInfo.encoding)
            self._addItem(node, parentItem)

        if modInfo.imports:
            node = TreeViewImportsItem(parentItem, modInfo)
            self._addItem(node, parentItem)

        if modInfo.globals:
            node = TreeViewGlobalsItem(parentItem, modInfo)
            self._addItem(node, parentItem)

        if modInfo.functions:
            node = TreeViewFunctionsItem(parentItem, modInfo)
            self._addItem(node, parentItem)

        if modInfo.classes:
            node = TreeViewClassesItem(parentItem, modInfo)
            self._addItem(node, parentItem)

        if repopulate:
            self.endInsertRows()
コード例 #10
0
 def __populateModel(self):
     """Populates the project browser model"""
     self.clear()
     project = self.globalData.project
     cache = self.globalData.briefModinfoCache
     for fname in project.filesList:
         if isPythonFile(fname):
             info = cache.get(fname)
             for globalObj in info.globals:
                 item = TreeViewGlobalItem(self.rootItem, globalObj)
                 item.appendData([basename(fname), globalObj.line])
                 item.setPath(fname)
                 self.rootItem.appendChild(item)
コード例 #11
0
    def __init__(self, fileName, info=None, parent=None):
        QDialog.__init__(self, parent)

        if info is None:
            if not exists(fileName):
                raise Exception('Cannot open ' + fileName)

            if not isPythonFile(fileName):
                raise Exception('Unexpected file type (' + fileName +
                                '). A python file is expected.')

        self.__createLayout(fileName, info)
        self.setWindowTitle('Lexer/parser errors: ' + basename(fileName))
        self.show()
コード例 #12
0
    def onFileUpdated(self, fileName):
        """Triggered when the file is updated"""
        if not GlobalData().project.isProjectFile(fileName):
            # Not a project file
            return

        if not isPythonFile(fileName):
            return

        if self.__model.onFileUpdated(fileName):
            # Need resort and counter updates
            self.layoutDisplay()
            self.updateCounter()
            self.model().setFilterRegExp("")
コード例 #13
0
    def __onSavedBufferAs(self, fileName, uuid):
        """Triggered when a file is saved with a new name"""
        if uuid in self.__outlineBrowsers:
            baseName = os.path.basename(fileName)
            if not isPythonFile(fileName):
                # It's not a python file anymore
                if uuid == self.__currentUUID:
                    self.__outlineBrowsers[uuid].browser.hide()
                    self.__noneLabel.show()
                    self.__currentUUID = None

                del self.__outlineBrowsers[uuid]
                self.showParsingErrorsButton.setEnabled(False)
                self.findButton.setEnabled(False)
                return

            # Still python file with a different name
            browser = self.__outlineBrowsers[uuid].browser
            self.__outlineBrowsers[uuid].shortFileName = baseName
            if self.__outlineBrowsers[uuid].changed:
                title = self.__modifiedFormat % baseName
            else:
                title = baseName
            browser.model().sourceModel().updateRootData(0, title)
コード例 #14
0
    def __addSingleFileToDataModel(self, info, fName):
        """Adds a single file to the data model"""
        if fName.endswith('__init__.py'):
            if not info.classes and not info.functions and \
               not info.globals and not info.imports:
                # Skip dummy init files
                return

        modBox = DgmModule()
        modBox.refFile = fName

        modBox.kind = DgmModule.ModuleOfInterest
        modBox.title = self.__getModuleTitle(fName)

        self.__addBoxInfo(modBox, info)
        modBoxName = self.dataModel.addModule(modBox)
        self.__addDocstringBox(info, fName, modBoxName)

        # Analyze what was imported
        resolvedImports, errors = resolveImports(fName, info.imports)
        if errors:
            message = 'Errors while analyzing ' + fName + ':'
            for err in errors:
                message += '\n    ' + err
            logging.warning(message)

        for item in resolvedImports:
            importName = item[0]  # from name
            resolvedPath = item[1]  # 'built-in', None or absolute path
            importedNames = item[2]  # list of strings

            impBox = DgmModule()
            impBox.title = importName

            if self.__isLocalOrProject(fName, resolvedPath):
                impBox.kind = DgmModule.OtherProjectModule
                impBox.refFile = resolvedPath
                if isPythonFile(resolvedPath):
                    otherInfo = GlobalData().briefModinfoCache.get(
                        resolvedPath)
                    self.__addBoxInfo(impBox, otherInfo)
            else:
                if resolvedPath is None:
                    # e.g. 'import sys' will have None for the path
                    impBox.kind = DgmModule.UnknownModule
                elif os.path.isabs(resolvedPath):
                    impBox.kind = DgmModule.SystemWideModule
                    impBox.refFile = resolvedPath
                    impBox.docstring = \
                        self.__getSytemWideImportDocstring(resolvedPath)
                else:
                    # e.g. 'import time' will have 'built-in' in the path
                    impBox.kind = DgmModule.BuiltInModule

            impBoxName = self.dataModel.addModule(impBox)

            impConn = DgmConnection()
            impConn.kind = DgmConnection.ModuleDependency
            impConn.source = modBoxName
            impConn.target = impBoxName

            if self.__options.includeConnText:
                for impWhat in importedNames:
                    if impWhat:
                        impConn.labels.append(impWhat)
            self.dataModel.addConnection(impConn)
コード例 #15
0
 def __scanProjectDirs(self):
     """Populates participant lists from the project files"""
     for fName in GlobalData().project.filesList:
         if isPythonFile(fName):
             self.__participantFiles.append(fName)