aboutsummaryrefslogtreecommitdiff
path: root/src/ee/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/tools')
-rw-r--r--src/ee/tools/__init__.py13
-rw-r--r--src/ee/tools/init.py25
-rw-r--r--src/ee/tools/ninja.py17
-rw-r--r--src/ee/tools/odoo-restructure.py26
-rw-r--r--src/ee/tools/templates/build.ninja.j29
5 files changed, 90 insertions, 0 deletions
diff --git a/src/ee/tools/__init__.py b/src/ee/tools/__init__.py
index 0d4ef14..d6d1298 100644
--- a/src/ee/tools/__init__.py
+++ b/src/ee/tools/__init__.py
@@ -67,3 +67,16 @@ def process_default_argparse_group(args):
log_level = log_level if log_level is not None else "info"
log.set_level(log_level)
+
+
+def parse_bool(v):
+ if isinstance(v, bool):
+ return v
+
+ if v.lower() in ("yes", "true", "t", "y", "1"):
+ return True
+
+ if v.lower() in ("no", "false", "f", "n", "0"):
+ return False
+
+ raise argparse.ArgumentTypeError("Boolean value expected.")
diff --git a/src/ee/tools/init.py b/src/ee/tools/init.py
index 9b3bcf4..e78ab9a 100644
--- a/src/ee/tools/init.py
+++ b/src/ee/tools/init.py
@@ -4,6 +4,7 @@ from pathlib import Path
from typing import List
import ee.tools
+from ee.tools import parse_bool
from ee.project import Project
@@ -49,12 +50,31 @@ def init_seeed_opl(project: Project):
ee.supplier.seeed.init_project(project)
+def init_odoo(project: Project, args):
+ enabled = parse_bool(project.cfg.get("odoo", "enabled", fallback=False))
+ # print("odoo enabled: {}".format(enabled))
+
+ if args.enable_odoo is not None:
+ # print("using args: {}".format(args.enable_odoo))
+ enabled = args.enable_odoo
+
+ if not enabled:
+ if "odoo" not in project.cfg:
+ return
+ project.cfg["odoo"]["enabled"] = "no"
+ return
+
+ import ee.odoo
+ ee.odoo.init_project(project)
+
+
def init(project_dir: Path, basedir: Path, args):
project = Project.load(project_dir)
init_kicad_project(basedir, project, args)
init_digikey(project)
init_seeed_opl(project)
+ init_odoo(project, args)
if args.create_bom_strategy:
create_bom = project.get_or_create_section("create-bom")
@@ -78,6 +98,11 @@ parser.add_argument("--create-bom-strategy",
required=False,
metavar="PY CALLABLE")
+parser.add_argument("--enable-odoo",
+ type=parse_bool, nargs="?",
+ const=True, default=None,
+ metavar="BOOL")
+
args = parser.parse_args()
ee.tools.process_default_argparse_group(args)
diff --git a/src/ee/tools/ninja.py b/src/ee/tools/ninja.py
index 7d73d8f..3df8796 100644
--- a/src/ee/tools/ninja.py
+++ b/src/ee/tools/ninja.py
@@ -1,5 +1,6 @@
import argparse
import os.path
+import pydoc
import sys
from pathlib import Path
from typing import List, Union
@@ -126,11 +127,27 @@ def generate(project: Project):
"default ee-reports\n",
])
+ # Hooks
+ hooks = [("odoo", "ee.odoo.generate_ninja")]
+ hook_fragments = {}
+ for name, function in hooks:
+ f = pydoc.locate(function)
+ hook_fragments[name] = f(project)
+
with ee_ninja.open("w") as f:
env = _create_env()
template = env.get_template("build.ninja.j2")
f.write(template.render(**params))
+ f.write("\n")
+ if len(hooks):
+ for name, _ in hooks:
+ f.write("# Hook: {}\n".format(name))
+ fragment_name = hook_fragments[name]
+ f.write(fragment_name)
+ if not fragment_name.endswith("\n"):
+ f.write("\n")
+
parser = argparse.ArgumentParser()
ee.tools.add_default_argparse_group(parser)
diff --git a/src/ee/tools/odoo-restructure.py b/src/ee/tools/odoo-restructure.py
new file mode 100644
index 0000000..38e67b6
--- /dev/null
+++ b/src/ee/tools/odoo-restructure.py
@@ -0,0 +1,26 @@
+import argparse
+from pathlib import Path
+
+import ee.odoo
+import ee.tools
+
+parser = argparse.ArgumentParser()
+ee.tools.add_default_argparse_group(parser)
+
+parser.add_argument("--in",
+ dest="in_path",
+ required=True)
+
+parser.add_argument("--out",
+ required=True)
+
+parser.add_argument("--in-format",
+ required=True)
+
+parser.add_argument("--out-format",
+ required=True)
+
+args = parser.parse_args()
+ee.tools.process_default_argparse_group(args)
+
+ee.odoo.restructure(Path(args.in_path), args.in_format, Path(args.out), args.out_format)
diff --git a/src/ee/tools/templates/build.ninja.j2 b/src/ee/tools/templates/build.ninja.j2
index 016c7da..4817b7b 100644
--- a/src/ee/tools/templates/build.ninja.j2
+++ b/src/ee/tools/templates/build.ninja.j2
@@ -3,6 +3,7 @@ ee = {{ ee }}
uuid = {{ project.uuid }}
public_dir = {{ project.public_dir }}
report_dir = {{ project.report_dir }}
+orders_dir = {{ project.orders_dir }}
{%- if sch is defined %}
sch = {{ sch | ninja_path }}
sch_files = {{ sch_files | ninja_path }}
@@ -196,6 +197,14 @@ build $public_dir/seeed/opl/{{ opl }}.xml: seeed-download-opl
{%- endfor %}
{%- endif %}
+rule ee-ninja
+ command = ee ninja && touch $out
+
+build build.ninja ee.ninja: ee-ninja eeconfig $orders_dir
+ generator = yes
+
+default ee.ninja
+
# Reports
build ee-reports: phony {{ " ".join(reports) }}
build ee-part-dbs: phony {%- for s in suppliers %} {{ s.part_db }}{% endfor %}