Esempio n. 1
0
    def contains(self, sAbsPath):

        sLibPath = normCase(self.absPath())
        sPathDirs = pathSplitDirs(normCase(sAbsPath))

        numDirs = len(pathSplitDirs(sLibPath))
        sAlignedPath = pathJoin(*sPathDirs[:numDirs])

        return sAlignedPath == sLibPath
Esempio n. 2
0
    def sectionFromPath(self, sEntryPath, library=None):

        sEntryPath = normCase(sEntryPath)
        sEntryPathDirs = pathSplitDirs(normCase(sEntryPath))

        sectionDataList = sorted(self.iterSectionPaths(library=library),
                                 key=lambda x: len(x[2]),
                                 reverse=True)

        for sSpace, sSection, sSectionPath in sectionDataList:
            if pathStartsWith(sEntryPath, sSectionPath, pathSplits=sEntryPathDirs):
                return sSpace, sSection

        return "", ""
Esempio n. 3
0
    def resourceFromPath(self, sEntryPath):

        proj = self.project

        drcEntry = proj.entryFromPath(sEntryPath)
        if not drcEntry:
            return "", ""

        pubEntry = drcEntry if drcEntry.isPublic() else drcEntry.getPublicFile(fail=True)

        sPublicPath = normCase(pubEntry.absPath())

        pathIter = proj.iterRcPaths("public", self.confSection, tokens=vars(self))
        for sVar, sPath in pathIter:
            if normCase(sPath) == sPublicPath:
                return sVar, sPath
Esempio n. 4
0
    def _addDbNodeToCache(self, dbnode):

        sDbPath = dbnode.file

#        sAbsPath = self.dbToAbsPath(sDbPath)
#        if not self.contains(sAbsPath):
#            raise AssertionError(u"{} path not contained in {}: '{}'."
#                                 .format(dbnode, self, sDbPath))

        dbCacheKey = normCase(sDbPath)
        logMsg(u"caching: '{}'".format(dbCacheKey), log='debug')

        self._cachedDbNodes[dbCacheKey] = dbnode
Esempio n. 5
0
    def _checkLibraryPaths(self, noError=False):

        sMissingPathList = []

        sSamePathDct = {}

        for sSpace, sLibSection in self._iterLibrariesSpaceAndSection():

            sLibFullName = DrcLibrary.makeFullName(sSpace, sLibSection)
            sLibPath = self.getPath(sSpace, sLibSection)

            sSamePathDct.setdefault(normCase(sLibPath), []).append(sLibFullName)

            if not osp.isdir(sLibPath):

                if sSpace == "public":
                    msg = u"No such '{}': '{}'.".format(sLibFullName, sLibPath)
                    if noError:
                        logMsg(msg, warning=True)
                    else:
                        raise EnvironmentError(msg)
                elif sSpace == "private":
                    sMissingPathList.append((sLibFullName, sLibPath))

        sSamePathList = tuple((p, libs) for p, libs in sSamePathDct.iteritems() if len(libs) > 1)
        if sSamePathList:
            msgIter = (u"'{}': {}".format(p, libs) for p, libs in sSamePathList)
            msg = u"Libraries using the same path:\n\n    " + u"\n    ".join(msgIter)
            raise EnvironmentError(msg)

        if sMissingPathList:

            msgIter = (u"'{}': '{}'".format(n, p) for n, p in sMissingPathList)
            msg = u"No such libraries:\n" + u"\n".join(msgIter)

            sConfirm = confirmDialog(title='WARNING !',
                                     message=msg + u"\n\nShould I create them ?",
                                     button=['Yes', 'No'],
                                     defaultButton='No',
                                     cancelButton='No',
                                     dismissString='No',
                                     icon="warning")

            if sConfirm == 'No':
                return False

            for _, p in sMissingPathList:
                os.makedirs(p)

        return True
Esempio n. 6
0
    def getEntry(self, pathOrInfo, weak=False, drcType=None, dbNode=True):
        logMsg(log="all")
        """
        weak means that we do not check if the path exists.  
        """

        fileInfo = None
        sRelPath = ""

        if isinstance(pathOrInfo, QFileInfo):
            sAbsPath = pathOrInfo.absoluteFilePath()
            fileInfo = pathOrInfo
        elif isinstance(pathOrInfo, basestring):
            sAbsPath = pathNorm(pathOrInfo)
            if not osp.isabs(sAbsPath):
                sRelPath = sAbsPath
                sAbsPath = self.relToAbsPath(sRelPath)
        else:
            raise TypeError("argument 'pathOrInfo' must be of type <QFileInfo> \
                            or <basestring>. Got {}.".format(type(pathOrInfo)))

        # entries are cached using their relative path the the library they belong to.
        if not sRelPath:
            sRelPath = self.absToRelPath(sAbsPath) if osp.isabs(sAbsPath) else sAbsPath

        # try to get an already loaded entry...
        drcEntry = self._cachedEntries.get(normCase(sRelPath))
        if drcEntry:
            drcEntry.loadData(drcEntry._qfileinfo, dbNode=dbNode)
            if weak:
                return drcEntry
            else:
                return drcEntry if drcEntry.exists() else None

        if not weak:
            sIgnorePatterns = ("*.db", ".*")
            sName = osp.basename(sAbsPath)
            for sPattern in sIgnorePatterns:
                if fnmatch(sName, sPattern):
                    return None

        if not fileInfo:
            fileInfo = toQFileInfo(sAbsPath)

        cls = self.__class__
        # no cached entry found so let's instance a new one
        if weak:
            if drcType:
                rcCls = drcType
            else:
                rcCls = cls.classDir if sAbsPath.endswith('/') else cls.classFile
        else:
            if fileInfo.isDir():
                rcCls = cls.classDir
            elif fileInfo.isFile():
                rcCls = cls.classFile
            else:
                return None

        entry = rcCls(self, fileInfo, dbNode=dbNode)

        return entry