我正在尝试使用当前构建版本更新我的 .ism 文件。查找和替换构建字符串没有问题。但是,我正在努力让我的 .ism 文件在被美丽的汤处理后保持其格式。以下是我尝试使用美丽的汤来查找和更新构建版本字符串:
def upVerIsm(origFile,newFile):
openIsm = origFile
outputIsm = newFile
soup = BeautifulSoup(openIsm)
tblProp = soup.find("table", {"name":"Property"})
rows = tblProp.find_all("row")
for row in rows:
firstCell = row.contents[0].get_text()
if firstCell == "ProductVersion":
tmpProdVer = row.contents[1].string.replace_with(updVerStr)
if(flgMstrVer):
tblReg = soup.find("table", {"name":"Registry"})
# get all rows within registry table
rows = tblReg.find_all("row")
for row in rows:
td4 = row.contents[3].get_text()
if td4 == "MasterVersion":
td5 = row.contents[4].get_text()
tmpMstrStr = re.split('_',unicode(td5))
newBuildStr = tmpMstrStr[0] + "_" + tmpMstrStr[1] + "_" + tmpMstrStr[2] + "_B" + version_num
row.contents[4].string.replace_with(str(newBuildStr))
print row
# tmpIsm = soup.encode("ascii","ignore")
# updatedIsm = soup.prettify(formatter=None) # if i do this i get the ascii code error: (UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 666845: ordinal not in range(128))
updatedIsm = str(soup) # this alters the content of the .ism file and breaks the build
outputIsm.write(updatedIsm)
return outputIsm,openIsm # new,original files respectively
我被困住了,想要一些指示,感谢您的阅读!