pylint fixes - entry mods

This commit is contained in:
The MMGen Project 2023-10-04 13:58:40 +00:00
commit 1cbd1a63b9
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
18 changed files with 53 additions and 90 deletions

View file

@ -1 +1 @@
14.0.dev6
14.0.dev7

View file

@ -48,32 +48,32 @@ def launch(mod,package='mmgen'):
if os.getenv('MMGEN_EXEC_WRAPPER'):
raise
else:
try:
errmsg = '{}'.format(e.args[0])
except:
errmsg = repr(e.args[0])
from collections import namedtuple
from mmgen.color import nocolor,yellow,red
try:
errmsg = str(e.args[0])
except:
errmsg = repr(e.args[0])
_o = namedtuple('exit_data',['color','exit_val','fs'])
d = {
0: _o(nocolor, 0, '{message}'),
1: _o(nocolor, 1, '{message}'),
2: _o(yellow, 2, '{message}'),
3: _o(yellow, 3, '\nMMGen Error ({name}):\n{message}'),
4: _o(red, 4, '\nMMGen Fatal Error ({name}):\n{message}'),
'x': _o(yellow, 5, '\nMMGen Unhandled Exception ({name}):\n{message}'),
}[getattr(e,'mmcode','x')]
from collections import namedtuple
from mmgen.color import nocolor,yellow,red
(sys.stdout if getattr(e,'stdout',None) else sys.stderr).write(
d.color(d.fs.format(
name = type(e).__name__,
message = errmsg ))
+ '\n' )
_o = namedtuple('exit_data',['color','exit_val','fs'])
d = {
0: _o(nocolor, 0, '{message}'),
1: _o(nocolor, 1, '{message}'),
2: _o(yellow, 2, '{message}'),
3: _o(yellow, 3, '\nMMGen Error ({name}):\n{message}'),
4: _o(red, 4, '\nMMGen Fatal Error ({name}):\n{message}'),
'x': _o(yellow, 5, '\nMMGen Unhandled Exception ({name}):\n{message}'),
}[getattr(e,'mmcode','x')]
sys.exit(d.exit_val)
(sys.stdout if getattr(e,'stdout',None) else sys.stderr).write(
d.color(d.fs.format(
name = type(e).__name__,
message = errmsg ))
+ '\n' )
sys.exit(d.exit_val)
except SystemExit as e:
if os.getenv('MMGEN_EXEC_WRAPPER') and e.code != 0:

View file

@ -21,15 +21,12 @@ mmgen-addrgen: Generate a series or range of addresses from an MMGen
deterministic wallet
"""
import mmgen.opts as opts
import mmgen.addrlist
from .cfg import gc,Config
from .addr import MMGenAddrType
from .addrfile import AddrFile
from .wallet import Wallet
import mmgen.addrlist
if gc.prog_name == 'mmgen-keygen':
gen_what = 'keys'
gen_clsname = 'KeyAddrList'
@ -46,10 +43,10 @@ else:
opts_data = {
'sets': [('print_checksum',True,'quiet',True)],
'text': {
'desc': """
Generate a range or list of {desc} from an {pnm} wallet,
'desc': f"""
Generate a range or list of {gen_desc} from an {gc.proj_name} wallet,
mnemonic, seed or brainwallet
""".format(desc=gen_desc,pnm=gc.proj_name),
""",
'usage':'[opts] [seed source] <index list or range(s)>',
'options': """
-h, --help Print this help message

View file

