From f328b015085be3eab7800e6f87cf1ae704486c0a Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 15 Aug 2019 13:30:57 +0200 Subject: odoo: Don't generate any Ninja code unless actually enabled. --- src/ee/odoo/__init__.py | 6 ++++++ src/ee/tools/__init__.py | 3 +++ src/ee/tools/ninja.py | 6 +++++- 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ee/odoo/__init__.py b/src/ee/odoo/__init__.py index af872b4..9da40c2 100644 --- a/src/ee/odoo/__init__.py +++ b/src/ee/odoo/__init__.py @@ -3,6 +3,7 @@ from pathlib import Path from ee.logging import log from ee.project import Project +from ee.tools import parse_bool def restructure(in_path: Path, in_format, out_path: Path, out_format): @@ -56,6 +57,11 @@ def init_project(project: Project): def generate_ninja(project: Project): + enabled = parse_bool(project.get_or_create_section("odoo").get("enabled")) + + if not enabled: + return + head = """ rule odoo-restructure command = ee odoo-restructure --in $in --in-format $in_format --out $out --out-format $out_format diff --git a/src/ee/tools/__init__.py b/src/ee/tools/__init__.py index 1c4e769..00fee58 100644 --- a/src/ee/tools/__init__.py +++ b/src/ee/tools/__init__.py @@ -71,6 +71,9 @@ def process_default_argparse_group(args): def parse_bool(v): + if v is None: + return False + if isinstance(v, bool): return v diff --git a/src/ee/tools/ninja.py b/src/ee/tools/ninja.py index c669ad1..eff5a18 100644 --- a/src/ee/tools/ninja.py +++ b/src/ee/tools/ninja.py @@ -151,8 +151,12 @@ def generate(project: Project): f.write("\n") if len(hooks): for name, _ in hooks: - f.write("# Hook: {}\n".format(name)) fragment_name = hook_fragments[name] + + if fragment_name is None: + continue + + f.write("# Hook: {}\n".format(name)) f.write(fragment_name) if not fragment_name.endswith("\n"): f.write("\n") -- cgit v1.2.3