From d95cdf49b950c942d9228abe0309765dd67618df Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 8 Oct 2024 12:56:00 +0000 Subject: [PATCH] cfg.py: `do_post_init` -> `caller_post_init` --- mmgen/base_obj.py | 3 ++- mmgen/cfg.py | 17 ++++++++++------- mmgen/main_autosign.py | 2 +- mmgen/opts.py | 9 --------- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/mmgen/base_obj.py b/mmgen/base_obj.py index caddb56c..09eaa31e 100755 --- a/mmgen/base_obj.py +++ b/mmgen/base_obj.py @@ -50,6 +50,7 @@ class AttrCtrl(metaclass=AttrCtrlMeta): _use_class_attr = False _default_to_none = False _skip_type_check = () + _delete_ok = () def _lock(self): self._locked = True @@ -88,7 +89,7 @@ class AttrCtrl(metaclass=AttrCtrlMeta): return object.__setattr__(self,name,value) def __delattr__(self,name): - if self._locked: + if self._locked and not name in self._delete_ok: raise AttributeError('attribute cannot be deleted') return object.__delattr__(self,name) diff --git a/mmgen/cfg.py b/mmgen/cfg.py index 23a961ab..c6234d3f 100755 --- a/mmgen/cfg.py +++ b/mmgen/cfg.py @@ -143,6 +143,7 @@ class Config(Lockable): _autolock = False _set_ok = ('usr_randchars','_proto') _reset_ok = ('accept_defaults',) + _delete_ok = ('_opts',) _use_class_attr = True _default_to_none = True @@ -442,8 +443,8 @@ class Config(Lockable): parsed_opts = None, need_proto = True, need_amt = True, - do_post_init = False, - process_opts = False ): + caller_post_init = False, + process_opts = False): # Step 1: get user-supplied configuration data from # a) command line, or @@ -564,12 +565,17 @@ class Config(Lockable): self._proto = init_proto_from_cfg(self,need_amt=need_amt) warn_trustlevel(self) # do this after initializing proto - if self._opts and not do_post_init: - self._opts.init_bottom(self) + if self._opts and not caller_post_init: + self._post_init() # Check user-set opts without modifying them check_opts(self) + def _post_init(self): + if self.help or self.longhelp: + self._opts.init_bottom(self) # exits + del self._opts + def _usage(self): from .help import make_usage_str print(make_usage_str(self, caller='user')) @@ -723,9 +729,6 @@ class Config(Lockable): elif key in cfgfile_auto_typeset_opts: do_set(key, cfgfile_auto_typeset_opts[key], ref_type) - def _post_init(self): - return self._opts.init_bottom(self) - def _die_on_incompatible_opts(self): for group in self._incompatible_opts: bad = [k for k in self.__dict__ if k in group and getattr(self,k) is not None] diff --git a/mmgen/main_autosign.py b/mmgen/main_autosign.py index 017b202a..f5aa5de1 100755 --- a/mmgen/main_autosign.py +++ b/mmgen/main_autosign.py @@ -192,7 +192,7 @@ cfg = Config( 'hash_preset': '1', 'label': 'Autosign Wallet', }, - do_post_init = True ) + caller_post_init = True) cmd = cfg._args[0] if len(cfg._args) == 1 else 'sign' if not cfg._args else cfg._usage() diff --git a/mmgen/opts.py b/mmgen/opts.py index ed5f0fba..c0fb8f51 100755 --- a/mmgen/opts.py +++ b/mmgen/opts.py @@ -136,19 +136,10 @@ class UserOpts: return def init_bottom(self,cfg): - # print help screen only after globals initialized and locked: if cfg.help or cfg.longhelp: self.print_help(cfg) # exits - # delete unneeded data: - for k in ('text','notes','code'): - if k in self.opts_data: - del self.opts_data[k] - del Opts.make_help - del Opts.process_uopts - del Opts.parse_opts - def usage(self): from .util import Die Die(1,Opts.make_usage_str(gc.prog_name,'user',self.usage_data))