aboutsummaryrefslogtreecommitdiff
path: root/src/ee/project
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-03-16 22:17:33 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2019-03-23 07:30:03 +0100
commit1fe278b37b4031a42f8e27ee4f3251b474efcb16 (patch)
treee89454d2f868b491ba27792cafb1db8266ff1bb0 /src/ee/project
parent8e642991d557bd902b749ddd84e41d65c48f79cf (diff)
downloadee-python-1fe278b37b4031a42f8e27ee4f3251b474efcb16.tar.gz
ee-python-1fe278b37b4031a42f8e27ee4f3251b474efcb16.tar.bz2
ee-python-1fe278b37b4031a42f8e27ee4f3251b474efcb16.tar.xz
ee-python-1fe278b37b4031a42f8e27ee4f3251b474efcb16.zip
Starting some code around creating reports.
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))