mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
CodeStyle: update xmlpretty.py
This commit is contained in:
parent
8fdbb36827
commit
3e4b931d18
@ -1,9 +1,20 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
import xml.dom.minidom as minidom
|
import xml.dom.minidom as minidom
|
||||||
from sys import exit, argv, stderr
|
from sys import exit, argv, stderr, stdout
|
||||||
import re
|
import re
|
||||||
|
import argparse
|
||||||
|
|
||||||
dom = minidom.parse(argv[1])
|
parser = argparse.ArgumentParser(description="Format XML")
|
||||||
|
parser.add_argument('infile', nargs=1)
|
||||||
|
parser.add_argument('outfile', nargs='?')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
f = open(args.infile[0],'r')
|
||||||
|
text = f.read()
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
dom = minidom.parseString(text)
|
||||||
|
|
||||||
def foreach_tree(doc, root, func, level=0):
|
def foreach_tree(doc, root, func, level=0):
|
||||||
func(doc, root, level)
|
func(doc, root, level)
|
||||||
@ -57,5 +68,14 @@ foreach_tree(dom, dom.documentElement, strip_text_whitespace)
|
|||||||
foreach_tree(dom, dom.documentElement, auto_indent)
|
foreach_tree(dom, dom.documentElement, auto_indent)
|
||||||
foreach_tree(dom, dom.documentElement, auto_space)
|
foreach_tree(dom, dom.documentElement, auto_space)
|
||||||
|
|
||||||
print "<?xml version='1.0'?>"
|
if args.outfile is not None:
|
||||||
print dom.documentElement.toxml()
|
f = open(args.outfile, 'w')
|
||||||
|
f.truncate()
|
||||||
|
else:
|
||||||
|
f = stdout
|
||||||
|
|
||||||
|
f.write("<?xml version='1.0'?>\n")
|
||||||
|
f.write(dom.documentElement.toxml())
|
||||||
|
f.write("\n")
|
||||||
|
|
||||||
|
f.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user