cic-cli/cic/utils.py
William Luke 60e8ecc41a
Some checks failed
continuous-integration/drone/push Build is failing
fix: bump ci
2022-04-26 14:12:43 +03:00

25 lines
845 B
Python

def object_to_str(obj, keys):
"""Return a string representation of an object."""
s = ""
for key in keys:
value = eval("obj." + key)
key = key.replace("()", "")
if isinstance(value, str):
s += f"{key} = {value}\n"
elif isinstance(value, list):
for idx, vv in enumerate(value):
if not vv:
s += f"{key}[{idx}] = \n"
continue
s += f"{key}[{idx}] = {vv}\n"
elif isinstance(value, dict):
for vv_key in value.keys():
vv_value = value[vv_key]
if not vv_value:
s += f"{key}.{vv_key} = \n"
continue
s += f"{key}.{vv_key} = {vv_value}\n"
else:
s += f"{key} = {str(value)}\n"
return s