使用beatifulsoup更新InstallShield .ism(MSI)文件并保持其格式

时间:2013-07-25 06:29:58

标签: python unicode windows-installer beautifulsoup installshield

我正在尝试使用当前版本更新我的.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

我被困住了,想要一些指示,谢谢你的阅读!

1 个答案:

答案 0 :(得分:1)

您不需要更新ISM,只需将构建版本(以及许多其他内容)传递给编译器即可。如果您真的想要更新ISM,InstallShield提供了一个自动化界面。您打开项目,更新属性,然后保存并关闭项目。

此外,尽管我喜欢InstallShield,但ISM仅仅是底层MSI表数据的DTD XML转换。如果代码表达性确实是您的首要任务,那么基于WiX XSD的XML就是您的最佳选择。