Debian Codegraph @

polsarpro/dev/devtools.py

raw
1 import re
2 from collections import OrderedDict
3
4
5 def parse_psp_parameter_string(input_string):
6 """Convenience development function to make cli parameters from strings copied from parameter files."""
7 ordered_dict = OrderedDict()
8
9 for line in input_string.strip().split("\n"):
10 key, value = re.split(r":\s*", line, maxsplit=1)
11 if value.isdigit():
12 value = int(value)
13 elif value.replace(".", "", 1).isdigit(): # Check for float
14 value = float(value)
15 ordered_dict[key] = value
16 str_param = " ".join([f"-{it[0]} {it[1]}" for it in ordered_dict.items()])
17 return str_param