Config: add _set_quiet() method

This commit is contained in:
The MMGen Project 2024-07-27 09:16:42 +00:00
commit ad4505f149
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
3 changed files with 14 additions and 9 deletions

View file

@ -115,7 +115,7 @@ class Config(Lockable):
"""
_autolock = False
_set_ok = ('usr_randchars','_proto')
_reset_ok = ('accept_defaults','quiet','verbose','yes')
_reset_ok = ('accept_defaults',)
_use_class_attr = True
_default_to_none = True
@ -692,6 +692,11 @@ class Config(Lockable):
if len(bad) > 1:
die(1,'Conflicting options: {}'.format(', '.join(map(fmt_opt,bad))))
def _set_quiet(self,val):
from .util import Util
self.__dict__['quiet'] = val
self.__dict__['_util'] = Util(self) # qmsg, qmsg_r
def check_opts(cfg): # Raises exception if any check fails
from .util import is_int,Msg

View file

@ -42,18 +42,18 @@ class tool_cmd(tool_cmd_base):
def get_subseed(self,subseed_idx:str,wallet=''):
"get the Seed ID of a single subseed by Subseed Index for default or specified wallet"
self.cfg.quiet = True
self.cfg._set_quiet(True)
return Wallet(self.cfg,self._get_seed_file(wallet)).seed.subseed(subseed_idx).sid
def get_subseed_by_seed_id(self,seed_id:str,wallet='',last_idx=SubSeedList.dfl_len):
"get the Subseed Index of a single subseed by Seed ID for default or specified wallet"
self.cfg.quiet = True
self.cfg._set_quiet(True)
ret = Wallet(self.cfg,self._get_seed_file(wallet)).seed.subseed_by_seed_id( seed_id, last_idx )
return ret.ss_idx if ret else None
def list_subseeds(self,subseed_idx_range:str,wallet=''):
"list a range of subseed Seed IDs for default or specified wallet"
self.cfg.quiet = True
self.cfg._set_quiet(True)
from ..subseed import SubSeedIdxRange
return Wallet(self.cfg,self._get_seed_file(wallet)).seed.subseeds.format(
*SubSeedIdxRange(subseed_idx_range) )
@ -64,7 +64,7 @@ class tool_cmd(tool_cmd_base):
master_share: f'(min:1, max:{MasterShareIdx.max_val}, 0=no master share)' = 0,
wallet = '' ):
"list the Seed IDs of the shares resulting from a split of default or specified wallet"
self.cfg.quiet = True
self.cfg._set_quiet(True)
return Wallet(self.cfg,self._get_seed_file(wallet)).seed.split(
share_count, id_str, master_share ).format()
@ -81,7 +81,7 @@ class tool_cmd(tool_cmd_base):
from ..addrlist import AddrList,AddrIdxList
addr = MMGenID( self.proto, mmgen_addr )
self.cfg.quiet = True
self.cfg._set_quiet(True)
ss = Wallet(self.cfg,self._get_seed_file(wallet))
if ss.seed.sid != addr.sid:

View file

@ -116,7 +116,7 @@ async def call_method(cls,method,cmd_name,args,mmtype,stdin_input):
aargs,kwargs = main_tool.process_args(cmd_name,args,cls)
oq_save = bool(cfg.quiet)
if not cfg.verbose:
cfg.quiet = True
cfg._set_quiet(True)
if stdin_input:
fd0,fd1 = os.pipe()
if os.fork(): # parent
@ -126,7 +126,7 @@ async def call_method(cls,method,cmd_name,args,mmtype,stdin_input):
cmd_out = method(*aargs,**kwargs)
os.dup2(stdin_save,0)
os.wait()
cfg.quiet = oq_save
cfg._set_quiet(oq_save)
return cmd_out
else: # child
os.close(fd0)
@ -137,7 +137,7 @@ async def call_method(cls,method,cmd_name,args,mmtype,stdin_input):
ret = method(*aargs,**kwargs)
if type(ret).__name__ == 'coroutine':
ret = await ret
cfg.quiet = oq_save
cfg._set_quiet(oq_save)
return ret
def tool_api(cls,cmd_name,args,opts):