Skip to content

Commit d90857d

Browse files
TeoMahnicRobertRostohar
authored andcommitted
session: add command property used for detecting which sub-command is executing
- cbuild-run: SVD file loading for load/erase/reset sub-command
1 parent c317d64 commit d90857d

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

pyocd/core/session.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def __init__(
132132
auto_open: bool = True,
133133
options: Optional[Mapping[str, Any]] = None,
134134
option_defaults: Optional[Mapping[str, Any]] = None,
135+
command: Optional[str] = None,
135136
**kwargs
136137
) -> None:
137138
"""@brief Session constructor.
@@ -166,6 +167,7 @@ def __init__(
166167
self._probe = probe
167168
self._closed: bool = True
168169
self._inited: bool = False
170+
self._command = command
169171
self._user_script_namespace: Dict[str, Any] = {}
170172
self._user_script_proxy: Optional[UserScriptDelegateProxy] = None
171173
self._user_script_print_proxy = PrintProxy()
@@ -331,6 +333,11 @@ def probe(self) -> Optional[DebugProbe]:
331333
"""@brief The @ref pyocd.probe.debug_probe.DebugProbe "DebugProbe" instance."""
332334
return self._probe
333335

336+
@property
337+
def command(self) -> Optional[str]:
338+
"""@brief The current command being executed in the session."""
339+
return self._command
340+
334341
@property
335342
def board(self) -> Optional[Board]:
336343
"""@brief The @ref pyocd.board.board.Board "Board" object."""

pyocd/subcommands/erase_cmd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def invoke(self) -> int:
8787
frequency=self._args.frequency,
8888
blocking=(not self._args.no_wait),
8989
connect_mode=self._args.connect_mode,
90+
command=self._args.cmd,
9091
options=convert_session_options(self._args.options),
9192
option_defaults=self._modified_option_defaults(),
9293
)

pyocd/subcommands/load_cmd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def invoke(self) -> int:
9898
frequency=self._args.frequency,
9999
blocking=(not self._args.no_wait),
100100
connect_mode=self._args.connect_mode,
101+
command=self._args.cmd,
101102
options=convert_session_options(self._args.options),
102103
option_defaults=self._modified_option_defaults(),
103104
)

pyocd/subcommands/reset_cmd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def invoke(self) -> None:
8686
connect_mode=self._args.connect_mode,
8787
resume_on_disconnect=not self._args.halt,
8888
reset_type=self._args.reset_type,
89+
command=self._args.cmd,
8990
options=convert_session_options(self._args.options),
9091
option_defaults=self._modified_option_defaults(),
9192
)

pyocd/target/pack/cbuild_run.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ def _cbuild_target_init(self, session: Session) -> None:
9595
super(self.__class__, self).__init__(session, self._cbuild_device.memory_map)
9696
self.vendor = self._cbuild_device.vendor
9797
self.part_number = self._cbuild_device.target
98-
_svd = self._cbuild_device.svd
99-
self._svd_location = SVDFile(filename=_svd) if _svd else None
98+
if session.command not in ('load', 'erase', 'reset'):
99+
# SVD file is not required for load/erase/reset commands
100+
_svd = self._cbuild_device.svd
101+
self._svd_location = SVDFile(filename=_svd) if _svd else None
100102
self.debug_sequence_delegate = CbuildRunDebugSequenceDelegate(self, self._cbuild_device)
101103

102104
@staticmethod
@@ -292,13 +294,13 @@ def _is_under(parent: Path, child: Path) -> bool:
292294
except ValueError:
293295
return False
294296

295-
# Use warning logging for non-required files
296-
log = LOG.warning
297-
err = f"File '{file_path}' not found"
297+
# Select appropriate logging level and error message based on whether the file is required
298298
if required:
299-
# Switch to using error logging for required files
300299
log = LOG.error
301300
err = f"File '{file_path}' is required but not found"
301+
else:
302+
log = LOG.warning
303+
err = f"File '{file_path}' not found"
302304

303305
self._get_required_packs()
304306
# Verify pack installation only if the file is located within a required pack.

0 commit comments

Comments
 (0)