pythonunicodewindows-installerbeautifulsoupinstallshield

Updating InstallShield .ism (MSI) file with beatifulsoup and maintaining its formatting


I am trying to update my .ism files with a current build version. I have no problem finding and replacing the build string. However, I am struggling with having my .ism file maintain its formatting after being processed by beautiful soup. The following is my attempt at using beautiful soup to find and update build version string:

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

I'm stuck and would like some pointers and thank you for reading!


Solution

  • You don't need to update the ISM, you can just pass the build version (and many other things) into the compiler. If you really want to update the ISM, there is an automation interface provided by InstallShield. You open the project, update the property and then save and close the project.

    Also, as much as I like InstallShield, the ISM is merely a DTD XML transformation of the underlying MSI table data. If code expressiveness is really a priority to you, WiX XSD based XML is the way to go.