Skip to content

Commit 62ff42e

Browse files
author
Pierre-Luc Tessier Gagné
committed
Allow to set bus config argument via CAN_CONFIG environment variable
1 parent 2e37856 commit 62ff42e

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎can/util.py‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Utilities and configuration file parsing.
55
"""
66

7+
import json
78
import os
89
import os.path
910
import platform
@@ -65,26 +66,34 @@ def load_environment_config(context=None):
6566
* CAN_INTERFACE
6667
* CAN_CHANNEL
6768
* CAN_BITRATE
69+
* CAN_CONFIG
6870
6971
if context is supplied, "_{context}" is appended to the environment
7072
variable name we will look at. For example if context="ABC":
7173
7274
* CAN_INTERFACE_ABC
7375
* CAN_CHANNEL_ABC
7476
* CAN_BITRATE_ABC
77+
* CAN_CONFIG_ABC
7578
7679
"""
7780
mapper = {
7881
"interface": "CAN_INTERFACE",
7982
"channel": "CAN_CHANNEL",
8083
"bitrate": "CAN_BITRATE",
8184
}
82-
config = dict()
85+
86+
context_suffix = "_{}".format(context) if context else ""
87+
88+
config = {}
89+
90+
can_config_key = "CAN_CONFIG" + context_suffix
91+
if can_config_key in os.environ:
92+
config = json.loads(os.environ.get(can_config_key))
93+
8394
for key, val in mapper.items():
84-
if context is not None:
85-
val = val + "_{}".format(context)
8695
if val in os.environ:
87-
config[key] = os.environ.get(val)
96+
config[key] = os.environ.get(val + context_suffix)
8897

8998
return config
9099

0 commit comments

Comments
 (0)