add_readme.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python
  2. import os
  3. from os import listdir
  4. from os.path import isfile, join
  5. import logging
  6. import sys
  7. logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
  8. level=logging.DEBUG,
  9. stream=sys.stdout)
  10. def create_readme(directory):
  11. project_name = os.path.basename(directory)
  12. onlyfiles = [f.lower()
  13. for f in listdir(directory)
  14. if isfile(join(directory, f))]
  15. if ('%s.tex' % project_name) not in onlyfiles:
  16. logging.warning("Dir '%s' has no standard .tex filename.", directory)
  17. return
  18. text = "Compiled example\n"
  19. text += "----------------\n"
  20. text += "![Example](%s.png)\n" % project_name
  21. with open(os.path.join(directory, "README.md"), 'w') as f:
  22. f.write(text)
  23. os.system("make png -C %s" % directory)
  24. subdirs = [x[0] for x in os.walk('.')]
  25. subdirs = [f for f in subdirs
  26. if not any([True for e in f.split('/')
  27. if e.startswith('.') and len(e) > 1])]
  28. for subdir in subdirs:
  29. onlyfiles = [f.lower() for f in listdir(subdir) if isfile(join(subdir, f))]
  30. if 'readme.md' not in onlyfiles:
  31. create_readme(subdir)