Guest User

Untitled

a guest
Jan 14th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. import os
  2. import sys
  3.  
  4. def findsource():
  5. pyfiles = []
  6. for root, dirs, files in os.walk(sys.argv[1]):
  7. for file in files:
  8. if file[-2:] == "py":
  9. print file
  10. pyfiles.append(str(root + os.sep + file))
  11. print pyfiles
  12. return pyfiles
  13.  
  14.  
  15.  
  16.  
  17. def get_todos(files):
  18. """Create a list of TODO information based on the given files.
  19.  
  20. @param files: List of paths to Python source files.
  21. @return: List of (person, date, file, line, text) tuples corresponding to
  22. TODO comments in the given sources.
  23. """
  24. comments = []
  25. for source_filename in files:
  26. source_file = open(source_filename, "r")
  27. line_number = 0
  28. for line in source_file:
  29. line_number += 1
  30. line = line.strip()
  31. if line.startswith("#TODO"):
  32. elements = line.split(":")
  33. todo_info = (elements[2],
  34. elements[1],
  35. source_filename,
  36. str(line_number),
  37. elements[3].strip())
  38.  
  39. comments.append(todo_info)
  40. return comments
  41.  
  42. def sortStuff(in_list):
  43. in_list.sort()
  44. print in_list
  45. return in_list
  46.  
  47.  
  48. def outputHTML(sorted_list):
  49. f = open('todo.html','w')
  50. startFile(f)
  51. person = sorted_list[0][0]
  52. f.write('<li>'+person+'\n<ul>\n')
  53. for item in sorted_list:
  54. if not item[0] == person:
  55. person = item[0]
  56. f.write('</ul></li>\n<li>'+person+'<ul>\n')
  57. f.write('<li>'+str(item[1])+' '+item[2]+' '+str(item[3])+' '+item[4]+'</li>\n')
  58. f.write('</ul></ul></body></html>')
  59. f.close()
  60.  
  61. def startFile(f):
  62. f.write('<html>\n<body>\n<ul>\n')
  63.  
  64.  
  65. if __name__ == '__main__':
  66. files = findsource()
  67. data = get_todos(files)
  68. sorted_list = sortStuff(data)
  69. outputHTML(sorted_list)
Add Comment
Please, Sign In to add comment