1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-09-06 20:11:53 +01:00

instrument: Clear up Instrument.reset semantics

- Fix missing parameter in the documentation

- Clarify meaning of `sites` and `kinds` in the documentation.

- With the current implementation the `channels` argument is
  useless: if `sites` and `kinds` are not also specified then all
  channels are enabled anyway. Fix that by making those parameters
  ignored when `channels` is provided.
This commit is contained in:
Brendan Jackman
2017-05-10 11:18:21 +01:00
parent 90040e8b58
commit 1513db0951
2 changed files with 29 additions and 17 deletions

View File

@@ -258,24 +258,29 @@ class Instrument(object):
pass
def reset(self, sites=None, kinds=None, channels=None):
self.active_channels = []
if kinds is None and sites is None and channels is None:
self.active_channels = sorted(self.channels.values(), key=lambda x: x.label)
else:
if isinstance(sites, basestring):
sites = [sites]
if isinstance(kinds, basestring):
kinds = [kinds]
self.active_channels = []
for chan_name in (channels or []):
elif channels is not None:
if sites is not None or kinds is not None:
raise ValueError(
'sites and kinds should not be set if channels is set')
for chan_name in channels:
try:
self.active_channels.append(self.channels[chan_name])
except KeyError:
msg = 'Unexpected channel "{}"; must be in {}'
raise ValueError(msg.format(chan_name, self.channels.keys()))
for chan in self.channels.values():
if (kinds is None or chan.kind in kinds) and \
(sites is None or chan.site in sites):
self.active_channels.append(chan)
else:
if isinstance(sites, basestring):
sites = [sites]
if isinstance(kinds, basestring):
kinds = [kinds]
else:
for chan in self.channels.values():
if (kinds is None or chan.kind in kinds) and \
(sites is None or chan.site in sites):
self.active_channels.append(chan)
# instantaneous