aboutsummaryrefslogtreecommitdiff
path: root/src/ee/project
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/project')
-rw-r--r--src/ee/project/__init__.py13
-rw-r--r--src/ee/project/report.py29
2 files changed, 42 insertions, 0 deletions
diff --git a/src/ee/project/__init__.py b/src/ee/project/__init__.py
index 187fc3c..4bedd97 100644
--- a/src/ee/project/__init__.py
+++ b/src/ee/project/__init__.py
@@ -10,3 +10,16 @@ def load_config(project_dir: Path) -> configparser.ConfigParser:
config.read_file(f, source=str(config_path))
return config
+
+
+class Project(object):
+ def __init__(self, project_dir: Path, cfg: configparser.ConfigParser):
+ self.report_dir = project_dir / "ee" / "reports"
+ self.project_dir = project_dir
+ self._cfg = cfg
+
+ @classmethod
+ def load(cls, project_dir: Path):
+ cfg = load_config(project_dir)
+
+ return Project(project_dir, cfg)
diff --git a/src/ee/project/report.py b/src/ee/project/report.py
new file mode 100644
index 0000000..5370f6c
--- /dev/null
+++ b/src/ee/project/report.py
@@ -0,0 +1,29 @@
+from pathlib import Path
+from typing import Optional
+
+from jinja2 import Environment, PackageLoader, select_autoescape
+
+from ee.tools import mk_parents
+
+
+class Message(object):
+ def __init__(self, object: Optional[str] = None, text: Optional[str] = None):
+ self.object = object
+ self.text = text
+
+
+def subsection_filter(s: str):
+ return "{}\n{}".format(s, "~" * len(s))
+
+
+def save_report(package: str, template_name: str, out_file: Path, **kwargs):
+ env = Environment(
+ loader=PackageLoader(package, "templates"),
+ autoescape=select_autoescape(["html", "xml"]),
+ )
+ env.filters["subsection"] = subsection_filter
+
+ mk_parents(out_file)
+ with out_file.open("w") as f:
+ template = env.get_template(template_name)
+ f.write(template.render(**kwargs))