本文整理汇总了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