DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
timing.cli.toolbox Namespace Reference

Classes

class  InterruptHandler
 
class  IntRange
 

Functions

 hookDebugger (debugger='gdb')
 
 sanitizeConnectionPaths (aConnectionPaths)
 
 completeDevices (ctx, args, incomplete)
 
 readSubNodes (aNode, dispatch=True)
 
 resetSubNodes (aNode, aValue=0x0, dispatch=True)
 
 validate_device (ctx, param, value)
 
 complete_device (ctx, args, incomplete)
 
 split (ctx, param, value)
 
 __str2int__ (value)
 
 split_ints (ctx, param, value)
 
 printRegTable (aRegs, aHeader=True, sort=True)
 
 printDictTable (aDict, aHdr=True, aSort=True, aFmtr=None)
 
 collateTables (t1, t2)
 
 escape_ansi (line)
 
 formatTStamp (aRawTStamp, clock_frequency_hz)
 
 tstamp2int (aRawTStamp)
 
 fmtEpState (aState)
 

Variables

 kReEscapeAnsi = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')
 

Function Documentation

◆ __str2int__()

timing.cli.toolbox.__str2int__ ( value)

Definition at line 172 of file toolbox.py.

172def __str2int__( value ):
173 if value.startswith('0x'):
174 base = 16
175 elif value.startswith('0o'):
176 bae = 8
177 elif value.startswith('0b'):
178 base = 2
179 else:
180 base = 10
181 return int(value, base)
182

◆ collateTables()

timing.cli.toolbox.collateTables ( t1,
t2 )

Definition at line 222 of file toolbox.py.

222def collateTables(t1, t2):
223 l1 = t1.split('\n')
224 l2 = t2.split('\n')
225
226 col1 = max([len(escape_ansi(l)) for l in l1])
227 col2 = max([len(escape_ansi(l)) for l in l2])
228
229 nrows = max(len(l1), len(l2));
230
231 l1 += [''] * (nrows - len(l1))
232 l2 += [''] * (nrows - len(l2))
233 fmt = '\'{:<%d}\' \'{:<%d}\'' % (col1, col2)
234 for c1,c2 in zip(l1, l2):
235 print (c1 + ' '*(col1-len(escape_ansi(c1))), ' ' ,c2 + ' '*(col2-len(escape_ansi(c2))))
236# ------------------------------------------------------------------------------
237
238# ------------------------------------------------------------------------------

◆ complete_device()

timing.cli.toolbox.complete_device ( ctx,
args,
incomplete )

Definition at line 157 of file toolbox.py.

157def complete_device(ctx, args, incomplete):
158 lDevices = ctx.obj.mConnectionManager.getDevices()
159
160 return [k for k in lDevices if incomplete in k]
161# -----------------
162
163# ------------------------------------------------------------------------------

◆ completeDevices()

timing.cli.toolbox.completeDevices ( ctx,
args,
incomplete )

Definition at line 94 of file toolbox.py.

94def completeDevices(ctx, args, incomplete):
95 import uhal
96 root_ctx = ctx.find_root()
97 devs = uhal.ConnectionManager(sanitizeConnectionPaths(str(root_ctx.params['connections']))).getDevices()
98 return [k for k in devs if incomplete in k]
99 # return []
100# ------------------------------------------------------------------------------
101
102
103# ------------------------------------------------------------------------------

◆ escape_ansi()

timing.cli.toolbox.escape_ansi ( line)

Definition at line 241 of file toolbox.py.

241def escape_ansi(line):
242 return kReEscapeAnsi.sub('', line)
243# ------------------------------------------------------------------------------
244
245# ------------------------------------------------------------------------------

◆ fmtEpState()

timing.cli.toolbox.fmtEpState ( aState)

Definition at line 263 of file toolbox.py.

263def fmtEpState(aState):
264 aState = aState.value()
265 return '{} ({})'.format(defs.kEpStates[aState], hex(aState)) if aState in defs.kEpStates else hex(aState)
266# ------------------------------------------------------------------------------
267
268
269# ------------------------------------------------------------------------------

◆ formatTStamp()

timing.cli.toolbox.formatTStamp ( aRawTStamp,
clock_frequency_hz )

Definition at line 246 of file toolbox.py.

246def formatTStamp( aRawTStamp, clock_frequency_hz ):
247 ts = int(aRawTStamp[0]) + int((aRawTStamp[1]) << 32)
248
249 lSubSec = ts % clock_frequency_hz
250 lSecFromEpoch = ts / clock_frequency_hz
251
252 return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(lSecFromEpoch))
253# ------------------------------------------------------------------------------
254
255
256# ------------------------------------------------------------------------------

◆ hookDebugger()

timing.cli.toolbox.hookDebugger ( debugger = 'gdb')
debugging helper, hooks debugger to running interpreter process
debugging helper, hooks debugger to running interpreter process

Definition at line 13 of file toolbox.py.

