Генерирует HTML страницы со структурой каталога, поддерживает шаблоны http://blindage.org/?p=7014
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

66 lines
1.8 KiB

  1. #!/usr/bin/python
  2. # -*- coding: utf-8
  3. import ConfigParser
  4. import os,sys
  5. import datetime
  6. if len(sys.argv)<2: sys.exit(0)
  7. Config = ConfigParser.ConfigParser()
  8. Config.read(sys.argv[1])
  9. workpath = Config.get("paths",'workpath')
  10. tmplpath = Config.get("paths",'tmplpath')
  11. title = Config.get("ui",'title')
  12. baseurl = Config.get("ui",'baseurl')
  13. ignore = Config.get("files",'ignore')
  14. ignore_list = ignore.split(':')
  15. timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  16. os.chdir(workpath)
  17. def replaces(content):
  18. content = content.replace('{title}', title)
  19. content = content.replace('{baseurl}', baseurl)
  20. content = content.replace('{timestamp}', timestamp)
  21. return content
  22. with open (tmplpath+"/header.html", "r") as myfile:
  23. tmpl_header=replaces(myfile.read())
  24. with open (tmplpath+"/footer.html", "r") as myfile:
  25. tmpl_footer=replaces(myfile.read())
  26. for dirname, dirnames, filenames in os.walk('.'):
  27. print dirname
  28. dirnames.sort()
  29. filenames.sort()
  30. index_file = open(dirname + "/index.html", "w")
  31. index_file.write(tmpl_header)
  32. if dirname == ".":
  33. index_file.write("<h4>Корневая директория</h4>")
  34. else:
  35. index_file.write("<h4>Текущий путь "+dirname+"</h4>")
  36. index_file.write("<p><a href='..'>Перейти наверх</a></p>")
  37. index_file.write("<ul>")
  38. # exclude files
  39. for ignore_filename in ignore_list:
  40. if ignore_filename in filenames:
  41. filenames.remove(ignore_filename)
  42. # list dirs
  43. for subdirname in dirnames:
  44. index_file.write("<li><a href='"+subdirname+"'>"+subdirname+"</a></li>\n")
  45. # list files
  46. for filename in filenames:
  47. index_file.write("<li><a href='"+filename+"'>"+filename+"</a></li>\n")
  48. index_file.write("</ul>")
  49. index_file.write(tmpl_footer)
  50. index_file.close()