make_policy_zip.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2011 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. """Creates a zip archive with policy template files.
  6. """
  7. import argparse
  8. import os
  9. import sys
  10. sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)),
  11. os.pardir, os.pardir, os.pardir,
  12. 'build', 'android', 'gyp'))
  13. from util import build_utils
  14. def main():
  15. """Pack a list of files into a zip archive.
  16. Args:
  17. output: The file path of the zip archive.
  18. base_dir: Base path of input files.
  19. languages: Comma-separated list of languages, e.g. en-US,de.
  20. add: List of files to include in the archive. The language placeholder
  21. ${lang} is expanded into one file for each language.
  22. """
  23. parser = argparse.ArgumentParser()
  24. parser.add_argument("--output", dest="output")
  25. parser.add_argument("--timestamp",
  26. type=int,
  27. metavar="TIME",
  28. help="Unix timestamp to use for files in the archive")
  29. parser.add_argument("--base_dir", dest="base_dir")
  30. parser.add_argument("--languages", dest="languages")
  31. parser.add_argument("--add", action="append", dest="files", default=[])
  32. args = parser.parse_args()
  33. # Process file list, possibly expanding language placeholders.
  34. _LANG_PLACEHOLDER = "${lang}"
  35. languages = list(filter(bool, args.languages.split(',')))
  36. file_list = []
  37. for file_to_add in args.files:
  38. if (_LANG_PLACEHOLDER in file_to_add):
  39. for lang in languages:
  40. file_list.append(file_to_add.replace(_LANG_PLACEHOLDER, lang))
  41. else:
  42. file_list.append(file_to_add)
  43. with build_utils.AtomicOutput(args.output) as f:
  44. build_utils.DoZip(file_list, f, args.base_dir, timestamp=args.timestamp)
  45. if '__main__' == __name__:
  46. sys.exit(main())