0

我試圖用當前版本更新我的.ism文件。我沒有發現和替換構建字符串的問題。不過,我正在努力讓我的.ism文件在被美麗的湯加工後保持其格式。以下是我在嘗試用美麗的湯來查找和更新版本的字符串:用beatifulsoup更新InstallShield .ism(MSI)文件並保持其格式化

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

您不需要更新ISM,只需將構建版本(以及許多其他內容)傳遞給編譯器即可。如果您確實想要更新ISM,則會提供InstallShield提供的自動化界面。您打開該項目,更新該屬性,然後保存並關閉該項目。此外,儘管我喜歡InstallShield,但ISM僅僅是底層MSI表數據的DTD XML轉換。如果代碼表現力真的是您的優先考慮事項,那麼基於WiX XSD的XML就是您的選擇。

+1

謝謝你,克里斯托弗!我接手了另一個整天按下按鈕的人的構建過程,他向我展示瞭如何通過UI改變屬性的手動過程。我試圖自動化構建過程,我顯然沒有做我的功課,做一個簡單的「iscmdbld /?」 – user1951677

+0

ISCMDBLD是一種選擇。 MSBuild是另一個。我使用的是基於Workflow和MSBuild的TFS環境,因此它很好地集成在一起。 PS-歡迎來構建自動化! –

相關問題