1*0e16a31dSJim Jagielski#************************************************************** 2*0e16a31dSJim Jagielski# 3*0e16a31dSJim Jagielski# Licensed to the Apache Software Foundation (ASF) under one 4*0e16a31dSJim Jagielski# or more contributor license agreements. See the NOTICE file 5*0e16a31dSJim Jagielski# distributed with this work for additional information 6*0e16a31dSJim Jagielski# regarding copyright ownership. The ASF licenses this file 7*0e16a31dSJim Jagielski# to you under the Apache License, Version 2.0 (the 8*0e16a31dSJim Jagielski# "License"); you may not use this file except in compliance 9*0e16a31dSJim Jagielski# with the License. You may obtain a copy of the License at 10*0e16a31dSJim Jagielski# 11*0e16a31dSJim Jagielski# http://www.apache.org/licenses/LICENSE-2.0 12*0e16a31dSJim Jagielski# 13*0e16a31dSJim Jagielski# Unless required by applicable law or agreed to in writing, 14*0e16a31dSJim Jagielski# software distributed under the License is distributed on an 15*0e16a31dSJim Jagielski# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*0e16a31dSJim Jagielski# KIND, either express or implied. See the License for the 17*0e16a31dSJim Jagielski# specific language governing permissions and limitations 18*0e16a31dSJim Jagielski# under the License. 19*0e16a31dSJim Jagielski# 20*0e16a31dSJim Jagielski#************************************************************** 21*0e16a31dSJim Jagielski 22*0e16a31dSJim Jagielski# usage: compare.py <base.kinds.json> <new.kinds.json> 23*0e16a31dSJim Jagielski# Exit 1 if any kind is new or any kind's error or package count increased. 24*0e16a31dSJim Jagielskiimport sys, json 25*0e16a31dSJim Jagielskia, b = json.load(open(sys.argv[1])), json.load(open(sys.argv[2])) 26*0e16a31dSJim Jagielskibad = False 27*0e16a31dSJim Jagielskifor k in sorted(set(a) | set(b)): 28*0e16a31dSJim Jagielski ea, eb = a.get(k, {}).get("errors", 0), b.get(k, {}).get("errors", 0) 29*0e16a31dSJim Jagielski pa, pb = len(a.get(k, {}).get("packages", [])), len(b.get(k, {}).get("packages", [])) 30*0e16a31dSJim Jagielski if (ea, pa) == (eb, pb): 31*0e16a31dSJim Jagielski continue 32*0e16a31dSJim Jagielski worse = k not in a or eb > ea or pb > pa 33*0e16a31dSJim Jagielski bad |= worse 34*0e16a31dSJim Jagielski print(f"{'WORSE' if worse else 'better'} errors {ea}->{eb} packages {pa}->{pb} {k[:110]}") 35*0e16a31dSJim Jagielskiprint("compare:", "FAIL" if bad else "OK") 36*0e16a31dSJim Jagielskisys.exit(1 if bad else 0) 37