mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
python style
This commit is contained in:
parent
40d76fdd68
commit
619c54b19b
1 changed files with 18 additions and 17 deletions
|
@ -3,34 +3,35 @@
|
||||||
import sys
|
import sys
|
||||||
from xml.dom import minidom
|
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):
|
def processNodes(base, custom):
|
||||||
customChild = custom.firstChild
|
baseChild = getFirstElementFrom(base.firstChild)
|
||||||
for baseChild in base.childNodes:
|
customChild = getFirstElementFrom(custom.firstChild)
|
||||||
if baseChild.nodeType != minidom.Node.ELEMENT_NODE:
|
while baseChild is not None:
|
||||||
continue
|
|
||||||
while customChild is not None and customChild.nodeType != minidom.Node.ELEMENT_NODE:
|
|
||||||
customChild = customChild.nextSibling
|
|
||||||
if baseChild.nodeName == 'node':
|
if baseChild.nodeName == 'node':
|
||||||
name = baseChild.getAttribute('name')
|
name = baseChild.getAttribute('name')
|
||||||
if name == '':
|
if name != '' and (customChild is None or name != customChild.getAttribute('name')):
|
||||||
continue
|
|
||||||
if customChild is None or name != customChild.getAttribute('name'):
|
|
||||||
newNode = custom.ownerDocument.createElement('node')
|
newNode = custom.ownerDocument.createElement('node')
|
||||||
newNode.setAttribute('name', name);
|
newNode.setAttribute('name', name)
|
||||||
value = baseChild.getAttribute('value')
|
value = baseChild.getAttribute('value')
|
||||||
if value != '':
|
if value != '':
|
||||||
newNode.setAttribute('value', value);
|
newNode.setAttribute('value', value)
|
||||||
newNode.setAttribute('toBeTranslated', 'true');
|
newNode.setAttribute('toBeTranslated', 'true')
|
||||||
customChild = custom.insertBefore(newNode, customChild)
|
customChild = custom.insertBefore(newNode, customChild)
|
||||||
processNodes(baseChild, customChild)
|
processNodes(baseChild, customChild)
|
||||||
customChild = customChild.nextSibling
|
baseChild = getFirstElementFrom(baseChild.nextSibling)
|
||||||
|
customChild = getFirstElementFrom(customChild.nextSibling)
|
||||||
|
|
||||||
if len(sys.argv) != 3:
|
if len(sys.argv) != 3:
|
||||||
print 'Usage: %s <en.xml> <custom.xml>' % sys.argv[0]
|
print 'Usage: %s <en.xml> <custom.xml>' % sys.argv[0]
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
base_model = minidom.parse(sys.argv[1])
|
baseModel = minidom.parse(sys.argv[1])
|
||||||
custom_model = minidom.parse(sys.argv[2])
|
customModel = minidom.parse(sys.argv[2])
|
||||||
|
|
||||||
processNodes(base_model, custom_model)
|
processNodes(baseModel, customModel)
|
||||||
print custom_model.toxml('UTF-8')
|
print customModel.toxml('UTF-8')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue