Commit d9cfbc6e authored by 智勇's avatar 智勇

增加yaml文件

parent 3e672e71
{
"python.linting.pylintEnabled": false
}
\ No newline at end of file
# coding=UTF-8
from __future__ import print_function
import io
import yaml
import fileinput
import os
import os.path
import re
import copy
f = io.open('replace_config.yaml', 'r', encoding='utf-8')
res = yaml.load(f)
print("全部配置信息:", res)
# 查看配置中是否有当前项目
env = os.environ
project = env.get('SYSTEM_NAME')
distPath = os.path.abspath(project + '/dist')
config = res.get(project, res.get('common'))
print(project, "的配置信息:", config)
print("dist路径:", distPath)
# 根据内容进行替换
namespace = env.get('NAMESPACE')
print('namespace:', namespace)
files = []
acceptType = {'.html', '.js', '.css'}
def findFile (dir):
if os.path.isfile(dir):
suffix = os.path.splitext(dir)[-1]
if (suffix in acceptType):
files.append(dir)
return
else:
for sub in os.listdir(dir):
findFile(dir + '/' + sub)
# 过滤符合要求的文件路径
findFile(distPath)
# 替换文件中的内容
for file in files:
for line in fileinput.input(file, inplace = 1):
for item in config:
if not config[item]:
continue
rule = copy.deepcopy(config[item])
if rule.get('useNamespace', None) and rule['to']:
rule['to'] = '-' + namespace + rule['to']
if rule['reg']:
p = re.compile(r'' + rule['reg'])
line = re.sub(p, rule['to'], line)
print(line, end = '')
fileinput.close()
f.close()
\ No newline at end of file
# reg: 匹配的正则
# to: 正则匹配后替换需要的值
# useNamespace: 是否在替换的值前追加 '-[namespace名称]'
lkbDomain: &lkbDomain '.liangkebang.com'
# 替换xyqbapi
xyqbApiRule: &xyqbApiRule
reg: '(?<=\w).xyqb.com'
to: *lkbDomain
useNamespace: true
# 替换cookie,需要放在api规则后;或者需要改正则
xyqbCookieRule: &xyqbCookieRule
reg: '.xyqb.com'
to: *lkbDomain
qgApiRule: &qgApiRule
reg: '(?<=\w).q-gp.com'
to: *lkbDomain
useNamespace: true
# todo: 看哪个项目需要
h5AuthRule: &h5AuthRule
reg: 'h5.auth.quantgroup.cn'
to: 'operator.liangkebang.com'
# todo: quantgroup.cn
common: &common
xyqbApiRule: *xyqbApiRule
qgApiRule: *qgApiRule
xyqbCookieRule: *xyqbCookieRule
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment