opts.init() -> Config()

This commit is contained in:
The MMGen Project 2023-04-04 16:04:10 +00:00
commit 9e1935ad19
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
44 changed files with 126 additions and 93 deletions

View file

@ -14,7 +14,7 @@ examples.halving-calculator.py: Demonstrate use of the MMGen asyncio/aiohttp JSO
import time
import mmgen.opts as opts
from mmgen.cfg import Config
from mmgen.util import async_run
opts_data = {
@ -39,7 +39,7 @@ mmgen-node-tools repository.
}
}
cfg = opts.init(opts_data)
cfg = Config(opts_data=opts_data)
def date(t):
return '{}-{:02}-{:02} {:02}:{:02}:{:02}'.format(*time.gmtime(t)[:6])

View file

@ -791,8 +791,7 @@ if __name__ == '__main__':
}
}
from mmgen.opts import init
cfg = init( opts_data, need_amt=False )
cfg = Config( opts_data=opts_data, need_amt=False )
msg('Checking CoinInfo WIF/P2PKH/P2SH version numbers and trust levels against protocol.py')
CoinInfo.verify_core_coin_data( cfg, cfg.quiet, cfg.verbose )

View file

@ -402,3 +402,38 @@ class Config(Lockable):
'mainnet': (self.data_dir_root,),
}[self.network] ))
return self._data_dir
def __init__(
self,
cfg = None,
opts_data = None,
add_opts = None,
init_opts = None,
opt_filter = None,
parse_only = False,
parsed_opts = None,
need_proto = True,
need_amt = True,
do_post_init = False,
process_opts = False ):
if opts_data or parsed_opts or process_opts:
import mmgen.opts as opts
self._opts = opts
opts.init(
cfg = self,
opts_data = opts_data,
add_opts = add_opts,
init_opts = init_opts,
opt_filter = opt_filter,
parse_only = parse_only,
parsed_opts = parsed_opts,
need_proto = need_proto,
need_amt = need_amt,
do_post_init = do_post_init )
if do_post_init:
self._post_init = opts.post_init

View file

@ -20,7 +20,7 @@
contrib.license: Copyright notice and text of GPLv3
"""
from ..globalvars import gc
from ..cfg import gc
warning = f"""
{gc.proj_name} Copyright (C) {gc.Cdates} by {gc.author} {gc.email}. This

View file

@ -123,13 +123,12 @@ def get_seed_file(cfg,nargs,wallets=None,invoked_as=None):
wd_from_opt = bool(cfg.hidden_incog_input_params or cfg.in_fmt) # have wallet data from opt?
import mmgen.opts as opts
if len(wallets) + (wd_from_opt or bool(wf)) < nargs:
if not wf:
msg('No default wallet found, and no other seed source was specified')
opts.usage()
cfg._opts.usage()
elif len(wallets) > nargs:
opts.usage()
cfg._opts.usage()
elif len(wallets) == nargs and wf and invoked_as != 'gen':
cfg._util.qmsg('Warning: overriding default wallet with user-supplied wallet')

View file

@ -126,7 +126,7 @@ FMT CODES:
}
}
cfg = opts.init(opts_data,opt_filter=opt_filter,need_amt=False)
cfg = Config( opts_data=opts_data, opt_filter=opt_filter, need_amt=False )
proto = cfg._proto
@ -136,7 +136,7 @@ addr_type = MMGenAddrType(
errmsg = f'{cfg.type!r}: invalid parameter for --type option' )
if len(cfg._args) < 1:
opts.usage()
cfg._opts.usage()
if cfg.keygen_backend:
from .keygen import check_backend

View file

@ -186,7 +186,7 @@ async def main():
del twctl
cfg = opts.init(opts_data,need_amt=False)
cfg = Config( opts_data=opts_data, need_amt=False )
proto = cfg._proto

View file

@ -25,7 +25,7 @@ from subprocess import run,PIPE,DEVNULL
from collections import namedtuple
from stat import *
import mmgen.opts as opts
from .cfg import Config
from .util import msg,msg_r,ymsg,rmsg,gmsg,bmsg,die,suf,fmt_list,async_run,exit_if_mswin
from .color import yellow,red,orange
@ -120,8 +120,8 @@ This command is currently available only on Linux-based platforms.
}
}
cfg = opts.init(
opts_data,
cfg = Config(
opts_data = opts_data,
add_opts = ['outdir','passwd_file'], # in _set_ok, so must be set
init_opts = {
'quiet': True,
@ -433,7 +433,7 @@ async def do_loop():
n += 1
if len(cmd_args) not in (0,1):
opts.usage()
cfg._opts.usage()
if len(cmd_args) == 1:
cmd = cmd_args[0]

View file

@ -14,6 +14,7 @@ mmgen-msg: Message signing operations for the MMGen suite
import sys
import mmgen.opts as opts
from .cfg import Config
from .base_obj import AsyncInit
from .util import msg,suf,async_run
from .msg import (
@ -203,12 +204,12 @@ $ mmgen-msg verify signatures.json
}
}
cfg = opts.init(opts_data,need_amt=False)
cfg = Config( opts_data=opts_data, need_amt=False )
cmd_args = cfg._args
if len(cmd_args) < 2:
opts.usage()
cfg._opts.usage()
op = cmd_args.pop(0)
@ -218,15 +219,15 @@ if cfg.msghash_type and op != 'create':
async def main():
if op == 'create':
if len(cmd_args) < 2:
opts.usage()
cfg._opts.usage()
MsgOps.create( cmd_args[0], ' '.join(cmd_args[1:]) )
elif op == 'sign':
if len(cmd_args) < 1:
opts.usage()
cfg._opts.usage()
await MsgOps.sign( cmd_args[0], cmd_args[1:] )
elif op in ('verify','export'):
if len(cmd_args) not in (1,2):
opts.usage()
cfg._opts.usage()
await getattr(MsgOps,op)( cmd_args[0], cmd_args[1] if len(cmd_args) == 2 else None )
else:
die(1,f'{op!r}: unrecognized operation')

View file

@ -134,9 +134,10 @@ FMT CODES:
}
}
cfg = opts.init(opts_data)
cfg = Config(opts_data=opts_data)
if len(cfg._args) < 2: opts.usage()
if len(cfg._args) < 2:
cfg._opts.usage()
pw_idxs = AddrIdxList(fmt_str=cfg._args.pop())

View file

@ -57,7 +57,7 @@ opts_data = {
}
}
cfg = opts.init(opts_data)
cfg = Config(opts_data=opts_data)
cmd_args = cfg._args
@ -77,7 +77,7 @@ def check_num_args():
die(1,m.format(args,'many','more',amax))
if not cmd_args:
opts.usage()
cfg._opts.usage()
elif cmd_args[0] not in MMGenRegtest.usr_cmds:
die(1,f'{cmd_args[0]!r}: invalid command')
elif cmd_args[0] not in ('cli','wallet_cli','balances'):

View file

@ -110,10 +110,10 @@ def print_shares_info():
out += f'{n:3}: {s.sid}\n'
cfg._util.qmsg(out)
cfg = opts.init(opts_data)
cfg = Config(opts_data=opts_data)
if len(cfg._args) + bool(cfg.hidden_incog_input_params) < 2:
opts.usage()
cfg._opts.usage()
if cfg.master_share:
master_idx = MasterShareIdx(cfg.master_share)

View file

@ -86,7 +86,7 @@ transaction reconfirmed before the timelock expires. Use at your own risk.
}
}
cfg = opts.init(opts_data,need_amt=False)
cfg = Config( opts_data=opts_data, need_amt=False )
proto = cfg._proto

View file

@ -347,7 +347,8 @@ def get_mod_cls(modname):
if gc.prog_name == 'mmgen-tool':
po = opts.init( opts_data, parse_only=True )
cfg = Config( opts_data=opts_data, parse_only=True )
po = cfg._parsed_opts
if po.user_opts.get('list'):
def gen():
@ -362,7 +363,7 @@ if gc.prog_name == 'mmgen-tool':
sys.exit(0)
if len(po.cmd_args) < 1:
opts.usage()
cfg._opts.usage()
cmd = po.cmd_args[0]
@ -371,11 +372,12 @@ if gc.prog_name == 'mmgen-tool':
if not cls:
die(1,f'{cmd!r}: no such command')
cfg = opts.init(
cfg = Config(
opts_data,
parsed_opts = po,
need_proto = cls.need_proto,
init_opts = {'rpc_backend':'aiohttp'} if cmd == 'twimport' else None )
init_opts = {'rpc_backend':'aiohttp'} if cmd == 'twimport' else None,
process_opts = True )
cmd,*args = cfg._args

View file

@ -103,7 +103,7 @@ FMT CODES:
}
}
cfg = opts.init(opts_data)
cfg = Config(opts_data=opts_data)
tx_file = cfg._args.pop(0)

View file

@ -79,7 +79,7 @@ opts_data = {
}
}
cfg = opts.init(opts_data)
cfg = Config(opts_data=opts_data)
async def main():

View file

@ -123,7 +123,7 @@ FMT CODES:
}
}
cfg = opts.init(opts_data)
cfg = Config(opts_data=opts_data)
from .tx import NewTX,OnlineSignedTX
from .tx.sign import txsign,get_seed_files,get_keyaddrlist,get_keylist

View file

@ -42,14 +42,14 @@ opts_data = {
}
}
cfg = opts.init(opts_data)
cfg = Config(opts_data=opts_data)
if len(cfg._args) == 1:
infile = cfg._args[0]
from .fileutil import check_infile
check_infile(infile)
else:
opts.usage()
cfg._opts.usage()
if not cfg.status:
from .ui import do_license_msg

View file

@ -99,12 +99,12 @@ FMT CODES:
}
}
cfg = opts.init(opts_data)
cfg = Config(opts_data=opts_data)
infiles = cfg._args
if not infiles:
opts.usage()
cfg._opts.usage()
from .fileutil import check_infile
for i in infiles:

View file

@ -145,7 +145,7 @@ FMT CODES:
}
}
cfg = opts.init(opts_data,opt_filter=opt_filter,need_proto=False)
cfg = Config( opts_data=opts_data, opt_filter=opt_filter, need_proto=False )
cmd_args = cfg._args
@ -166,17 +166,17 @@ elif invoked_as == 'seedsplit':
m2 = 'To generate a master share, omit the seed split specifier.'
die(1,m1+' '+m2)
elif not sss:
opts.usage()
cfg._opts.usage()
elif master_share:
sss = SeedSplitSpecifier('1:2')
else:
opts.usage()
cfg._opts.usage()
from .fileutil import check_infile,get_seed_file
if cmd_args:
if invoked_as == 'gen' or len(cmd_args) > 1:
opts.usage()
cfg._opts.usage()
check_infile(cmd_args[0])
sf = get_seed_file(cfg,nargs,invoked_as=invoked_as)

Some files were not shown because too many files have changed in this diff Show more