1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 17:59:33 +02:00
FBReaderJ/scripts/resources/repair.py
2012-10-21 05:14:19 +04:00

38 lines
1.2 KiB
Python
Executable file

#!/usr/bin/python
import sys
from xml.dom import minidom
def getFirstElementFrom(node):
while node is not None and node.nodeType != minidom.Node.ELEMENT_NODE:
node = node.nextSibling
return node
def processNodes(base, custom):
baseChild = getFirstElementFrom(base.firstChild)
customChild = getFirstElementFrom(custom.firstChild)
while baseChild is not None:
if baseChild.nodeName == 'node':
name = baseChild.getAttribute('name')
if name != '' and (customChild is None or name != customChild.getAttribute('name')):
newNode = custom.ownerDocument.createElement('node')
newNode.setAttribute('name', name)
value = baseChild.getAttribute('value')
if value != '':
newNode.setAttribute('value', value)
newNode.setAttribute('toBeTranslated', 'true')
customChild = custom.insertBefore(newNode, customChild)
if customChild is not None:
processNodes(baseChild, customChild)
customChild = getFirstElementFrom(customChild.nextSibling)
baseChild = getFirstElementFrom(baseChild.nextSibling)
if len(sys.argv) != 3:
print 'Usage: %s <en.xml> <custom.xml>' % sys.argv[0]
exit(1)
baseModel = minidom.parse(sys.argv[1])
customModel = minidom.parse(sys.argv[2])
processNodes(baseModel, customModel)
print customModel.toxml('UTF-8')