GME  13
xme_fix_dup_guids.py
Go to the documentation of this file.
00001 import os
00002 import os.path
00003 import sys
00004 import uuid
00005 
00006 def fix_dups(filename, output_filename):
00007     from xml.etree import ElementTree
00008     xme = ElementTree.parse(filename)
00009     guid_map = {}
00010     for element in xme.iter():
00011         guid = element.get('guid')
00012         if guid:
00013             if guid_map.get(guid):
00014                 guid = element.attrib['guid'] = '{' + str(uuid.uuid4()) + '}'
00015             guid_map[guid] = 1
00016     
00017     with open(output_filename, 'wb') as output:
00018         output.write('<!DOCTYPE project SYSTEM "mga.dtd">\n')
00019         xme.write(output)
00020 
00021 if __name__ == '__main__':
00022     input = sys.argv[1]
00023     output = os.path.splitext(input)[0] + "_fixed.xme"
00024     fix_dups(input, output)