Mercurial > pyndexr
changeset 0:565931613345 default tip
Initial commit
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Mon, 22 Oct 2012 13:58:57 +0200 |
| parents | |
| children | |
| files | .hgignore pyndexr.py |
| diffstat | 2 files changed, 59 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Mon Oct 22 13:58:57 2012 +0200 @@ -0,0 +1,12 @@ +syntax: glob +*.pyc +*~ +.*.swp +build/* +dist/* +bin/* +lib/* +include/* +local +*.egg-info +*.DS_Store
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pyndexr.py Mon Oct 22 13:58:57 2012 +0200 @@ -0,0 +1,47 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sys +import urllib + +import jinja2 + + +INDEX = 'index.html' +TEMPLATE = """\ +<!doctype html> +<link href="/index.css" rel="stylesheet" type="text/css"> +<title>/{{ path }}</title> +<h1>/{{ path }}</h1> +<ul> + <li class="dir up"><a href="..">../</a></li> +{% for name in dirs %} + <li class="dir"><a href="{{ quote(name) }}/">{{ name }}/</a></li> +{% endfor %} +{%for name in files %} + <li class="file"><a href="{{ quote(name) }}">{{ name }}</a></li> +{% endfor %} +</ul> +""" + + +def main(top): + template = jinja2.Template(TEMPLATE) + for path, dirs, files in os.walk(top): + files = [name for name in files if name != INDEX] + html = template.render(path=path.strip('.'), dirs=dirs, files=files, + quote=urllib.quote) + f = open(os.path.join(path, INDEX), 'w') + try: + f.write(html) + finally: + f.close() + + +if __name__ == '__main__': + if len(sys.argv) > 1: + top = sys.argv[1] + else: + top = os.getcwd() + main(top)
