make_readme.py 708 B

12345678910111213141516171819202122232425262728
  1. from __future__ import unicode_literals
  2. import io
  3. import sys
  4. import re
  5. from youtube_dl.compat import compat_open as open
  6. README_FILE = 'README.md'
  7. helptext = sys.stdin.read()
  8. if isinstance(helptext, bytes):
  9. helptext = helptext.decode('utf-8')
  10. with io.open(README_FILE, encoding='utf-8') as f:
  11. oldreadme = f.read()
  12. header = oldreadme[:oldreadme.index('# OPTIONS')]
  13. footer = oldreadme[oldreadme.index('# CONFIGURATION'):]
  14. options = helptext[helptext.index(' General Options:') + 19:]
  15. options = re.sub(r'(?m)^ (\w.+)$', r'## \1', options)
  16. options = '# OPTIONS\n' + options + '\n'
  17. with open(README_FILE, 'w', encoding='utf-8') as f:
  18. f.write(header)
  19. f.write(options)
  20. f.write(footer)