From 3a8533db1dc9d284825a81c20f14d83b8a81e9e6 Mon Sep 17 00:00:00 2001 From: Tadej Fius Date: Mon, 3 Apr 2023 13:24:16 +0200 Subject: [PATCH] Create create_public_pod_index.py --- create_public_pod_index.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 create_public_pod_index.py diff --git a/create_public_pod_index.py b/create_public_pod_index.py new file mode 100644 index 0000000..6216ccb --- /dev/null +++ b/create_public_pod_index.py @@ -0,0 +1,29 @@ +import os +import sys +import argparse + +def create_index_html(startpath, title=None, description=None): + with open("index.html", "w") as f: + f.write("{0}\n".format(title or "")) + if title: + f.write("

{0}

".format(title)) + if description: + f.write("

{0}

".format(description)) + for root, dirs, files in os.walk(startpath): + for file in files: + # Create a relative link to the file + relpath = os.path.relpath(os.path.join(root, file), startpath) + link = "{1}
\n".format(relpath, file) + f.write(link) + f.write("") + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Create an HTML index of files in a directory tree.") + parser.add_argument("path", help="The path to the directory to index.") + parser.add_argument("--title", help="The title of the HTML document.") + parser.add_argument("--description", help="A description of the content of the directory.") + args = parser.parse_args() + + create_index_html(args.path, args.title, args.description) + +