debugging tool

This commit is contained in:
.[d]. 2022-10-05 18:55:33 -05:00
parent f07dec500d
commit cc707f8dee

106
tool_ezd_methods_plugin.py Normal file
View File

@ -0,0 +1,106 @@
# -*- coding: utf-8 -*- ############################################################### SOF
import re,ipdb
###########################################################################################
# find types:
# - types[methods] populate methods list
# - types[str,bool,list,dict] populate data_[str,bool,list,dict] lists
###########################################################################################
async def dump_methods(literal,explicit,blacklist) -> None:
#######################################################################################
print('\n[ getting types ]\n')
methods=[]; data_str=[]; data_bool=[]; data_list=[]; data_dict=[]
for _dir in dir(explicit):
cmde=f"explicit.{_dir}"
cmdl=f"{literal}.{_dir}"
try:
_type=type(eval(cmde))
if _type==str:
data_str.append([cmdl,eval(cmde)])
if _type==bool:
data_bool.append([cmdl,eval(cmde)])
if _type==list:
data_list.append([cmdl,eval(cmde)])
if _type==dict:
data_dict.append([cmdl,eval(cmde)])
if str(_type)=="<class 'method'>":
if not _dir.startswith('_'):
methods.append(cmde)
except Exception as e:
print(f'<<< error >>> {cmdl} - {str(e).lower()}')
#######################################################################################
print('\n[ probing methods ]\n')
results=[]
for i,m in enumerate(methods):
ceiling=len(methods)
key=m.split('explicit.')[1]
if not key in blacklist:
print(f'[{str(i+1).zfill(len(str(ceiling)))}/{ceiling}] - {literal}.{key}')
try:
results.append([f'{literal}.{key}',await eval(m)()])
except Exception as e:
results.append([f'{literal}.{key}',str(e).lower()])
else:
results.append([f'{literal}.{key}',f'blacklist: {blacklist}'])
#######################################################################################
dump_results_log=[]
dump_results_log.append("results data_str"); dump_results_log.append(data_str)
dump_results_log.append("results data_bool"); dump_results_log.append(data_bool)
dump_results_log.append("results data_list"); dump_results_log.append(data_list)
dump_results_log.append("results data_dict"); dump_results_log.append(data_dict)
dump_results_log.append("results methods"); dump_results_log.append(results)
print('\n[ results data_str ]\n')
dump_results(data_str,['__doc__'])
print('\n[ results data_bool ]\n')
dump_results(data_bool,[])
print('\n[ results data_list ]\n')
dump_results(data_list,[])
print('\n[ results data_dict ]\n')
dump_results(data_dict,[])
print('\n[ results methods ]\n')
dump_results(results,[])
#######################################################################################
print('\n[ methods uniques ]\n')
ceiling=len(methods)
maxlen=0
uniques=[]
for i,_ in enumerate(results):
if not type(_[1])==str and not type(_[1])==list and not str(type(_[1]))=="<class 'NoneType'>":
_dir=[]
for d in dir(_[1]):
if not d.startswith('_'):
_dir.append(d)
if len(str(type(_[1])))>maxlen: maxlen=len(str(type(_[1])))
uniques.append([f'[{str(i+1).zfill(len(str(ceiling)))}/{ceiling}]',type(_[1]),_dir])
for _ in uniques:
spacing=maxlen-len(str(_[1]))
print(f'{_[0]} - {_[1]}{" "*spacing} - {_[2]}')
#######################################################################################
# this section below that is commented out is where you break into post specific detail
#######################################################################################
#
# if literal=='client':
# nowdothis(results)
# elif literal=="server":
# nowdothat(results)
ipdb.set_trace()
###########################################################################################
def dump_results(datalist,blacklist):
maxlen=0
for _ in datalist:
if len(_[0])>maxlen: maxlen=len(_[0])
try:
for i,_ in enumerate(datalist):
spacing=0
if len(_[0])<=maxlen:
spacing=maxlen-len(_[0])
if not _[0].split('.')[-1] in blacklist:
chunks = re.findall(r'.{1,129}(?:\s+|$)', str(_[1]).replace("\n",""))
for chunk in chunks:
print(f'[{str(i+1).zfill(3)}/{len(datalist)}] - {_[0]}{" "*spacing} - {chunk}')
else:
print(f'[{str(i+1).zfill(3)}/{len(datalist)}] - {_[0]}{" "*spacing} - blacklist: {blacklist}')
except:
print(f'[{str(i+1).zfill(3)}/{len(datalist)}] - {_[0]}{" "*spacing} - {str(_[1])}')
####################################################################################### EOF