proposals.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """Provides a list of proposal files."""
  2. __copyright__ = """
  3. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  4. Exceptions. See /LICENSE for license information.
  5. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. """
  7. import os
  8. import re
  9. import sys
  10. def get_title(parent_dir, entry):
  11. """Returns the title from the requested file."""
  12. path = os.path.join(parent_dir, entry)
  13. with open(path) as md:
  14. titles = [t for t in md.readlines() if t.startswith("# ")]
  15. if not titles:
  16. sys.exit("%r is missing a title." % path)
  17. return titles[0][2:-1]
  18. def get_path():
  19. return os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
  20. def get_list(proposals_path):
  21. proposals = []
  22. proposals_list = os.listdir(proposals_path)
  23. proposals_list.sort()
  24. for f in proposals_list:
  25. match = re.match(r"^p([0-9]{4})\.md$", f)
  26. if not match:
  27. continue
  28. number = match[1]
  29. title = get_title(proposals_path, f)
  30. proposals.append(("%s - %s" % (number, title), f))
  31. decision_file = "p%s_decision.md" % number
  32. if decision_file in proposals_list:
  33. proposals.append(("%s - Decision" % number, decision_file))
  34. return proposals