From 8c07b6a13d5fee6a8f37d2c183942a20c5b195c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Neum=C3=BCller?= Date: Sat, 2 Apr 2016 15:03:16 +0200 Subject: [PATCH] dir2html: Better filtering of uninteresting files & CSS classes. --- dir2html.py | 18 ++++++++++++++---- dirlisting.css | 6 +++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/dir2html.py b/dir2html.py index f9355db..ed9a736 100644 --- a/dir2html.py +++ b/dir2html.py @@ -34,17 +34,27 @@ def ext(fname): def write_dir_listing(indirname, outfname): lines = [] outdirname = path.dirname(outfname) + try: + os.remove(outfname) # Avoid self-listing. + except FileNotFoundError: + pass for root, dirs, files in os.walk(indirname): + def file_filter(f): + stemName, extName = path.splitext(f) + if extName != ".html": + return False + if ext(stemName)[1:].lower() not in CEXTS: + return False + return True + + files = list(filter(file_filter, files)) if not files: continue files.sort() root = path.relpath(root, outdirname) - lines.append('
  • {0}: