1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19# 20#************************************************************** 21 22# usage: report.py <val.json> <kinds.json> [12|14|12x] -- groups errors by normalized message 23import sys, re, json, collections 24 25 26def norm(m): 27 m = re.sub(r'; expected .*', '', m) 28 m = re.sub(r' \(with xmlns.*', '', m) 29 return re.sub(r'value of attribute "([^"]+)" is invalid.*', r'value of attribute "\1" is invalid', m) 30 31 32val, out = sys.argv[1], sys.argv[2] 33ver = sys.argv[3] if len(sys.argv) > 3 else "12" 34d = json.load(open(val)) 35kinds = collections.defaultdict(lambda: {"errors": 0, "packages": set()}) 36for f, line, col, msg in d["errors"][ver]: 37 k = kinds[norm(msg) if f != "?" else "UNPARSED: " + msg] 38 k["errors"] += 1; k["packages"].add(f.split("/")[0]) 39res = {k: {"errors": v["errors"], "packages": sorted(v["packages"])} for k, v in kinds.items()} 40json.dump(res, open(out, "w"), indent=1, sort_keys=True) 41tot = sum(v["errors"] for v in res.values()) 42print(f"ODF {ver[0]}.{ver[1]}{' extended, foreign content removed' if ver.endswith('x') else ''}: {len(res)} kinds, {tot} errors, {len({p for v in res.values() for p in v['packages']})} packages with errors") 43for k, v in sorted(res.items(), key=lambda kv: -kv[1]["errors"]): 44 print(f" {v['errors']:5d} {len(v['packages']):4d} {k[:120]}") 45