1 | import glob |
2 | import os |
3 | from operator import attrgetter |
4 |
|
5 |
|
6 | class dotdict(dict): |
7 | __getattr__ = dict.get |
8 | __setattr__ = dict.__setitem__ |
9 | __delattr__ = dict.__delitem__ |
10 |
|
11 |
|
12 | def current_dir(): |
13 | return os.path.realpath(os.path.dirname(__file__)) |
14 |
|
15 |
|
16 | def 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 |
|
30 | def 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 |
|