65 lines
1.3 KiB
Python
65 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import argparse
|
|
import html
|
|
import urllib.parse
|
|
|
|
|
|
def mkindex(root, outfile, omits):
|
|
os.chdir(root)
|
|
|
|
paths = []
|
|
|
|
for dirpath, dirnames, filenames in os.walk("."):
|
|
for filename in filenames:
|
|
if filename.startswith("."):
|
|
continue
|
|
|
|
path = os.path.join(dirpath, filename)
|
|
|
|
if any([x in path for x in omits]):
|
|
continue
|
|
|
|
path = path[2:]
|
|
|
|
paths.append(path)
|
|
|
|
paths.sort()
|
|
|
|
contents = []
|
|
|
|
contents.append("""<style>
|
|
body {
|
|
color: #fff;
|
|
background-color: #0c0c0c;
|
|
}
|
|
a {
|
|
color: #44f;
|
|
}
|
|
a:visited {
|
|
color: #33a;
|
|
}
|
|
</style>""")
|
|
|
|
for path in paths:
|
|
contents.append('<a href="{}">{}</a><br />'.format(urllib.parse.quote(path), html.escape(path)))
|
|
|
|
outfile.write(''.join(contents))
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="static index generator")
|
|
parser.add_argument("outfile", help="output html file")
|
|
parser.add_argument("--root", default=".", help="root directory to index from")
|
|
parser.add_argument("--omit", nargs="+", help="don't include paths containing this substring")
|
|
args = parser.parse_args()
|
|
|
|
outfile = open(args.outfile, "w")
|
|
|
|
mkindex(args.root, outfile, args.omit)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|