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 31 of file toolbox.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 41 of file toolbox.py.

41 def __init__(self, min=None, max=None, clamp=False):
42 self.min = min
43 self.max = max
44 self.clamp = clamp
45

Member Function Documentation

◆ __repr__()

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

Definition at line 78 of file toolbox.py.

78 def __repr__(self):
79 return 'IntRange(%r, %r)' % (self.min, self.max)
80# ------------------------------------------------------------------------------
81
82
83# ------------------------------------------------------------------------------

◆ convert()

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

Definition at line 46 of file toolbox.py.

46 def convert(self, value, param, ctx):
47
48 if type(value) == str:
49 if value.startswith('0x'):
50 base = 16
51 elif value.startswith('0o'):
52 bae = 8
53 elif value.startswith('0b'):
54 base = 2
55 else:
56 base = 10
57 rv = int(value, base)
58 else:
59 rv = int(value)
60 if self.clamp:
61 if self.min is not None and rv < self.min:
62 return self.min
63 if self.max is not None and rv > self.max:
64 return self.max
65 if self.min is not None and rv < self.min or \
66 self.max is not None and rv > self.max:
67 if self.min is None:
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)
73 else:
74 self.fail('%s is not in the valid range of %s to %s.'
75 % (rv, self.min, self.max), param, ctx)
76 return rv
77

Member Data Documentation

◆ clamp

timing.cli.toolbox.IntRange.clamp = clamp

Definition at line 44 of file toolbox.py.

◆ max

timing.cli.toolbox.IntRange.max = max

Definition at line 43 of file toolbox.py.

◆ min

timing.cli.toolbox.IntRange.min = min

Definition at line 42 of file toolbox.py.

◆ name

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

Definition at line 39 of file toolbox.py.


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