WizardKit/scripts/wk/debug.py

52 lines
1.2 KiB
Python

"""WizardKit: Debug Functions"""
# pylint: disable=invalid-name
# vim: sts=2 sw=2 ts=2
# Classes
class Debug():
# pylint: disable=too-few-public-methods
"""Object used when dumping debug data."""
def method(self):
"""Dummy method used to identify functions vs data."""
# STATIC VARIABLES
DEBUG_CLASS = Debug()
METHOD_TYPE = type(DEBUG_CLASS.method)
# Functions
def generate_object_report(obj, indent=0):
"""Generate debug report for obj, returns list."""
report = []
attr_list = []
# Get attribute list
if hasattr(obj, '__slots__'):
attr_list = list(obj.__slots__)
else:
attr_list = [name for name in dir(obj) if not name.startswith('_')]
# Dump object data
for name in attr_list:
attr = getattr(obj, name)
# Skip methods
if isinstance(attr, METHOD_TYPE):
continue
# Add attribute to report (expanded if necessary)
if isinstance(attr, dict):
report.append(f'{name}:')
for key, value in attr.items():
report.append(f'{" "*(indent+1)}{key}: {str(value)}')
else:
report.append(f'{" "*indent}{name}: {str(attr)}')
# Done
return report
if __name__ == '__main__':
print("This file is not meant to be called directly.")