1 回答
TA贡献1803条经验 获得超3个赞
一个简单的方法是使用第二个条件:
URL_PREFIX = "http://ourrepo:8081/artifactory"
nodePattern = re.compile(r'^.*-(ngwebui|nodeservice).*$')
dockerPattern = re.compile(r'patternForDocker')
if nodePattern.match(artifact):
return URL_PREFIX + "/npm-local/region/%s/-/region/%s-%s" % (artifact, artifact, version)
elif dockerPattern.match(artifact):
return URL_PREFIX + "docker/path/..."
else:
return URL_PREFIX + "/libs-releases-local/org/region/%s/%s/%s-%s" % (artifact, version, artifact, version)
但一种更具可扩展性的方法是创建模式和路径的映射:
URL_PREFIX = "http://ourrepo:8081/artifactory"
PATHS = {
'^.*-(ngwebui|nodeservice).*$': "/npm-local/region/%s/-/region/%s-%s" % (artifact, artifact, version),
'^patternForDocker$': "docker/path/...",
# other pairs
}
for pattern, path in PATHS.items():
compiled = re.compile(pattern)
if compiled.match(artifact):
return URL_PREFIX + path
return URL_PREFIX + "/libs-releases-local/org/region/%s/%s/%s-%s" % (artifact, version, artifact, version)
添加回答
举报