Skip to content

Commit

Permalink
Minor unification and cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
markaj-nordic committed Apr 9, 2024
1 parent 3b2c5dd commit 3c79946
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 2 additions & 0 deletions scripts/setup/nrfconnect/zap_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

from west import log

MATTER_PATH = Path(__file__).parents[3]

def find_zap(root: Path = Path.cwd(), max_depth: int = 1):
"""
Find *.zap file in the given directory or its subdirectories.
Expand Down
24 changes: 14 additions & 10 deletions scripts/setup/nrfconnect/zap_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause

import argparse
import os
import sys
from textwrap import dedent

from pathlib import Path
from textwrap import dedent

from west import log
from west.commands import WestCommand
from zap_common import find_zap, ZapInstaller

from zap_common import find_zap, ZapInstaller, MATTER_PATH

class ZapGenerate(WestCommand):

Expand All @@ -25,11 +28,12 @@ def __init__(self):
def do_add_parser(self, parser_adder):
parser = parser_adder.add_parser(self.name,
help=self.help,
formatter_class=argparse.RawDescriptionHelpFormatter,
description=self.description)

parser.add_argument('-z', '--zap-file', help='Path to the .zap file [optional]')
parser.add_argument('-o', '--output', help='Path where to store the generated files [optional]')

parser.add_argument('-z', '--zap-file', type=Path,
help='Path to data model configuration file (*.zap)')
parser.add_argument('-o', '--output', type=Path,
help='Path where to store the generated files')
return parser

def do_run(self, args, unknown_args):
Expand All @@ -46,18 +50,18 @@ def do_run(self, args, unknown_args):
if args.output is None:
args.output = args.zap_file.parent.absolute() / "zap-generated"

MATTER_PATH = str(Path(self.manifest.path).parent.absolute() / "../modules/lib/matter")
APP_TEMPLATES = MATTER_PATH + "/src/app/zap-templates/app-templates.json"
app_templates_path = MATTER_PATH / "src/app/zap-templates/app-templates.json"
zap_generate_path = MATTER_PATH / "scripts/tools/zap/generate.py"

zap_installer = ZapInstaller(Path(MATTER_PATH))
zap_installer.update_zap_if_needed()

# make sure that the generate.py script uses the proper zap_cli binary (handled by west)
os.environ["ZAP_INSTALL_PATH"] = str(zap_installer.get_zap_cli_path().parent.absolute())

cmd = [MATTER_PATH + "/scripts/tools/zap/generate.py"]
cmd = [str(zap_generate_path)]
cmd += ["{}".format(args.zap_file)]
cmd += ["-t", APP_TEMPLATES]
cmd += ["-t", str(app_templates_path)]
cmd += ["-o", "{}".format(args.output)]

self.check_call(cmd)
Expand Down
12 changes: 5 additions & 7 deletions scripts/setup/nrfconnect/zap_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
from pathlib import Path
from textwrap import dedent

from zap_common import find_zap, ZapInstaller

from west import log
from west.commands import WestCommand

MATTER_PATH = Path(__file__).parents[3]
from zap_common import find_zap, ZapInstaller, MATTER_PATH

class ZapGui(WestCommand):

Expand All @@ -30,10 +28,10 @@ def __init__(self):
attributes and events are enabled for the given application.'''))

def do_add_parser(self, parser_adder):
parser = parser_adder.add_parser(
self.name, help=self.help,
formatter_class=argparse.RawDescriptionHelpFormatter,
description=self.description)
parser = parser_adder.add_parser(self.name,
help=self.help,
formatter_class=argparse.RawDescriptionHelpFormatter,
description=self.description)
parser.add_argument('-z', '--zap-file', type=Path,
help='Path to data model configuration file (*.zap)')
parser.add_argument('-j', '--zcl-json', type=Path,
Expand Down

0 comments on commit 3c79946

Please sign in to comment.