1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!runpy.sh
"""\
This module contains tools for comparing files output by LLVOAvatar::dumpArchetypeXML
$LicenseInfo:firstyear=2016&license=viewerlgpl$
Second Life Viewer Source Code
Copyright (C) 2016, Linden Research, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2.1 of the License only.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
$/LicenseInfo$
"""
import argparse
from lxml import etree
from itertools import chain
def node_key(e):
if e.tag == "param":
return e.tag + " " + e.get("id")
if e.tag == "texture":
return e.tag + " " + e.get("te")
if e.get("name"):
return e.tag + " " + e.get("name")
return None
def compare_matched_nodes(key,items):
tags = list(set([e.tag for e in items]))
if len(tags) != 1:
print "different tag types for key",key
return
all_attrib = list(set(chain.from_iterable([e.attrib.keys() for e in items])))
#print key,"all_attrib",all_attrib
for attr in all_attrib:
vals = [e.get(attr) for e in items]
#print "key",key,"attr",attr,"vals",vals
if len(set(vals)) != 1:
print "key",key,"attr",attr,"multiple values",vals
def compare_trees(file_trees):
print "compare_trees"
all_keys = list(set([node_key(e) for tree in file_trees for e in tree.getroot().iter() if node_key(e)]))
#print "keys",all_keys
tree_nodes = []
for i,tree in enumerate(file_trees):
nodes = dict((node_key(e),e) for e in tree.getroot().iter() if node_key(e))
tree_nodes.append(nodes)
for key in sorted(all_keys):
items = []
for nodes in tree_nodes:
if not key in nodes:
print "file",i,"missing item for key",key
else:
items.append(nodes[key])
compare_matched_nodes(key,items)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="compare avatar XML archetype files")
parser.add_argument("--verbose", help="verbose flag", action="store_true")
parser.add_argument("files", nargs="+", help="name of one or more archtype files")
args = parser.parse_args()
print "files",args.files
file_trees = [etree.parse(filename) for filename in args.files]
compare_trees(file_trees)
|