Esempio n. 1
0
    def __init__(self,
                 fileName=None,
                 lineNumber=None,
                 condition="",
                 temporary=False,
                 enabled=True,
                 ignoreCount=0):
        if fileName is None:
            self.__fileName = fileName
        elif os.path.isabs(fileName):
            project = GlobalData().project
            if project.isLoaded():
                if project.isProjectFile(fileName):
                    # This is a project file; strip the project dir
                    self.__fileName = fileName.replace(project.getProjectDir(),
                                                       "")
                else:
                    # Not a project file, save as is
                    self.__fileName = fileName
            else:
                # Pretty much impossible
                self.__fileName = fileName
        else:
            # Relative path, i.e. a project file
            self.__fileName = fileName

        self.__lineNumber = lineNumber
        self.__condition = condition
        self.__temporary = temporary
        self.__enabled = enabled
        self.__ignoreCount = ignoreCount
Esempio n. 2
0
    def __getAutoDocFileName(fileName):
        """Forms the auto doc file name"""
        # Markdown is used as a default documentation format
        fBaseName = os.path.basename(fileName)
        if '.' in fBaseName:
            fileExtension = fBaseName.split('.')[-1]
            fBaseName = fBaseName[:-len(fileExtension)] + 'md'
        else:
            fBaseName += '.md'

        project = GlobalData().project
        if project.isProjectFile(fileName):
            projectDir = project.getProjectDir()
            relativePath = fileName[len(projectDir):]
            projectName = project.getProjectName()
            if relativePath.startswith(projectName):
                relativePath = relativePath.replace(projectName, '', 1)
            return os.path.normpath(
                os.path.sep.join([projectDir + 'doc',
                                  os.path.dirname(relativePath),
                                  fBaseName]))
        return os.path.normpath(
            os.path.sep.join([os.path.dirname(fileName),
                              'doc',
                               fBaseName]))
Esempio n. 3
0
    def __init__( self, fileName = None, lineNumber = None, condition = "",
                        temporary = False, enabled = True, ignoreCount = 0 ):

        if fileName is None:
            self.__fileName = fileName
        elif os.path.isabs( fileName ):
            project = GlobalData().project
            if project.isLoaded():
                if project.isProjectFile( fileName ):
                    # This is a project file; strip the project dir
                    self.__fileName = fileName.replace( project.getProjectDir(),
                                                        "" )
                else:
                    # Not a project file, save as is
                    self.__fileName = fileName
            else:
                # Pretty much impossible
                self.__fileName = fileName
        else:
            # Relative path, i.e. a project file
            self.__fileName = fileName

        self.__lineNumber = lineNumber
        self.__condition = condition
        self.__temporary = temporary
        self.__enabled = enabled
        self.__ignoreCount = ignoreCount

        return
Esempio n. 4
0
    def onAutoAddDoc(self):
        """Create a doc file, add a link and open for editing"""
        if not self.__actionPrerequisites():
            return

        selectedItem = self.selectedItems()[0]  # Exactly one is selected
        editor = selectedItem.getEditor()
        fileName = editor._parent.getFileName()
        if not fileName:
            logging.error('Save file before invoking auto doc')
            return

        needContent = False
        newAnchor = 'doc' + str(uuid.uuid4().fields[-1])[-6:]

        docFileName = self.__getAutoDocFileName(fileName)
        if not os.path.exists(docFileName):
            # Create file and populate with the default content
            try:
                os.makedirs(os.path.dirname(docFileName), exist_ok=True)
                with open(docFileName, 'w') as f:
                    pass
            except Exception as exc:
                logging.error('Error creating the documentation file ' +
                              docFileName + ': ' + str(exc))
                return
            needContent = True

        project = GlobalData().project
        if project.isProjectFile(docFileName):
            link = project.getRelativePath(docFileName)
        else:
            link = os.path.relpath(docFileName, fileName)

        # Insert a doc link
        with editor:
            lineNo = selectedItem.getFirstLine()
            line = CMLdoc.generate(link, newAnchor, 'See documentation',
                                   None, None, None,
                                   selectedItem.ref.body.beginPos)
            editor.insertLines(line, lineNo)

            QApplication.processEvents()
            self.parent().redrawNow()

        # Open the file
        if GlobalData().mainWindow.openFile(docFileName, -1):
            if needContent:
                widget = GlobalData().mainWindow.em.getWidgetForFileName(docFileName)
                editor = widget.getEditor()
                editor.text = getDefaultFileDoc(fileName, newAnchor)
                editor.document().setModified(False)