当前位置: 首页>>代码示例>>Python>>正文


Python FileSystem.isdir方法代码示例

本文整理汇总了Python中FileSystem.FileSystem.isdir方法的典型用法代码示例。如果您正苦于以下问题:Python FileSystem.isdir方法的具体用法?Python FileSystem.isdir怎么用?Python FileSystem.isdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileSystem.FileSystem的用法示例。


在下文中一共展示了FileSystem.isdir方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MirroredDirectory

# 需要导入模块: from FileSystem import FileSystem [as 别名]
# 或者: from FileSystem.FileSystem import isdir [as 别名]

#.........这里部分代码省略.........
    def getOriginalFileName(self):
        if self._kind == self.KIND_IS_CLASS:
            return self.getFileName()
        elif self._kind == self.KIND_IS_TEST:
            return self.getTestFileName()
        elif self._kind == self.KIND_IS_DB_TEST:
            return self.getDbFileName()
        else:
            raise Exception("Unknown file type")

    def getToggledDir(self):
        if self._kind == self.KIND_IS_CLASS:
            return self.getTestFileDir()
        elif self._kind == self.KIND_IS_TEST:
            return self.getFileDir()
        elif self._kind == self.KIND_IS_DB_TEST:
            return self.getFileDir()
        else:
            raise Exception("Unknown file type")

    def getToggledFileName(self):
        if self._kind == self.KIND_IS_CLASS:
            return self.getTestFileName()
        elif self._kind == self.KIND_IS_TEST:
            return self.getFileName()
        elif self._kind == self.KIND_IS_DB_TEST:
            return self.getFileName()
        else:
            raise Exception("Unknown file type")

    def setBasePath(self, basePath):
        self.fileComponents.setBasePath(basePath)

    def getBasePath(self):
        result = self.fileComponents.getBasePath()
        if result is None:
            self._discoverBasePath()
            result = self.fileComponents.getBasePath()
        return result

    def getRelativeFileName(self):
        result = self.fileComponents.getRelativeFileName()
        if result is None:
            self._discoverBasePath()
            result = self.fileComponents.getRelativeFileName()
        return result 

    def setKind(self, kind):
        self._kind = kind

    def getKind(self):
        return self._kind

    def _discoverBasePathFromClassFile(self, aPath, searchTerm):
        folders = Std.dirExplode(aPath)
        result = False
        while len(folders) > 0:
            tempDir = Std.dirImplode(folders) + searchTerm
            if self.fileSystem.isdir(tempDir):
                if DEBUG: print("MirroredDirectory: directory '" + tempDir + "' exists")
                result = Std.dirImplode(folders)
                break
            currentFolder = folders.pop()
        return result 

    def _discoverBasePath(self):
        if not self.fileComponents.pathIsAbsolute(): return
        searchTerm = "Test"
        result = self._discoverBasePathFromClassFile(self.fileComponents.getDir(), searchTerm)
        if not result:
            if DEBUG: print("MirroredDirectory: base Path could not be discovered.")
        else:
            self.setBasePath(result)

    def _determineKind(self, fileName):
        result = MirroredDirectory.KIND_IS_CLASS
        fileName, ext = os.path.splitext(fileName)
        for kind, endings in Std.getIterItems(self._kindDict):
            for ending in endings:
                endingLen = len(ending)
                if len(fileName) > endingLen:
                    if fileName[-endingLen:] == ending:
                        result = kind
                        return result
        return result

    def _scrubPath(self, aPath, kind):
        if kind == MirroredDirectory.KIND_IS_CLASS:
            return aPath
        fileName, ext = os.path.splitext(aPath)
        folders = Std.dirExplode(fileName)
        result = False
        for searchTerm in self._kindDict[kind]:
            for i in range(len(folders)):
                currentFolder = folders[i]
                if len(currentFolder) > len(searchTerm):
                    ending = currentFolder[-len(searchTerm):]
                    if ending == searchTerm:
                        folders[i] = currentFolder[:-len(searchTerm)]
        return Std.dirImplode(folders) + ext
开发者ID:anconaesselmann,项目名称:LiveUnit,代码行数:104,代码来源:MirroredDirectory.py


注:本文中的FileSystem.FileSystem.isdir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。