DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
timing.cli.toolbox.IntRange Class Reference
Inheritance diagram for timing.cli.toolbox.IntRange:
[legend]
Collaboration diagram for timing.cli.toolbox.IntRange:
[legend]

Public Member Functions

 __init__ (self, min=None, max=None, clamp=False)
 
 convert (self, value, param, ctx)
 
 __repr__ (self)
 

Public Attributes

 min = min
 
 max = max
 
 clamp = clamp
 

Static Public Attributes

str name = 'integer range'
 

Detailed Description

A parameter that works similar to :data:`click.INT` but restricts
the value to fit into a range.  The default behavior is to fail if the
value falls outside the range, but it can also be silently clamped
between the two edges.

See :ref:`ranges` for an example.

Definition at line 50 of file toolbox.py.

Constructor & Destructor Documentation

◆ __init__()

timing.cli.toolbox.IntRange.__init__ ( self,
min = None,
max = None,
clamp = False )

Definition at line 60 of file toolbox.py.

60 def __init__(self, min=None, max=None, clamp=False):
61 self.min = min
62 self.max = max
63 self.clamp = clamp
64

Member Function Documentation

◆ __repr__()

timing.cli.toolbox.IntRange.__repr__ ( self)

Definition at line 97 of file toolbox.py.

97 def __repr__(self):
98 return 'IntRange(%r, %r)' % (self.min, self.max)
99# ------------------------------------------------------------------------------
100
101
102# ------------------------------------------------------------------------------

◆ convert()

timing.cli.toolbox.IntRange.convert ( self,
value,
param,
ctx )

Definition at line 65 of file toolbox.py.

65 def convert(self, value, param, ctx):
66
67 if type(value) == str:
68 if value.startswith('0x'):
69 base = 16
70 elif value.startswith('0o'):
71 bae = 8
72 elif value.startswith('0b'):
73 base = 2
74 else:
75 base = 10
76 rv = int(value, base)
77 else:
78 rv = int(value)
79 if self.clamp:
80 if self.min is not None and rv < self.min:
81 return self.min
82 if self.max is not None and rv > self.max:
83 return self.max
84 if self.min is not None and rv < self.min or \
85 self.max is not None and rv > self.max:
86 if self.min is None:
87 self.fail('%s is bigger than the maximum valid value '
88 '%s.' % (rv, self.max), param, ctx)
89 elif self.max is None:
90 self.fail('%s is smaller than the minimum valid value '
91 '%s.' % (rv, self.min), param, ctx)
92 else:
93 self.fail('%s is not in the valid range of %s to %s.'
94 % (rv, self.min, self.max), param, ctx)
95 return rv
96

Member Data Documentation

◆ clamp

timing.cli.toolbox.IntRange.clamp = clamp

Definition at line 63 of file toolbox.py.

◆ max

timing.cli.toolbox.IntRange.max = max

Definition at line 62 of file toolbox.py.

◆ min

timing.cli.toolbox.IntRange.min = min

Definition at line 61 of file toolbox.py.

◆ name

str timing.cli.toolbox.IntRange.name = 'integer range'
static

Definition at line 58 of file toolbox.py.


The documentation for this class was generated from the following file: