extract_from_release_notes.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  4. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. #
  6. """
  7. Extract the latest release notes content from RELEASE_NOTES.md
  8. """
  9. import argparse
  10. import os
  11. import sys
  12. import traceback
  13. def latest_content(release_notes_path):
  14. """
  15. can't change the format of the original content
  16. """
  17. content = ""
  18. start_extract = False
  19. with open(release_notes_path, encoding="utf-8") as f:
  20. for line in f:
  21. if line.startswith("## "):
  22. if start_extract:
  23. break
  24. start_extract = True
  25. continue
  26. # hit a separated line
  27. if line.startswith("---"):
  28. break
  29. content += line
  30. content += os.linesep
  31. return content
  32. def main():
  33. """
  34. GO!GO!!GO!!!
  35. """
  36. parser = argparse.ArgumentParser(description="run the sample and examine outputs")
  37. parser.add_argument("release_notes_path", type=str)
  38. args = parser.parse_args()
  39. ret = 1
  40. try:
  41. print(latest_content(args.release_notes_path))
  42. ret = 0
  43. except AssertionError:
  44. traceback.print_exc()
  45. return ret
  46. if __name__ == "__main__":
  47. sys.exit(main())