import os
import math
import re
def Generate_Batch_Scripts_mml(sourepath, templatepath, parentnode):
"""
根据模板中的MML,批量生成小区的MML脚本
template:MML模板,UCELLID=XXX,UNODEB=YYY
source:原始数据,如导出的CFGMML,主要是用于提取CELLID,以ADD UCELLSETUP中的小区为准
parentnode:(str)主键从父节点中获取,如CELLID从ADD UCELLSETUP中获取
return:result增量脚本结果
"""
# 1.获取主键
# 环境导出的CFGMML
soure = open(sourepath, 'r', encoding='utf-8')
lines1 = soure.readlines()
keywordlines = []
for l in lines1:
if parentnode.strip() in l:
res = re.search(r'ucellid=\d+', l).group()
keywordlines.append(res)
# print("keywordlines=", keywordlines, type(keywordlines))
soure.close()
# 2.获取模板替换主键并批量生成MML
# MML模板
template = open(templatepath, 'r', encoding='utf-8')
result = open(r"D:\pycharm\01 Get_MML\result.txt", 'w+', encoding='utf-8')
lines2 = template.readlines()
for l in keywordlines:
for ll in lines2:
result.writelines(ll.replace("ucellid=XXX", l.strip()))
result.writelines('\n')
template.close()
result.close()
return result
if __name__ == '__main__':
# 原数据路径
path_scr = r"D:\pycharm\01 Get_MML\119.txt"
# 功能:根据模板中的MML,批量生成小区脚本
# MML模板路径
path_template = r"D:\pycharm\01 Get_MML\template.txt"
parentnode = "add ultecell"
Generate_Batch_Scripts_mml(path_scr, path_template, parentnode)
|