From 62437820e4a81d6c342c57f25d8848e30000a177 Mon Sep 17 00:00:00 2001 From: davidovski Date: Wed, 29 Sep 2021 23:18:33 +0100 Subject: removed html --- build.py | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 123 insertions(+), 5 deletions(-) (limited to 'build.py') diff --git a/build.py b/build.py index 45d8982..e922ac9 100644 --- a/build.py +++ b/build.py @@ -2,6 +2,9 @@ import markdown import os import time import shutil +import subprocess +from html import escape + from const import * @@ -60,10 +63,22 @@ def make(): os.makedirs(os.path.join(dist, "entries")) except: print("Already have content") - shutil.rmtree(os.path.join(dist, "src")) - shutil.rmtree(os.path.join(dist, "images")) - shutil.copytree(source, os.path.join(dist, "src")) - shutil.copytree(images, os.path.join(dist, "images")) + try: + shutil.rmtree(os.path.join(dist, "src")) + except: + pass + try: + shutil.rmtree(os.path.join(dist, "images")) + except: + pass + try: + shutil.copytree(source, os.path.join(dist, "src")) + except: + pass + try: + shutil.copytree(images, os.path.join(dist, "images")) + except: + pass pages = listPages() @@ -117,8 +132,111 @@ def make(): rss_templ.replace("%items%", itemsXML) ) + for f in os.listdir(resources): + shutil.copy(os.path.join(resources, f), dist) + print(f"built in {len(pages)} pages") -make() + +def get_repos(): + repos = [] + if os.path.exists("git_repos.txt"): + with open("git_repos.txt", "r") as file: + repos = file.read().split("\n")[:-1] + return repos + +def list_files(path): + files = [] + dirlist = [path] + + while len(dirlist) > 0: + for (dirpath, dirnames, filenames) in os.walk(dirlist.pop()): + dirlist.extend(dirnames) + files.extend(map(lambda n: os.path.join(*n), zip([dirpath] * len(filenames), filenames))) + print(len(files)) + + return files + +def format_file(page_templ, content, v): + return page_templ.replace("%title%", v["name"])\ + .replace("%up%", v["above"])\ + .replace("%filename%", v["filename"])\ + .replace("%commit%", str(v["commit"]))\ + .replace("%content%", content) + + +def traverse_repo(path, name, commit): + page_templ = getTemplateHTML("page.html") + page_templ = page_templ.replace("%content%", getTemplateHTML("file.html")) + + for root, dirs, files in os.walk(path): + index_content = "" + + index_content = format_file(page_templ, index_content, { + "name": name, + "commit": commit, + "filename": "/".join(root.split("/")[1:]), + "above": "/".join(root.split("/")[1:-1]), + }) + + with open(os.path.join(root,"index.html"), "w") as file: + file.write(index_content) + +def create_repos(): + try: + shutil.rmtree(os.path.join(dist, "git")) + except: + pass + + git_path = os.path.join(dist, "git") + try: + os.makedirs(git_path) + except: + print("Already have git path") + + for repo in get_repos(): + print(repo) + + os.system(f"cd {dist}/git; git clone {repo}") + name = ".".join(repo.split("/")[-1].split(".")[:-1]) + + command = subprocess.run(f"cd {dist}/git/{name} && git log --pretty=format:'%h%x09%an%x09%ad%x09%s' --no-decorate -1", stdout=subprocess.PIPE, shell=True) + + commit = command.stdout.decode() + + traverse_repo(os.path.join(git_path, name), name, commit) +make() +create_repos() -- cgit v1.2.1