From ad4505f1497e1768c31d9c950c43ada278fdd212 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 27 Jul 2024 09:16:42 +0000 Subject: [PATCH] Config: add `_set_quiet()` method --- mmgen/cfg.py | 7 ++++++- mmgen/tool/wallet.py | 10 +++++----- test/tooltest2.py | 6 +++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/mmgen/cfg.py b/mmgen/cfg.py index b25ddcc7..ce255356 100755 --- a/mmgen/cfg.py +++ b/mmgen/cfg.py @@ -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 diff --git a/mmgen/tool/wallet.py b/mmgen/tool/wallet.py index 3d33d030..61628069 100755 --- a/mmgen/tool/wallet.py +++ b/mmgen/tool/wallet.py @@ -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: diff --git a/test/tooltest2.py b/test/tooltest2.py index 36c4b665..d9b9d1a4 100755 --- a/test/tooltest2.py +++ b/test/tooltest2.py @@ -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):