13def hookDebugger(debugger='gdb'):
14 '''debugging helper, hooks debugger to running interpreter process'''
15
16 import os
17 pid = os.spawnvp(os.P_NOWAIT,
18 debugger, [debugger, '-q', 'python', str(os.getpid())])
19
20 # give debugger some time to attach to the python process
21 import time
22 time.sleep( 1 )
23
24 # verify the process' existence (will raise OSError if failed)
25 os.waitpid( pid, os.WNOHANG )
26 os.kill( pid, 0 )
27 return
28# ------------------------------------------------------------------------------
29
30# ------------------------------------------------------------------------------

◆ printDictTable()

timing.cli.toolbox.printDictTable ( aDict,
aHdr = True,
aSort = True,
aFmtr = None )

Definition at line 216 of file toolbox.py.

216def printDictTable(aDict, aHdr=True, aSort=True, aFmtr=None):
217 echo ( formatDictTable(aDict, aHdr, aSort, aFmtr) )
218# ------------------------------------------------------------------------------
219
220
221# ------------------------------------------------------------------------------

◆ printRegTable()

timing.cli.toolbox.printRegTable ( aRegs,
aHeader = True,
sort = True )

Definition at line 211 of file toolbox.py.

211def printRegTable(aRegs, aHeader=True, sort=True):
212 echo ( format_reg_table(aRegs, aHeader, sort) )
213# ------------------------------------------------------------------------------
214
215# ------------------------------------------------------------------------------

◆ readSubNodes()

timing.cli.toolbox.readSubNodes ( aNode,
dispatch = True )

Definition at line 104 of file toolbox.py.

104def readSubNodes(aNode, dispatch=True):
105 lValues = { n:aNode.getNode(n).read() for n in aNode.getNodes() }
106
107 if dispatch:
108 aNode.getClient().dispatch()
109 return lValues
110# ------------------------------------------------------------------------------
111
112
113# ------------------------------------------------------------------------------

◆ resetSubNodes()

timing.cli.toolbox.resetSubNodes ( aNode,
aValue = 0x0,
dispatch = True )
Reset subnodes of aNode to aValue

Definition at line 114 of file toolbox.py.

114def resetSubNodes(aNode, aValue=0x0, dispatch=True):
115 """
116 Reset subnodes of aNode to aValue
117 """
118 lValues = { n:aNode.getNode(n).write(aValue) for n in aNode.getNodes() }
119 if dispatch:
120 aNode.getClient().dispatch()
121# ------------------------------------------------------------------------------
122
123# ------------------------------------------------------------------------------

◆ sanitizeConnectionPaths()

timing.cli.toolbox.sanitizeConnectionPaths ( aConnectionPaths)

Definition at line 84 of file toolbox.py.

84def sanitizeConnectionPaths(aConnectionPaths):
85
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)
91# ------------------------------------------------------------------------------
92
93# ------------------------------------------------------------------------------

◆ split()

timing.cli.toolbox.split ( ctx,
param,
value )

Definition at line 164 of file toolbox.py.

164def split(ctx, param, value):
165 if value is None:
166 return []
167
168 return value.split(',')
169# ------------------------------------------------------------------------------
170
171# ------------------------------------------------------------------------------

◆ split_ints()

timing.cli.toolbox.split_ints ( ctx,
param,
value )

Definition at line 183 of file toolbox.py.

183def split_ints(ctx, param, value):
184
185 sep = ','
186 dash = '-'
187
188 if value is None:
189 return []
190
191 numbers = []
192 for item in value.split(sep):
193 nums = item.split(dash)
194 if len(nums) == 1:
195 # single entry
196 numbers.append(__str2int__(item))
197 elif len(nums) == 2:
198 # range
199 i, j = __str2int__(nums[0]), __str2int__(nums[1])
200 if i > j:
201 click.ClickException('Invalid interval '+item)
202 numbers.extend(list(range(i,j+1)))
203 else:
204 click.ClickException('Malformed option (comma separated list expected): {}'.format(value))
205
206 return numbers
207# ------------------------------------------------------------------------------
208
209
210# ------------------------------------------------------------------------------

◆ tstamp2int()

timing.cli.toolbox.tstamp2int ( aRawTStamp)

Definition at line 257 of file toolbox.py.

257def tstamp2int( aRawTStamp ):
258 return int(aRawTStamp[0]) + int((aRawTStamp[1]) << 32)
259# ------------------------------------------------------------------------------
260
261
262# ------------------------------------------------------------------------------

◆ validate_device()

timing.cli.toolbox.validate_device ( ctx,
param,
value )

Definition at line 144 of file toolbox.py.

144def validate_device(ctx, param, value):
145
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])
151 )
152 return value
153# -----------------
154
155
156# -----------------

Variable Documentation

◆ kReEscapeAnsi

timing.cli.toolbox.kReEscapeAnsi = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')

Definition at line 239 of file toolbox.py.