minor changes, fixes and cleanups

This commit is contained in:
The MMGen Project 2026-10-26 13:36:47 +00:00
commit b3e42701c5
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
10 changed files with 18 additions and 20 deletions

View file

@ -275,7 +275,7 @@ class Autosign:
self.do_umount()
self.led.set('on')
raise
except:
except: # noqa: E722 (signing must always succeed so we don’t break out of loop)
ymsg('An error occurred with {} ‘{}’'.format(target.desc, f.name))
good.append(ret) if ret else bad.append(f)
self.cfg._util.qmsg('')

View file

@ -841,8 +841,7 @@ def check_opts(cfg): # Raises exception if any check fails
try:
os.stat(fn)
except Exception:
b = os.path.dirname(fn)
if b:
if b := os.path.dirname(fn):
check_outdir(b)
else:
check_outfile(fn, blkdev_ok=True)

View file

@ -435,9 +435,7 @@ class CoinDaemon(Daemon):
(self.dfl_p2p_port + self.port_shift))
fn_stem = f'{self.id}-{self.network}-daemon-{self.bind_port}'
self.logfile = self.network_datadir / (fn_stem + '.log')
if self.use_pidfile:
self.pidfile = self.network_datadir / (fn_stem + '.pid')

View file

@ -37,8 +37,8 @@ class File:
try:
st = os.stat(str(fn))
except FileNotFoundError:
die('FileNotFound', f'{fn!s}: file not found')
except FileNotFoundError as e:
die('FileNotFound', f'{fn!s}: file not found ({e})')
import stat
if stat.S_ISBLK(st.st_mode):

View file

@ -48,8 +48,8 @@ def check_binary(args):
from subprocess import run, DEVNULL
try:
run(args, stdout=DEVNULL, stderr=DEVNULL, check=True)
except Exception:
die(2, f'{args[0]!r} binary missing, not in path, or not executable')
except Exception as e:
die(2, f'{args[0]!r} binary missing, not in path, or not executable ({e})')
def shred_file(cfg, fn, *, iterations=30):
check_binary(['shred', '--version'])
@ -137,13 +137,13 @@ def get_seed_file(cfg, *, nargs, wallets=None, invoked_as=None):
def _open_or_die(filename, mode, *, silent=False):
try:
return open(filename, mode)
except Exception:
except Exception as e:
if silent:
die(2, '')
else:
fn = {0:'STDIN', 1:'STDOUT', 2:'STDERR'}[filename] if isinstance(filename, int) else f'‘{filename}’'
desc = 'reading' if 'r' in mode else 'writing'
die(2, f'Unable to open file {fn} for {desc}')
die(2, f'Unable to open file {fn} for {desc} ({e})')
def write_data_to_file(
cfg,

View file

@ -56,7 +56,7 @@ class bitcoin_core_daemon(CoinDaemon):
['--keypool=1'],
['--rpcallowip=127.0.0.1'],
[f'--rpcbind=127.0.0.1:{self.rpc_port}'],
[f'--pid={self.pidfile}', self.use_pidfile],
[f'--pid={self.pidfile}', self.use_pidfile],
['--daemon', gc.platform in ('linux', 'darwin') and not self.opt.no_daemonize],
['--fallbackfee=0.0002', self.coin == 'BTC' and self.network == 'regtest'],
['--deprecatedrpc=create_bdb', self.coin == 'BTC' and self.opt.bdb_wallet],

View file

@ -151,7 +151,7 @@ class Token(Contract):
assert ret.startswith('0x')
return int(ret, 16)
except Exception:
msg(f'RPC call to decimals() failed (returned {ret!r})')
msg(f'RPC call to decimals() returned illegal value ({ret!r})')
async def get_total_supply(self):
return await self.do_call('totalSupply()', toUnit=True)

View file

@ -64,7 +64,6 @@ def create_shm_dir(data_dir, autosign_data_dir, trash_dir, trash_dir2):
for tdir in (autosign_data_dir, trash_dir, trash_dir2):
dest = os.path.join(shm_dir, os.path.basename(tdir))
os.mkdir(dest, 0o755)
run(f'rm -rf {tdir}', shell=True, check=True)
os.symlink(dest, tdir)
@ -191,7 +190,7 @@ po = Config(opts_data=opts_data, parse_only=True)._parsed_opts
data_dir = Config.test_datadir
# step 1: delete data_dir symlink in ./test;
# step 1: delete data_dir symlinks in test/tmp:
if not po.user_opts.get('skip_deps'):
for fn in (data_dir, autosign_data_dir):
try:
@ -199,7 +198,7 @@ if not po.user_opts.get('skip_deps'):
except:
pass
# step 2: opts.init will create new data_dir in ./test (if not po.user_opts['skip_deps'])
# step 2: opts.init will create new data_dir in test/tmp (if not po.user_opts['skip_deps'])
cfg = Config(opts_data=opts_data)
if cfg.no_altcoin and cfg.coin != 'BTC':

View file

@ -1345,8 +1345,8 @@ class CmdTestEthdev(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
cmd = [
'python3',
'scripts/create-token.py',
'--coin=' + self.proto.coin,
'--outdir=' + odir
f'--coin={self.proto.coin}',
f'--outdir={odir}'
] + cmd_args + [self.proto.checksummed_addr(dfl_devaddr)]
imsg('Executing: {}'.format(' '.join(cmd)))
if (cp := run(cmd, stdout=DEVNULL, stderr=PIPE, text=True)).returncode:

View file

@ -187,7 +187,8 @@ class CmdTestXMRAutosign(CmdTestXMRWallet, CmdTestAutosignThreaded, CmdTestShare
t = self.spawn(
'mmgen-xmrwallet',
self.extra_opts
+ ([f'--{self.user}', '--compat'] if self.compat else [])
+ [f'--{self.user}']
+ (['--compat'] if self.compat else [])
+ [f'--daemon=localhost:{data.md.rpc_port}']
+ (self.autosign_opts if autosign else [])
+ [op]
@ -340,7 +341,8 @@ class CmdTestXMRAutosign(CmdTestXMRWallet, CmdTestAutosignThreaded, CmdTestShare
args = (
self.extra_opts
+ self.autosign_opts
+ ([f'--{self.user}', '--compat'] if self.compat else [])
+ [f'--{self.user}']
+ (['--compat'] if self.compat else [])
+ [f'--daemon=localhost:{data.md.rpc_port}']
+ add_opts
+ [op]