-
Notifications
You must be signed in to change notification settings - Fork 0
/
template_loader.py
49 lines (35 loc) · 1.13 KB
/
template_loader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
This class is used to load a set of templates
"""
# Built in imports
import os
import os.path
# Our imports
from issue import Issue
# 3rd party imports
import yaml
from rich.traceback import install
install(show_locals=False)
class TemplateLoader(object):
def __init__(self):
self._files = []
def load(self, path):
if not os.path.exists(path):
raise RuntimeError(f"The provided path ({path}) does not exist")
keepers = []
for root, dirs, files in os.walk(path):
for name in files:
if name.startswith(".") or not (name.endswith(".yml") or name.endswith(".yaml")):
continue
else:
keepers.append(os.path.join(root, name))
issues = {}
for keeper in keepers:
data = open(keeper, "r").read()
parsed = yaml.safe_load_all(data)
for doc in parsed:
i = Issue(**doc)
if i.name in issues:
raise ValueError("Duplicate issue name '{}' found".format(i.name))
issues[i.name] = i
return issues