From 72622c096f74d1a425b400ca03d501e863b8796c Mon Sep 17 00:00:00 2001 From: tmaeno Date: Mon, 11 Jul 2022 11:21:27 +0200 Subject: [PATCH] added message removal functions to MBSenderProxy --- PandaPkgInfo.py | 2 +- README.txt | 3 +++ .../liveconfigparser/LiveConfigParser.py | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/PandaPkgInfo.py b/PandaPkgInfo.py index 9c8a7ff..309f47b 100644 --- a/PandaPkgInfo.py +++ b/PandaPkgInfo.py @@ -1 +1 @@ -release_version = "0.0.30" +release_version = "0.0.31" diff --git a/README.txt b/README.txt index c5c3063..f1d7d2d 100644 --- a/README.txt +++ b/README.txt @@ -7,6 +7,9 @@ Includes all libraries used by both server and monitor (and others). Release Note ------------ +* 0.0.31 (11/7/2022) + * added expand_values + * 0.0.30 (1/7/2022) * added message removal functions to MBSenderProxy diff --git a/pandacommon/liveconfigparser/LiveConfigParser.py b/pandacommon/liveconfigparser/LiveConfigParser.py index 10e8b1c..968b802 100644 --- a/pandacommon/liveconfigparser/LiveConfigParser.py +++ b/pandacommon/liveconfigparser/LiveConfigParser.py @@ -16,6 +16,7 @@ # import os +import re try: from urllib.request import urlopen @@ -68,3 +69,24 @@ def read(self, fileName, config_url=None): ConfigParser.read_file(self, res) # read ConfigParser.read(self, confFiles) + + +# expand values +def expand_values(target, values_dict): + for tmpKey in values_dict: + tmpVal = values_dict[tmpKey] + # env variable + m = re.search(r'^\$\{*(\w+)\}*$', tmpVal) + if m and m.group(1) in os.environ: + tmpVal = os.environ[m.group(1)] + # convert string to bool/int + if tmpVal == 'True': + tmpVal = True + elif tmpVal == 'False': + tmpVal = False + elif tmpVal == 'None': + tmpVal = None + elif isinstance(tmpVal, str) and re.match('^\d+$', tmpVal): + tmpVal = int(tmpVal) + # update dict + target.__dict__[tmpKey] = tmpVal