@ -22,11 +22,9 @@ mmgen-addrimport: Import addresses into a MMGen coin daemon tracking wallet
from collections import namedtuple
import mmgen.opts as opts
from .cfg import gc,Config
from .util import msg,suf,die,fmt,async_run
from .addrlist import AddrList,KeyAddrList
from .tw.shared import TwLabel
opts_data = {
'text': {
@ -127,7 +125,7 @@ def check_opts(twctl):
from .ui import keypress_confirm
if not keypress_confirm(
cfg,
'\n{}\n\nContinue?'.format(addrimport_msgs['rescan']),
f'\n{addrimport_msgs["rescan"]}\n\nContinue?',
default_yes = True ):
die(1,'Exiting at user request')
@ -171,7 +169,7 @@ async def main():
def gen_args_list(al):
_d = namedtuple('import_data',['addr','twmmid','comment'])
for num,e in enumerate(al.data,1):
for e in al.data:
yield _d(
addr = e.addr,
twmmid = f'{al.al_id}:{e.idx}' if e.idx else f'{proto.base_coin.lower()}:{e.addr}',

View file

@ -20,9 +20,6 @@
autosign: Auto-sign MMGen transactions, message files and XMR wallet output files
"""
import sys
from .cfg import Config
from .util import msg,die,fmt_list,exit_if_mswin,async_run
exit_if_mswin('autosigning')

View file

@ -13,13 +13,11 @@ 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,die
from .msg import (
NewMsg,
CompletedMsg,
UnsignedMsg,
SignedMsg,
SignedOnlineMsg,

View file

@ -21,7 +21,6 @@ mmgen-passgen: Generate a series or range of passwords from an MMGen
deterministic wallet
"""
import mmgen.opts as opts
from .cfg import gc,Config
from .addrlist import AddrIdxList
from .passwdlist import PasswordList
@ -43,7 +42,7 @@ opts_data = {
--, --longhelp Print help message for long options (common options)
-d, --outdir= d Output files to directory 'd' instead of working dir
-e, --echo-passphrase Echo passphrase or mnemonic to screen upon entry
-f, --passwd-fmt= f Generate passwords of format 'f'. Default: {dpf}.
-f, --passwd-fmt= f Generate passwords of format 'f'. Default: {pl.dfl_pw_fmt}.
See PASSWORD FORMATS below
-i, --in-fmt= f Input is from wallet format 'f' (see FMT CODES below)
-H, --hidden-incog-input-params=f,o Read hidden incognito data from file
@ -115,14 +114,13 @@ FMT CODES:
},
'code': {
'options': lambda cfg,help_notes,s: s.format(
pnm=gc.proj_name,
dsl=help_notes('dfl_seed_len'),
dpf=PasswordList.dfl_pw_fmt,
cfg=cfg,
dsl=help_notes('dfl_seed_len'),
pl=PasswordList,
gc=gc,
),
'notes': lambda cfg,help_notes,s: s.format(
o=opts,cfg=cfg,i58=pwi['b58'],i32=pwi['b32'],i39=pwi['bip39'],
cfg=cfg,i58=pwi['b58'],i32=pwi['b32'],i39=pwi['bip39'],
ml=MMGenPWIDString.max_len,
fs="', '".join(MMGenPWIDString.forbidden),
n_pw=help_notes('passwd'),

View file

@ -21,7 +21,6 @@ mmgen-regtest: Coin daemon regression test mode setup and operations for the MMG
suite
"""
import mmgen.opts as opts
from .cfg import gc,Config
from .util import die,async_run

View file

@ -21,11 +21,9 @@ mmgen-seedjoin: Regenerate an MMGen deterministic wallet from seed shares
created by 'mmgen-seedsplit'
"""
import mmgen.opts as opts
from .cfg import gc,Config
from .util import msg,msg_r,die
from .color import yellow
from .obj import MMGenWalletLabel
from .seed import Seed
from .seedsplit import SeedSplitIDString,MasterShareIdx,SeedShareMasterJoining
from .wallet import Wallet

View file

@ -23,9 +23,7 @@ mmgen-split: Split funds after a replayable chain fork using a timelocked transa
UNMAINTAINED
"""
import time
from .cfg import Config
from .cfg import Config,gc
from .util import gmsg,die
opts_data = {
@ -95,7 +93,7 @@ die(1,'This command is disabled')
# the following code is broken:
cfg.other_coin = cfg.other_coin.upper() if cfg.other_coin else proto.forks[-1][2].upper()
if cfg.other_coin.lower() not in [e[2] for e in proto.forks if e[3] == True]:
if cfg.other_coin.lower() not in [e[2] for e in proto.forks if e[3] is True]:
die(1,f'{cfg.other_coin!r}: not a replayable fork of {proto.coin} chain')
if len(cfg._args) != 2:
@ -103,7 +101,7 @@ if len(cfg._args) != 2:
from .addr import MMGenID
try:
mmids = [MMGenID(a) for a in cfg._args]
mmids = [MMGenID(proto,a) for a in cfg._args]
except:
die(1,'Command line arguments must be valid MMGen IDs')
@ -117,9 +115,9 @@ if cfg.tx_fees:
for idx,g_coin in ((1,cfg.other_coin),(0,proto.coin)):
proto = init_proto( cfg, g_coin )
cfg.fee = cfg.tx_fees.split(',')[idx]
opts.opt_is_tx_fee('foo',cfg.fee,'transaction fee') # raises exception on error
# opts.opt_is_tx_fee('foo',cfg.fee,'transaction fee') # raises exception on error
tx1 = MMGenSplitTX()
tx1 = MMGenSplitTX(proto)
cfg.no_blank = True
async def main():
@ -136,9 +134,9 @@ async def main():
gmsg(f'\nCreating transaction for short chain ({cfg.other_coin})')
proto = init_proto( self.cfg, cfg.other_coin )
proto2 = init_proto( cfg, cfg.other_coin )
tx2 = MMGenSplitTX()
tx2 = MMGenSplitTX(proto2)
tx2.inputs = tx1.inputs
tx2.inputs.convert_coin()

View file

@ -22,7 +22,6 @@ mmgen-tool: Perform various MMGen- and cryptocoin-related operations.
"""
import sys,os,importlib
import mmgen.opts as opts
from .cfg import gc,Config
from .util import msg,Msg,die,capfirst,suf,async_run
@ -202,22 +201,18 @@ def create_call_sig(cmd,cls,as_string=False):
get_type_from_ann = lambda x: 'str or STDIN' if ann[x] == 'sstr' else ann[x].__name__
return ' '.join(
[f'{a} [{get_type_from_ann(a)}]' for a in args[:nargs]] +
['{a} [{b}={c!r}]'.format(
a = a,
b = dfl_types[n].__name__,
c = dfls[n] )
for n,a in enumerate(args[nargs:])] )
[f'{a} [{dfl_types[n].__name__}={dfls[n]!r}]' for n,a in enumerate(args[nargs:])] )
else:
get_type_from_ann = lambda x: 'str' if ann[x] == 'sstr' else ann[x].__name__
return (
[(a,get_type_from_ann(a)) for a in args[:nargs]], # c_args
dict([(a,dfls[n]) for n,a in enumerate(args[nargs:])]), # c_kwargs
dict([(a,dfl_types[n]) for n,a in enumerate(args[nargs:])]), # c_kwargs_types
{a:dfls[n] for n,a in enumerate(args[nargs:])}, # c_kwargs
{a:dfl_types[n] for n,a in enumerate(args[nargs:])}, # c_kwargs_types
('STDIN_OK' if nargs and ann[args[0]] == 'sstr' else flag), # flag
ann ) # ann
def process_args(cmd,cmd_args,cls):
c_args,c_kwargs,c_kwargs_types,flag,ann = create_call_sig(cmd,cls)
c_args,c_kwargs,c_kwargs_types,flag,_ = create_call_sig(cmd,cls)
have_stdin_input = False
def usage_die(s):
@ -269,7 +264,7 @@ def process_args(cmd,cmd_args,cls):
usage_die(f'{k!r}: invalid keyword argument')
def conv_type(arg,arg_name,arg_type):
if arg_type == 'bytes' and type(arg) != bytes:
if arg_type == 'bytes' and not isinstance(arg,bytes):
die(1,"'Binary input data must be supplied via STDIN")
if have_stdin_input and arg_type == 'str' and isinstance(arg,bytes):
@ -295,7 +290,7 @@ def process_args(cmd,cmd_args,cls):
args = [conv_type(u_args[i],c_args[0][0],c_args[0][1]) for i in range(len(u_args))]
else:
args = [conv_type(u_args[i],c_args[i][0],c_args[i][1]) for i in range(len(c_args))]
kwargs = {k:conv_type(u_kwargs[k],k,c_kwargs_types[k].__name__) for k in u_kwargs}
kwargs = {k:conv_type(v,k,c_kwargs_types[k].__name__) for k,v in u_kwargs.items()}
return ( args, kwargs )
@ -317,7 +312,7 @@ def process_result(ret,pager=False,print_result=False):
else:
return o
if ret == True:
if ret is True:
return True
elif ret in (False,None):
die(2,f'tool command returned {ret!r}')
@ -332,10 +327,7 @@ def process_result(ret,pager=False,print_result=False):
return triage_result(ret.decode())
except:
# don't add NL to binary data if it can't be converted to utf8
if print_result:
return os.write(1,ret)
else:
return ret
return os.write(1,ret) if print_result else ret
else:
die(2,f'tool.py: can’t handle return value of type {type(ret).__name__!r}')
@ -343,8 +335,7 @@ def get_cmd_cls(cmd):
for modname,cmdlist in mods.items():
if cmd in cmdlist:
return getattr(importlib.import_module(f'mmgen.tool.{modname}'),'tool_cmd')
else:
return False
return False
def get_mod_cls(modname):
return getattr(importlib.import_module(f'mmgen.tool.{modname}'),'tool_cmd')

View file

@ -21,11 +21,9 @@ mmgen-txbump: Increase the fee on a replaceable (replace-by-fee) MMGen
transaction, and optionally sign and send it
"""
import mmgen.opts as opts
from .cfg import gc,Config
from .util import msg,msg_r,die,async_run
from .color import green
from .wallet import Wallet
opts_data = {
'sets': [('yes', True, 'quiet', True)],
@ -118,7 +116,7 @@ seed_files = get_seed_files(cfg,cfg._args) if (cfg._args or cfg.send) else None
from .ui import do_license_msg
do_license_msg(cfg)
silent = cfg.yes and cfg.fee != None and cfg.output_to_reduce != None
silent = cfg.yes and cfg.fee is not None and cfg.output_to_reduce is not None
async def main():

View file

@ -21,7 +21,6 @@ mmgen-txcreate: Create a cryptocoin transaction with MMGen- and/or non-MMGen
inputs and outputs
"""
import mmgen.opts as opts
from .cfg import gc,Config
from .util import fmt_list,async_run

View file

@ -20,17 +20,16 @@
mmgen-txdo: Create, sign and broadcast an online MMGen transaction
"""
import mmgen.opts as opts
from .cfg import gc,Config
from .util import die,fmt_list,async_run
from .wallet import Wallet
from .subseed import SubSeedIdxRange
opts_data = {
'sets': [('yes', True, 'quiet', True)],
'text': {
'desc': f'Create, sign and send an {gc.proj_name} transaction',
'usage': '[opts] [<addr,amt> ...] <change addr, addrlist ID or addr type> [addr file ...] [seed source ...]',
'usage': '[opts] [<addr,amt> ...] <change addr, addrlist ID or addr type> [addr file ...] ' +
'[seed source ...]',
'options': """
-h, --help Print this help message
--, --longhelp Print help message for long options (common options)

View file

@ -22,7 +22,6 @@ mmgen-txsend: Broadcast a transaction signed by 'mmgen-txsign' to the network
import sys
import mmgen.opts as opts
from .cfg import gc,Config
from .util import async_run

View file

@ -20,11 +20,9 @@
mmgen-txsign: Sign a transaction generated by 'mmgen-txcreate'
"""
import mmgen.opts as opts
from .cfg import gc,Config
from .util import msg,ymsg,suf,die,async_run
from .subseed import SubSeedIdxRange
from .wallet import Wallet
from .color import orange
# -w, --use-wallet-dat (keys from running coin daemon) removed: use walletdump rpc instead

View file

@ -21,7 +21,6 @@ main_wallet: Entry point for MMGen wallet-related scripts
"""
import sys,os
import mmgen.opts as opts
from .cfg import gc,Config
from .color import green,yellow
from .util import msg,gmsg_r,ymsg,bmsg,die,capfirst

View file

@ -21,11 +21,8 @@ mmgen-xmrwallet: Perform various Monero wallet and transacting operations for
addresses in an MMGen XMR key-address file
"""
from collections import namedtuple
import mmgen.opts as opts
from .cfg import gc,Config
from .util import ymsg,die,async_run
from .util import die,async_run
from .xmrwallet import (
MoneroWalletOps,
xmrwallet_uarg_info,