/python/make_htmls.py

http://github.com/clawpack/clawpack-4.x · Python · 70 lines · 55 code · 12 blank · 3 comment · 11 complexity · 26ffc26f61fbd9b26933ff774f85d2ad MD5 · raw file

  1. """
  2. Performs 'make .htmls' in each directory to create html files from
  3. source files using $CLAW/doc/clawcode2html.py.
  4. This is useful so that links will work, e.g. if you build the Sphinx
  5. documentation locally.
  6. Use make_clean.py to first remove old versions if desired, or
  7. set remove_first to True below.
  8. """
  9. import os,sys,glob
  10. remove_first = True # to force remaking of htmls
  11. # only set to True if you're sure
  12. def make_htmls(rootdir):
  13. if rootdir==[]:
  14. # if called from command line with no argument
  15. clawdir = os.path.expandvars('$CLAW')
  16. rootdir = clawdir
  17. else:
  18. # called with an argument, try to use this for rootdir:
  19. rootdir = rootdir[0]
  20. rootdir = os.path.abspath(rootdir)
  21. print "Will make htmls in all of ",rootdir
  22. ans = raw_input("Ok? ")
  23. if ans.lower() not in ['y','yes']:
  24. print "Aborting."
  25. sys.exit()
  26. os.chdir(rootdir)
  27. goodlist = []
  28. badlist = []
  29. for (dirpath, subdirs, files) in os.walk('.'):
  30. currentdir = os.path.abspath(os.getcwd())
  31. os.chdir(os.path.abspath(dirpath))
  32. if os.path.isfile('Makefile'):
  33. print 'In directory ',dirpath
  34. if remove_first:
  35. os.system('rm -f *.html')
  36. try:
  37. os.system('make .htmls')
  38. goodlist.append(dirpath)
  39. except:
  40. print "*** make .htmls Failed"
  41. badlist.append(dirpath)
  42. os.chdir(currentdir)
  43. print ' '
  44. print 'Created htmls in directories:'
  45. for d in goodlist:
  46. print ' ',d
  47. print ' '
  48. if len(badlist) > 0:
  49. print 'Failed in the following directories:'
  50. for d in badlist:
  51. print ' ',d
  52. print ' '
  53. if __name__=='__main__':
  54. make_htmls(sys.argv[1:])