1. Список говнокодов пользователя omgiafs

    Всего: 1

  2. Python / Говнокод #7153

    −96

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    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)

    Мой первый говнокод :)

    Проходит по папке с расширениями Thunderbird, изменяя требуемую минимальную версию плагина на железно заданную maxVer. Вынужденно наговнокодено после обновления ТБ на версию 5.

    Прошу разобрать по косточкам, я Питон только изучаю. Дочитал Лутца до классов, почти всё накопал с помощью Гугля .

    omgiafs, 05 Июля 2011

    Комментарии (21)