virtualmin domain-list --multiline returns a structured string which I would like to convert to a list of dicts of dicts.
The string looks like this (there are sometimes missing values):
do.ma.in.1
key1a: value1a
key1b: value1b
key1c:
...
do.ma.in.2
key2a: value2a
key2b: value2b
...
...
(the key: value pairs are indented by 4 spaces in the string)
which I would like to convert into this form:
[do.ma.in.1: {key1a: value1a, key1b: value1b, key1c: None ...},
do.ma.in.2: {key2a: value2a, key2b: value2b, ...}, ...
So far I did split the string with re.split("\s*(?=^\S)", str) which got me
[do.ma.in.1\n key1a: value1a\n key1b: value1b\n key1c:\n ...,
do.ma.in.2\n key2a: value2a\n key2b: value2b\n ..., ...
where the list items are just strings. (so no actual dictionary items)
Where do I go from there?
{do.ma.in.1: {key1a: value1a, key1b: value1b, key1c: None ...}, do.ma.in.2: {key2a: value2a, key2b: value2b, ...}, ...}? That would be great too. Or is that also not possible?