Генерирует 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.
 
 
 

65 lines
1.8 KiB

#!/usr/bin/python
# -*- coding: utf-8
import ConfigParser
import os,sys
import datetime
if len(sys.argv)<2: sys.exit(0)
Config = ConfigParser.ConfigParser()
Config.read(sys.argv[1])
workpath = Config.get("paths",'workpath')
tmplpath = Config.get("paths",'tmplpath')
title = Config.get("ui",'title')
baseurl = Config.get("ui",'baseurl')
ignore = Config.get("files",'ignore')
ignore_list = ignore.split(':')
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
os.chdir(workpath)
def replaces(content):
content = content.replace('{title}', title)
content = content.replace('{baseurl}', baseurl)
content = content.replace('{timestamp}', timestamp)
return content
with open (tmplpath+"/header.html", "r") as myfile:
tmpl_header=replaces(myfile.read())
with open (tmplpath+"/footer.html", "r") as myfile:
tmpl_footer=replaces(myfile.read())
for dirname, dirnames, filenames in os.walk('.'):
print dirname
dirnames.sort()
filenames.sort()
index_file = open(dirname + "/index.html", "w")
index_file.write(tmpl_header)
if dirname == ".":
index_file.write("<h4>Корневая директория</h4>")
else:
index_file.write("<h4>Текущий путь "+dirname+"</h4>")
index_file.write("<p><a href='..'>Перейти наверх</a></p>")
index_file.write("<ul>")
# exclude files
for ignore_filename in ignore_list:
if ignore_filename in filenames:
filenames.remove(ignore_filename)
# list dirs
for subdirname in dirnames:
index_file.write("<li><a href='"+subdirname+"'>"+subdirname+"</a></li>\n")
# list files
for filename in filenames:
index_file.write("<li><a href='"+filename+"'>"+filename+"</a></li>\n")
index_file.write("</ul>")
index_file.write(tmpl_footer)
index_file.close()