Displays YAML files in a flat format using python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

43 lines
1.6 KiB

def list_handler(VALUE, PARENT_PATH):
for idx in range(len(VALUE)):
value = VALUE[idx]
if isinstance(value, dict):
dict_handler(value, "{KEY}[{IDX}]".format(
KEY=PARENT_PATH, IDX=idx))
elif isinstance(value, list):
list_handler(value, "{KEY}[{IDX}]".format(
KEY=PARENT_PATH, IDX=idx))
elif isinstance(value, str):
print('.{KEY}[{IDX}] = "{VALUE}"'.format(
KEY=PARENT_PATH, IDX=idx, VALUE=value))
else:
print(".{KEY}[{IDX}] = {VALUE}".format(
KEY=PARENT_PATH, IDX=idx, VALUE=value))
def dict_handler(VALUE, PARENT_PATH):
for key in VALUE:
value = VALUE.get(key)
if isinstance(value, dict):
dict_handler(value, PARENT_PATH + "." + key)
elif isinstance(value, list):
list_handler(value, PARENT_PATH + "." + key)
elif isinstance(value, str):
print('.{PARENT_PATH}.{KEY} = "{VALUE}"'.format(
PARENT_PATH=PARENT_PATH, KEY=key, VALUE=value))
else:
print(".{PARENT_PATH}.{KEY} = {VALUE}".format(
PARENT_PATH=PARENT_PATH, KEY=key, VALUE=value))
def ycat(YAML):
for key in YAML:
value = YAML.get(key)
if isinstance(value, dict):
dict_handler(value, key)
elif isinstance(value, list):
list_handler(value, key)
elif isinstance(value, str):
print('.{KEY} = "{VALUE}"'.format(KEY=key, VALUE=value))
else:
print(".{KEY} = {VALUE}".format(KEY=key, VALUE=value))