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


Python StringUtils.matches方法代码示例

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


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

示例1: modifyEnvFile

# 需要导入模块: from pyaid.string.StringUtils import StringUtils [as 别名]
# 或者: from pyaid.string.StringUtils.StringUtils import matches [as 别名]
    def modifyEnvFile(cls, target, install =True, test =False):
        """Doc..."""
        pathSep = OsUtils.getPerOsValue(u';', u':')

        nimblePath = FileUtils.createPath(
            FileUtils.getDirectoryOf(nimble.__file__),
            '..', isDir=True, noTail=True)

        pyaidPath = FileUtils.createPath(
            FileUtils.getDirectoryOf(pyaid.__file__),
            '..', isDir=True, noTail=True)

        pyglassPath = FileUtils.createPath(
            FileUtils.getDirectoryOf(pyglass.__file__),
            '..', isDir=True, noTail=True)

        removals  = []
        additions = [nimblePath]
        if not StringUtils.matches(pyaidPath, additions):
            additions.append(pyaidPath)

        if not StringUtils.matches(pyglassPath, additions):
            additions.append(pyglassPath)

        with open(target, 'r') as f:
            contents = f.read()

        result = cls._PYTHON_PATH_PATTERN.search(contents)
        if not result:
            if install:
                contents += (u'\n' if contents else u'') + u'PYTHONPATH=' + pathSep.join(additions)
            else:
                return cls.MAYA_ENV_MODIFIED_RESULT_NT([], [])
        else:
            paths = result.groupdict()['paths'].split(pathSep)
            index = 0
            while index < len(paths):
                if not additions:
                    break

                p = paths[index]

                # If path already exists don't add it again
                if p in additions:
                    additions.remove(p)
                    if not install:
                        removals.append(p)
                        paths.remove(p)
                    else:
                        index += 1
                    continue
                elif not install:
                    index += 1
                    continue

                # Remove unrecognized paths that import nimble, pyaid, or pyglass
                testPaths = [
                    FileUtils.createPath(p, u'nimble', isDir=True),
                    FileUtils.createPath(p, u'pyaid', isDir=True),
                    FileUtils.createPath(p, u'pyglass', isDir=True) ]
                for test in testPaths:
                    if os.path.exists(test):
                        paths.remove(p)
                        continue

                index += 1

            paths += additions
            contents = contents[:result.start()] + u'PYTHONPATH=' + pathSep.join(paths) \
                + u'\n' + contents[result.end():]

        result = cls.MAYA_ENV_MODIFIED_RESULT_NT(additions if install else [], removals)
        if test:
            return result

        with open(target, 'w') as f:
            f.write(contents)

        return result
开发者ID:Gorfaal,项目名称:Nimble,代码行数:81,代码来源:MayaEnvUtils.py


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