Mistři v programování na #hovnokod

Python #435

import os
import codecs
from xml.dom import minidom

dir = 'C:\\Users\\pee\\AppData\\Roaming\\Thunderbird\\Profiles\\your_profile_here.default\\extensions'
target = 'install.rdf'
TB_id = '{3550f703-e582-4d05-9a08-453d09bdfdc6}'
maxVer = '5.*'

# open file, parse xml, find Thunderbird ID, change maxVersion, save file
def verchanger(rdf):
    found = False
    print(rdf)
    xmldoc = minidom.parse(rdf)
    idlist = xmldoc.getElementsByTagName("em:id")
    for i in idlist:
        if i._get_firstChild().nodeValue == TB_id:
            print('Thunderbird ID was founded in em:id node with index ', idlist.index(i)+1)
            print(i.parentNode.getElementsByTagName("em:maxVersion")[0]._get_firstChild().nodeValue)
            if i.parentNode.getElementsByTagName("em:maxVersion")[0]._get_firstChild().nodeValue == maxVer:
                print('file already updated, skipping')
                break
            else:
                found = True
                i.parentNode.getElementsByTagName("em:maxVersion")[0]._get_firstChild().nodeValue = maxVer
            print('new value is: ', i.parentNode.getElementsByTagName("em:maxVersion")[0]._get_firstChild().nodeValue )
    if found:
        xmldoc.writexml(codecs.open(rdf,'w','utf-8'), encoding='utf-8')


# get list of files with full paths
filelist = [dir + '\\' + x + '\\' + target for x in os.listdir(dir)]

for i in filelist:
    verchanger(i)

HovnoKod,