Newer
Older
Brad Payne (Vir Linden)
committed
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
"""\
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
Brad Payne (Vir Linden)
committed
def compare_matched_nodes(key,items,summary):
Brad Payne (Vir Linden)
committed
tags = list(set([e.tag for e in items]))
if len(tags) != 1:
Brad Payne (Vir Linden)
committed
summary.setdefault("tag_mismatch",0)
summary["tag_mismatch"] += 1
Brad Payne (Vir Linden)
committed
return
all_attrib = list(set(chain.from_iterable([list(e.attrib.keys()) for e in items])))
Brad Payne (Vir Linden)
committed
#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:
Brad Payne (Vir Linden)
committed
summary.setdefault("attr",{})
summary["attr"].setdefault(attr,0)
summary["attr"][attr] += 1
Brad Payne (Vir Linden)
committed
def compare_trees(file_trees):
Brad Payne (Vir Linden)
committed
summary = {}
Brad Payne (Vir Linden)
committed
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:
Brad Payne (Vir Linden)
committed
summary.setdefault("missing",0)
summary["missing"] += 1
Brad Payne (Vir Linden)
committed
else:
items.append(nodes[key])
Brad Payne (Vir Linden)
committed
compare_matched_nodes(key,items,summary)
Brad Payne (Vir Linden)
committed
def dump_appearance_params(tree):
vals = []
for e in tree.getroot().iter():
if e.tag == "param":
g = int(e.get("group"))
if g in [0,3]:
vals.append("{" + e.get("id") + "," +e.get("u8") + "}")
#print e.get("id"), e.get("name"), e.get("group"), e.get("u8")
if len(vals)==253:
Brad Payne (Vir Linden)
committed
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("--compare", help="compare flag", action="store_true")
parser.add_argument("--appearance_params", help="compare flag", action="store_true")
Brad Payne (Vir Linden)
committed
parser.add_argument("files", nargs="+", help="name of one or more archtype files")
args = parser.parse_args()
Brad Payne (Vir Linden)
committed
file_trees = [etree.parse(filename) for filename in args.files]
if args.compare:
compare_trees(file_trees)
if args.appearance_params:
dump_appearance_params(file_trees[0])