Config
odin_control.config.parser - configuration parsing for the ODIN server.
Tim Nicholls, STFC Application Engineering Group
AdapterConfig
Bases: object
An adapter configuration container class.
A simple container class used by ConfigParser to define the options for an API adapter. This class contains at least the name and module path for the adapter, plus any other options can be set as attributes using the set() method
Source code in src/odin_control/config/parser.py
__contains__(option)
Containment check operator - allows in to check for presence of option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
option
|
name of option to check for |
required |
Returns:
| Type | Description |
|---|---|
|
bool True or False indicating presence of option |
Source code in src/odin_control/config/parser.py
__getattr__(option)
Attribute getter allowing adapter options to be accessed by object.option syntax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
option
|
name option to get |
required |
Returns:
| Type | Description |
|---|---|
|
value of the requested option |
Raises:
| Type | Description |
|---|---|
AttributeError
|
raised for unrecognised option |
Source code in src/odin_control/config/parser.py
__init__(name, module)
Initialise the AdapterConfig object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
name of the adapter |
required | |
module
|
module path for the adapter |
required |
options()
Return a dictionary of the options set in the object.
Returns:
| Type | Description |
|---|---|
|
dictionary of options |
set(option, value)
Set an option for the adapter configuration object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
option
|
name of the option |
required | |
value
|
value of the option |
required |
Returns:
| Type | Description |
|---|---|
|
None |
ConfigError
Bases: Exception
ConfigParser exception class.
A trivial exception class for signalling configuration parsing errors
ConfigOption
Bases: object
A configuration option container class.
A simple container class used internally by ConfigParser to define a configuration option, its type, default value and whether it has multiple values
Source code in src/odin_control/config/parser.py
__init__(name, option_type=None, default=None, multiple=False, callback=None)
Initialise the ConfigOption object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
name of the option |
required | |
option_type
|
type of the option (e.g. int, bool, str, ...) |
None
|
|
default
|
default value for the option |
None
|
|
multiple
|
flag indicating multiple-valued option |
False
|
|
callback
|
callback to be called whenever option has a value set at parse time |
None
|
Source code in src/odin_control/config/parser.py
ConfigParser
Parses configuration options from the command-line and from a file.
Provides parsing of program configuration options from both command-line arguments and from an INI-style file. This class is designed to integrate and replace the default Tornado options parser, which has limitations in prioritising options from multiple sources. Parsed options are set as attributes of the object, allowing the calling program to easily resolve them.
Options specified at the command-line take priority over the value present in any configuration file specified. Any options already defined by Tornado packages at parse time are integrated into this parser and can be specified in the [tornado] section of the configuration file. Similarly, options defined by this parser are specified in the [server] section.
API adapters are treated as a special case of file-only configuration. If the adapters config
option is defined (either in command-line args or in a configuration file) then the
resolve_adapters() method can be used to extract adapter-specific options from a section named
[adapter.
Source code in src/odin_control/config/parser.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
__contains__(item)
Containment check operator - allows in to check for presence of option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
item to check for presence |
required |
__init__(has_adapters=True)
Initialise the configuration parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
has_adapters
|
if True, automatically define an --adapters option in the parser |
True
|
Source code in src/odin_control/config/parser.py
__iter__()
Return an iterator object over the options specified in the current instance.
define(name, default=None, option_type=None, option_help=None, metavar=None, multiple=False, action='store', callback=None)
Define an option to be parsed from the command-line and/or a configuration file.
This method replicates the functionality of the tornado options define(), allowing
options to be defined for parsing. Named options can be given a default value, a type,
which can either be given explicitly or inferred from the default value if given,
help and metavar values for display in command-line help, and a multiple
flag to allow comma-delimited multiple values to be specified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
name of the option |
required | |
default
|
default value for the option |
None
|
|
option_type
|
type of the option (e.g. int, bool, str) |
None
|
|
option_help
|
help text to be displayed for the option |
None
|
|
metavar
|
a name for the option to be used in help text |
None
|
|
multiple
|
defines if the option accepts multiple, comma-delimited values |
False
|
|
action
|
ArgumentParser-like action to be taken on parsing option |
'store'
|
|
callback
|
callback to run whenever a value for the option is set at parse time |
None
|
Returns:
| Type | Description |
|---|---|
|
None |
Source code in src/odin_control/config/parser.py
parse(args=None)
Parse command-line and file configuration options.
This method parses command-line and file (if specified a --config argument)
configuration options. The parser will parse command-line options from the
program invocation arguments or, if specified in the args parameter, from
a string with the appropriate format.
This method resolves any options already loaded into the global tornado options instance and parses them from the command-line or the [tornado] section of a configuration file. Those options are loaded back into the tornado options instance on completion of parsing, and the the tornado parser callbacks invoked to replicate the desired behaviour.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
optional string containing arguments to parse |
None
|
Returns:
| Type | Description |
|---|---|
|
None |
Source code in src/odin_control/config/parser.py
resolve_adapters(adapter_list=None)
Resolve any adapter sections present in the configuration file.
This method resovles adapter sections preent in the configuration file into a usable list of adapters to be loaded and configured by the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter_list
|
a list of adapter names to resolve. If not set, the parsers adapters attribute will be substituted |
None
|
Returns:
| Type | Description |
|---|---|
|
dict of AdapterConfig objects from the configuration file |