mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-07-29 13:46:49 +00:00
kodi: fix appliance.xml merge
Only combine elements with matching attributes, fixes merge of appliance.xml
This commit is contained in:
parent
3739066e7c
commit
511b1d2b27
@ -11,6 +11,10 @@ from xml.etree import ElementTree as et
|
||||
def printerr(*args, **kwargs):
|
||||
print(*args, file=sys.stderr, **kwargs)
|
||||
|
||||
class hashabledict(dict):
|
||||
def __hash__(self):
|
||||
return hash(tuple(sorted(self.items())))
|
||||
|
||||
class XMLCombiner(object):
|
||||
def __init__(self, filenames):
|
||||
if len(filenames) == 0:
|
||||
@ -32,19 +36,19 @@ class XMLCombiner(object):
|
||||
return self.prettyPrint(self.roots[0])
|
||||
|
||||
def combine_element(self, one, other):
|
||||
mapping = {el.tag: el for el in one}
|
||||
mapping = {(el.tag, hashabledict(el.attrib)): el for el in one}
|
||||
for el in other:
|
||||
if len(el) == 0:
|
||||
try:
|
||||
mapping[el.tag].text = el.text
|
||||
mapping[(el.tag, hashabledict(el.attrib))].text = el.text
|
||||
except KeyError:
|
||||
mapping[el.tag] = el
|
||||
mapping[(el.tag, hashabledict(el.attrib))] = el
|
||||
one.append(el)
|
||||
else:
|
||||
try:
|
||||
self.combine_element(mapping[el.tag], el)
|
||||
self.combine_element(mapping[(el.tag, hashabledict(el.attrib))], el)
|
||||
except KeyError:
|
||||
mapping[el.tag] = el
|
||||
mapping[(el.tag, hashabledict(el.attrib))] = el
|
||||
one.append(el)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user