31 import lxml.etree
as le
32 from operator
import attrgetter
39 "filename": os.path.abspath(name),
40 "tmpfilename":
"." + prefix +
"." + os.path.basename(name)
56 for key
in sorted(elem.keys()):
57 keys.append(elem.get(key))
66 attrkeys = sorted(item.keys())
68 sorteditem.set(key, item.get(key))
88 items = sorted(items, key=sortbytext)
89 items = sorted(items, key=sortbytag)
95 newitem = le.Element(item.tag)
96 if item.text
and item.text.isspace()
is False:
97 newitem.text = item.text
106 newroot.append(newitem)
114 with open(fileobj[
'filename'],
'r') as original: 116 xmldoc = le.parse(original)
117 xmlroot = xmldoc.getroot()
121 newxmlroot = le.Element(xmlroot.tag)
128 newtree = le.ElementTree(newxmlroot)
129 with open(fileobj[
'tmpfilename'],
'wb')
as newfile:
130 newtree.write(newfile, pretty_print=
True)
143 if platform.system() ==
"Windows":
144 sp = subprocess.Popen([
"cmd",
"/c",
'diff ' +
145 filefrom[
'tmpfilename'] +
" " +
146 fileto[
'tmpfilename']],
147 stdout=subprocess.PIPE, shell=
True)
149 sp = subprocess.Popen([
'diff ' +
150 os.path.abspath(filefrom[
'tmpfilename']) +
151 " " + os.path.abspath(fileto[
'tmpfilename'])],
152 stdout=subprocess.PIPE, shell=
True)
153 stdout = sp.communicate()[0]
157 os.remove(filefrom[
'tmpfilename'])
158 os.remove(fileto[
'tmpfilename'])
def compareFiles(filename1, filename2)
def sortAttrs(item, sorteditem)
def createFileObj(prefix, name)
def sortElements(items, newroot)