|
@@ -1,6 +1,6 @@
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
-import sys,os,pprint,traceback,re,json
|
|
|
+import sys,os,re,traceback,json,pprint
|
|
|
from decimal import Decimal
|
|
|
from difflib import unified_diff
|
|
|
|
|
@@ -33,9 +33,9 @@ def print_stack_trace(message):
|
|
|
class MMGenObject(object):
|
|
|
|
|
|
# Pretty-print any object subclassed from MMGenObject, recursing into sub-objects - WIP
|
|
|
- def pmsg(self): print(self.pformat())
|
|
|
- def pdie(self): print(self.pformat()); sys.exit(0)
|
|
|
- def pformat(self,lvl=0,id_list=[]):
|
|
|
+ def pmsg(self): print(self.pfmt())
|
|
|
+ def pdie(self): print(self.pfmt()); sys.exit(0)
|
|
|
+ def pfmt(self,lvl=0,id_list=[]):
|
|
|
scalars = (str,int,float,Decimal)
|
|
|
def do_list(out,e,lvl=0,is_dict=False):
|
|
|
out.append('\n')
|
|
@@ -43,8 +43,9 @@ class MMGenObject(object):
|
|
|
el = i if not is_dict else e[i]
|
|
|
if is_dict:
|
|
|
out.append('{s}{:<{l}}'.format(i,s=' '*(4*lvl+8),l=10,l2=8*(lvl+1)+8))
|
|
|
- if hasattr(el,'pformat'):
|
|
|
- out.append('{:>{l}}{}'.format('',el.pformat(lvl=lvl+1,id_list=id_list+[id(self)]),l=(lvl+1)*8))
|
|
|
+ if hasattr(el,'pfmt'):
|
|
|
+ out.append('{:>{l}}{}'.format('',el.pfmt(
|
|
|
+ lvl=lvl+1,id_list=id_list+[id(self)]),l=(lvl+1)*8))
|
|
|
elif isinstance(el,scalars):
|
|
|
if isList(e):
|
|
|
out.append('{:>{l}}{:16}\n'.format('',repr(el),l=lvl*8))
|
|
@@ -57,7 +58,8 @@ class MMGenObject(object):
|
|
|
out.append('\n')
|
|
|
do_list(out,el,lvl=lvl+1,is_dict=isDict(el))
|
|
|
else:
|
|
|
- out.append('{:>{l}}{:16} {}\n'.format('','<'+type(el).__name__+'>',repr(el),l=(lvl*8)+8))
|
|
|
+ out.append('{:>{l}}{:16} {}\n'.format(
|
|
|
+ '','<'+type(el).__name__+'>',repr(el),l=(lvl*8)+8))
|
|
|
out.append('\n')
|
|
|
if not e: out.append('{}\n'.format(repr(e)))
|
|
|
|
|
@@ -84,13 +86,14 @@ class MMGenObject(object):
|
|
|
# print repr(self.__dict__.keys())
|
|
|
|
|
|
for k in self.__dict__:
|
|
|
- if k in ('_OrderedDict__root','_OrderedDict__map'): continue # exclude these because of recursion
|
|
|
+ if k in ('_OrderedDict__root','_OrderedDict__map'): continue # excluded because of recursion
|
|
|
e = getattr(self,k)
|
|
|
if isList(e) or isDict(e):
|
|
|
out.append('{:>{l}}{:<10} {:16}'.format('',k,'<'+type(e).__name__+'>',l=(lvl*8)+4))
|
|
|
do_list(out,e,lvl=lvl,is_dict=isDict(e))
|
|
|
- elif hasattr(e,'pformat') and type(e) != type:
|
|
|
- out.append('{:>{l}}{:10} {}'.format('',k,e.pformat(lvl=lvl+1,id_list=id_list+[id(self)]),l=(lvl*8)+4))
|
|
|
+ elif hasattr(e,'pfmt') and type(e) != type:
|
|
|
+ out.append('{:>{l}}{:10} {}'.format(
|
|
|
+ '',k,e.pfmt(lvl=lvl+1,id_list=id_list+[id(self)]),l=(lvl*8)+4))
|
|
|
else:
|
|
|
out.append('{:>{l}}{:<10} {:16} {}\n'.format(
|
|
|
'',k,'<'+type(e).__name__+'>',repr(e),l=(lvl*8)+4))
|