#!/usr/bin/env python3
# ---
# Copyright 2020 glowinthedark
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and limitations under the License.
# ---
#
# Generate index.html files for
# all subdirectories in a directory tree.
# -handle symlinked files and folders: displayed with custom icons
# By default only the current folder is processed.
# Use -r or --recursive to process nested folders.
import argparse
import datetime
import os
import sys
from pathlib import Path
from urllib.parse import quote
DEFAULT_OUTPUT_FILE = 'index.html'
def process_dir(top_dir, opts):
glob_patt = opts.filter or '*'
path_top_dir: Path
path_top_dir = Path(top_dir)
index_file = None
index_path = Path(path_top_dir, opts.output_file)
if opts.verbose:
print(f'Traversing dir {path_top_dir.absolute()}')
try:
index_file = open(index_path, 'w')
except Exception as e:
print('cannot create file %s %s' % (index_path, e))
return
index_file.write("""