CMS 3D CMS Logo

checkDictionaryUpdate.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 import sys
4 import json
5 import argparse
6 
7 # exit codes
8 NO_CHANGES = 0
9 DATAFORMATS_CHANGED = 40
10 POLICY_VIOLATION = 41
11 
12 def policyChecks(document):
13  """Check policies on dictionary definitions. Return True if checks are fine."""
14  # Contents to be added later
15  return True
16 
17 def updatePolicyChecks(reference, update):
18  """Check policies on dictionary updates. Return True if checks are fine."""
19  # Contents to be added later
20  return True
21 
22 def main(args):
23  with open(args.baseline) as f:
24  baseline = json.load(f)
25 
26  if args.pr is not None:
27  with open(args.pr) as f:
28  pr = json.load(f)
29  pc1 = policyChecks(pr)
30  if baseline != pr:
31  pc2 = updatePolicyChecks(baseline, pr)
32  if not (pc1 and pc2):
33  return POLICY_VIOLATION
34 
35  print("Changes in persistable data formats")
36  return DATAFORMATS_CHANGED
37  if not pc1:
38  return POLICY_VIOLATION
39  else:
40  if not policyChecks(baseline):
41  return POLICY_VIOLATION
42 
43  return NO_CHANGES
44 
45 if __name__ == "__main__":
46  parser = argparse.ArgumentParser(description=f"Check dictionary policies of the JSON output of edmDumpClassVersion. If one JSON document is given (--baseline; e.g. in IBs), only the dictionary definition policy checks are done. If two JSON documents are given (--baseline and --pr; e.g. in PR tests), the dictionary definition policy checks are done on the --pr document, and, in addition, if any persistable data formats are changed, additional checks are done to ensure the dictionary update is done properly. Exits with {NO_CHANGES} if there are no changes to persistent data formats. Exits with {DATAFORMATS_CHANGED} if persistent data formats are changed, and the update complies with data format policies. Exits with {POLICY_VIOLATION} if some data format policy is violated. Other exit codes (e.g. 1, 2) denote some failure in the script itself.")
47 
48  parser.add_argument("--baseline", required=True, type=str, help="JSON file for baseline")
49  parser.add_argument("--pr", type=str, help="JSON file for baseline+PR")
50  parser.add_argument("--transientDataFormatPackage", action="store_true", help="The JSON files are for a package that can have only transient data formats")
51 
52  args = parser.parse_args()
53  sys.exit(main(args))
def updatePolicyChecks(reference, update)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
Definition: main.py:1