devtools: rename pretty-print functions and methods
This commit is contained in:
parent
3d004c3600
commit
c90bc087e0
7 changed files with 23 additions and 18 deletions
|
|
@ -474,7 +474,7 @@ Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file
|
|||
|
||||
out.append(e)
|
||||
if g.debug_addrlist:
|
||||
Msg('generate():\n{}'.format(e.pformat()))
|
||||
Msg('generate():\n{}'.format(e.pfmt()))
|
||||
|
||||
qmsg('\r{}: {} {}{} generated{}'.format(
|
||||
self.al_id.hl(),t_addrs,self.gen_desc,suf(t_addrs,self.gen_desc_pl),' '*15))
|
||||
|
|
@ -579,7 +579,7 @@ Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file
|
|||
qmsg_r('\rGenerating addresses from keylist: {}/{}'.format(n,len(d)))
|
||||
e.addr = ag.to_addr(kg.to_pubhex(e.sec))
|
||||
if g.debug_addrlist:
|
||||
Msg('generate_addrs_from_keys():\n{}'.format(e.pformat()))
|
||||
Msg('generate_addrs_from_keys():\n{}'.format(e.pfmt()))
|
||||
qmsg('\rGenerated addresses from keylist: {}/{} '.format(n,len(d)))
|
||||
|
||||
def format(self,enable_comments=False):
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ class MMGenListItem(MMGenObject):
|
|||
if self.valid_attrs == None:
|
||||
type(self).valid_attrs = (
|
||||
( {e for e in dir(self) if e[:2] != '__'} | self.valid_attrs_extra ) -
|
||||
{'pformat','pmsg','pdie','valid_attrs','valid_attrs_extra'} )
|
||||
{'pfmt','pmsg','pdie','valid_attrs','valid_attrs_extra'} )
|
||||
if args:
|
||||
raise ValueError('Non-keyword args not allowed')
|
||||
for k in kwargs:
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ def send(addr,amt):
|
|||
def show_mempool():
|
||||
p = start_cmd('cli','getrawmempool')
|
||||
from ast import literal_eval
|
||||
msg(mmgen_pformat(literal_eval(p.stdout.read().decode())))
|
||||
pp_msg(literal_eval(p.stdout.read().decode()))
|
||||
p.wait()
|
||||
|
||||
def cli(*args):
|
||||
|
|
|
|||
|
|
@ -818,8 +818,8 @@ Selected non-{pnm} inputs: {{}}""".strip().format(pnm=g.proj_name,pnl=g.proj_nam
|
|||
|
||||
def check_equal(desc,hexio,mmio):
|
||||
if mmio != hexio:
|
||||
msg('\nMMGen {}:\n{}'.format(desc,mmgen_pformat(mmio)))
|
||||
msg('Hex {}:\n{}'.format(desc,mmgen_pformat(hexio)))
|
||||
msg('\nMMGen {}:\n{}'.format(desc,pp_fmt(mmio)))
|
||||
msg('Hex {}:\n{}'.format(desc,pp_fmt(hexio)))
|
||||
m2 = '{} in hex transaction data from coin daemon do not match those in MMGen transaction!\n'
|
||||
raise TxHexMismatch((m2+m).format(desc.capitalize()))
|
||||
|
||||
|
|
|
|||
|
|
@ -90,9 +90,11 @@ def Die(ev=0,s=''):
|
|||
def rdie(ev=0,s=''): die(ev,red(s))
|
||||
def ydie(ev=0,s=''): die(ev,yellow(s))
|
||||
|
||||
def mmgen_pformat(d):
|
||||
def pp_fmt(d):
|
||||
import pprint
|
||||
return pprint.PrettyPrinter(indent=4,compact=True).pformat(d)
|
||||
def pp_msg(d):
|
||||
msg(pp_fmt(d))
|
||||
|
||||
def set_for_type(val,refval,desc,invert_bool=False,src=None):
|
||||
src_str = (''," in '{}'".format(src))[bool(src)]
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class unit_test(object):
|
|||
seed2.subseeds._generate(10)
|
||||
assert len(ss2_list) == 10, len(ss2_list)
|
||||
|
||||
assert seed.pformat() == seed2.pformat()
|
||||
assert seed.pfmt() == seed2.pfmt()
|
||||
|
||||
s = seed.subseeds.format(1,g.subseeds)
|
||||
s_lines = s.strip().split('\n')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue