regen-readme.py 698 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python
  2. import subprocess
  3. import os
  4. import sys
  5. basedir = os.path.dirname(sys.argv[0])
  6. readme = os.path.join(basedir, "doc/using.md")
  7. with open(readme) as f:
  8. inp = f.read()
  9. out = ""
  10. it = iter(inp.splitlines(True))
  11. for line in it:
  12. out += line
  13. if line.startswith("```cmdoutput"):
  14. # Get command.
  15. cmd = next(it)
  16. assert cmd.startswith("$ "), cmd
  17. real_cmd = cmd[2:].strip()
  18. out += cmd
  19. print("Running: " + real_cmd)
  20. out += subprocess.check_output(real_cmd, shell=True)
  21. # Skip pre-existing command output.
  22. line = next(it)
  23. while not line.startswith("```"):
  24. line = next(it)
  25. out += line
  26. with open(readme, "w") as f:
  27. f.write(out)