1from __future__
import print_function
10from click
import echo, style, secho
14 '''debugging helper, hooks debugger to running interpreter process'''
17 pid = os.spawnvp(os.P_NOWAIT,
18 debugger, [debugger,
'-q',
'python', str(os.getpid())])
25 os.waitpid( pid, os.WNOHANG )
32 """A parameter that works similar to :data:`click.INT` but restricts
33 the value to fit into a range. The default behavior is to fail if the
34 value falls outside the range, but it can also be silently clamped
35 between the two edges.
37 See :ref:`ranges` for an example.
39 name =
'integer range'
41 def __init__(self, min=None, max=None, clamp=False):
48 if type(value) == str:
49 if value.startswith(
'0x'):
51 elif value.startswith(
'0o'):
53 elif value.startswith(
'0b'):
61 if self.
min is not None and rv < self.
min:
63 if self.
max is not None and rv > self.
max:
65 if self.
min is not None and rv < self.
min or \
66 self.
max is not None and rv > self.
max:
68 self.fail(
'%s is bigger than the maximum valid value '
69 '%s.' % (rv, self.
max), param, ctx)
70 elif self.
max is None:
71 self.fail(
'%s is smaller than the minimum valid value '
72 '%s.' % (rv, self.
min), param, ctx)
74 self.fail(
'%s is not in the valid range of %s to %s.'
75 % (rv, self.
min, self.
max), param, ctx)
79 return 'IntRange(%r, %r)' % (self.
min, self.
max)
86 lConnectionList = aConnectionPaths.split(
';')
87 for i,c
in enumerate(lConnectionList):
88 if re.match(
'^\w+://.*', c)
is None:
89 lConnectionList[i] =
'file://'+c
90 return ';'.join(lConnectionList)
96 root_ctx = ctx.find_root()
98 return [k
for k
in devs
if incomplete
in k]
105 lValues = { n:aNode.getNode(n).read()
for n
in aNode.getNodes() }
108 aNode.getClient().dispatch()
116 Reset subnodes of aNode to aValue
118 lValues = { n:aNode.getNode(n).write(aValue)
for n
in aNode.getNodes() }
120 aNode.getClient().dispatch()
126 debugging helper, hooks debugger to running interpreter process
130 pid = os.spawnvp(os.P_NOWAIT,
131 debugger, [debugger,
'-q',
'python', str(os.getpid())])
138 os.waitpid( pid, os.WNOHANG )
146 lDevices = ctx.obj.mConnectionManager.getDevices()
147 if value
not in lDevices:
148 raise click.BadParameter(
149 'Device must be one of '+
150 ', '.join([
"'"+lId+
"'" for lId
in lDevices])
158 lDevices = ctx.obj.mConnectionManager.getDevices()
160 return [k
for k
in lDevices
if incomplete
in k]
168 return value.split(
',')
173 if value.startswith(
'0x'):
175 elif value.startswith(
'0o'):
177 elif value.startswith(
'0b'):
181 return int(value, base)
192 for item
in value.split(sep):
193 nums = item.split(dash)
201 click.ClickException(
'Invalid interval '+item)
202 numbers.extend(list(range(i,j+1)))
204 click.ClickException(
'Malformed option (comma separated list expected): {}'.format(value))
212 echo ( format_reg_table(aRegs, aHeader, sort) )
217 echo ( formatDictTable(aDict, aHdr, aSort, aFmtr) )
229 nrows = max(len(l1), len(l2));
231 l1 += [
''] * (nrows - len(l1))
232 l2 += [
''] * (nrows - len(l2))
233 fmt =
'\'{:<%d}\' \'{:<%d}\'' % (col1, col2)
234 for c1,c2
in zip(l1, l2):
239kReEscapeAnsi = re.compile(
r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')
242 return kReEscapeAnsi.sub(
'', line)
247 ts = int(aRawTStamp[0]) + int((aRawTStamp[1]) << 32)
249 lSubSec = ts % clock_frequency_hz
250 lSecFromEpoch = ts / clock_frequency_hz
252 return time.strftime(
"%a, %d %b %Y %H:%M:%S +0000", time.localtime(lSecFromEpoch))
258 return int(aRawTStamp[0]) + int((aRawTStamp[1]) << 32)
264 aState = aState.value()
265 return '{} ({})'.format(defs.kEpStates[aState], hex(aState))
if aState
in defs.kEpStates
else hex(aState)
282 def handler(signum, frame):
286 signal.signal(self.
sig, handler)