policy_templates.py 975 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python3
  2. # Copyright 2022 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. import argparse
  6. import json
  7. import os
  8. import sys
  9. POLICY_TEMPLATES_PATH = os.path.join(
  10. os.path.dirname(__file__), 'policy_templates.json')
  11. def GetPolicyTemplates():
  12. '''Returns an object containing the policy templates.'''
  13. with open(POLICY_TEMPLATES_PATH, 'r', encoding='utf-8') as f:
  14. return eval(f.read())
  15. def main():
  16. '''Generates the a JSON file at `dest` with all the policy definitions.
  17. Args:
  18. dest: A path to the policy templates generated definitions.
  19. '''
  20. parser = argparse.ArgumentParser()
  21. parser.add_argument('--dest', dest='dest')
  22. args = parser.parse_args()
  23. with open(os.path.join(args.dest), 'w+', encoding='utf-8') as dest:
  24. json.dump(GetPolicyTemplates(), dest, indent=2, sort_keys=True)
  25. if '__main__' == __name__:
  26. sys.exit(main())