cfg.py: do_post_init -> caller_post_init

This commit is contained in:
The MMGen Project 2024-10-08 12:56:00 +00:00
commit d95cdf49b9
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
4 changed files with 13 additions and 18 deletions

View file

@ -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)

View file

@ -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]

View file

@ -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()

View file

@ -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))