Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-28 22:48:53

0001 #!/usr/bin/env python3
0002 
0003 import sys
0004 import json
0005 import argparse
0006 
0007 # exit codes
0008 NO_CHANGES = 0
0009 DATAFORMATS_CHANGED = 40
0010 POLICY_VIOLATION = 41
0011 
0012 def policyChecks(document):
0013     """Check policies on dictionary definitions. Return True if checks are fine."""
0014     # Contents to be added later
0015     return True
0016 
0017 def updatePolicyChecks(reference, update):
0018     """Check policies on dictionary updates. Return True if checks are fine."""
0019     # Contents to be added later
0020     return True
0021 
0022 def main(args):
0023     with open(args.baseline) as f:
0024         baseline = json.load(f)
0025 
0026     if args.pr is not None:
0027         with open(args.pr) as f:
0028             pr = json.load(f)
0029         pc1 = policyChecks(pr)
0030         if baseline != pr:
0031             pc2 = updatePolicyChecks(baseline, pr)
0032             if not (pc1 and pc2):
0033                 return POLICY_VIOLATION
0034 
0035             print("Changes in persistable data formats")
0036             return DATAFORMATS_CHANGED
0037         if not pc1:
0038             return POLICY_VIOLATION
0039     else:
0040         if not policyChecks(baseline):
0041             return POLICY_VIOLATION
0042 
0043     return NO_CHANGES
0044 
0045 if __name__ == "__main__":
0046     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.")
0047 
0048     parser.add_argument("--baseline", required=True, type=str, help="JSON file for baseline")
0049     parser.add_argument("--pr", type=str, help="JSON file for baseline+PR")
0050     parser.add_argument("--transientDataFormatPackage", action="store_true", help="The JSON files are for a package that can have only transient data formats")
0051 
0052     args = parser.parse_args()
0053     sys.exit(main(args))