#!/usr/local/bin/python import sys, os, stat, string, errno, time index_='index.html' indexnew_=index_+'{new}' html={ '&': '&', '<': '<', '>': '>', '"': '"' } for dir in sys.argv[1:]: if dir[-1:]=='/': dir=dir[:-1] index=dir+'/'+index_ indexnew=dir+'/'+indexnew_ files=os.listdir(dir) if index_ in files: mode=stat.S_IMODE(os.stat(index)[stat.ST_MODE]) else: mode=os.stat(dir)[0] mode=mode&~(stat.S_IXUSR|stat.S_IXGRP|stat.S_IXOTH) try: os.unlink(indexnew) except OSError, info: if info[0]!=errno.ENOENT: raise OSError, info fd=os.open(indexnew, os.O_WRONLY|os.O_CREAT|os.O_EXCL, mode) fh=os.fdopen(fd, 'w') title='' for char in dir: try: title=title+html[char] except KeyError: title=title+char fh.writelines([''' Listing: '''[1:], title, '''

Listing: ''', title, '''

Parent directory
Last modified Size File ''']) files.sort(lambda a, b: (a>b)-(a', file, '\n']) fh.write('
\n\n\n') fh.flush() os.fsync(fh.fileno()) fh.close() os.rename(indexnew, index)