Index

joshstock.in / dcef9a4

Source for serving and static templating/compiling of https://joshstock.in.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
15814 Jan 2023 23:375aaa26aWebsite rewriteJosh Stockin1340G

Blob @ joshstock.in / site / _utils.py

application/x-python897 bytesdownload raw
1import glob
2import os
3from operator import attrgetter
4
5
6class dotdict(dict):
7 __getattr__ = dict.get
8 __setattr__ = dict.__setitem__
9 __delattr__ = dict.__delitem__
10
11
12def current_dir():
13 return os.path.realpath(os.path.dirname(__file__))
14
15
16def load_generators(parent_module, identifiers):
17 generator_functions = {}
18 for identifier in identifiers:
19 generator_file = f"{parent_module}.{identifier}"
20 generator_functions[identifier] = attrgetter(identifier)(
21 __import__(generator_file)
22 ).run
23
24 def run(generator_name, data=dotdict()):
25 return generator_functions[generator_name](data)
26
27 return run
28
29
30def list_files(path, extension=""):
31 path = glob.iglob(os.path.join(path, f"**/*{extension}"), recursive=True)
32 files = [p for p in path if os.path.isfile(p)] # Discards directories
33 files.sort(reverse=True)
34 return files
35