various exception-related changes and cleanups
This commit is contained in:
parent
1a3f11ba51
commit
988e621712
6 changed files with 21 additions and 25 deletions
|
|
@ -35,14 +35,11 @@ from .util import (
|
|||
def check_or_create_dir(cfg, path):
|
||||
try:
|
||||
os.listdir(path)
|
||||
except:
|
||||
if cfg.test_suite and os.path.exists(path): # path is a link or regular file
|
||||
from subprocess import run
|
||||
run(['rm', '-rf', str(path)])
|
||||
try:
|
||||
os.makedirs(path, 0o700)
|
||||
except:
|
||||
die(2, f'ERROR: unable to read or create path ‘{path}’')
|
||||
except FileNotFoundError:
|
||||
os.makedirs(path, 0o700) # will fail if file is a broken link
|
||||
except NotADirectoryError: # path is a good link or regular file
|
||||
os.unlink(path)
|
||||
os.makedirs(path, 0o700)
|
||||
|
||||
def check_binary(args):
|
||||
from subprocess import run, DEVNULL
|
||||
|
|
|
|||
|
|
@ -28,24 +28,21 @@ from ...objmethods import MMGenObject
|
|||
from ...daemon import CoinDaemon
|
||||
|
||||
def create_data_dir(cfg, data_dir):
|
||||
rt_dir = os.path.join(data_dir, 'regtest')
|
||||
try:
|
||||
os.stat(os.path.join(data_dir, 'regtest'))
|
||||
except:
|
||||
pass
|
||||
os.stat(rt_dir)
|
||||
except FileNotFoundError:
|
||||
os.makedirs(rt_dir)
|
||||
else:
|
||||
from ...ui import keypress_confirm
|
||||
if keypress_confirm(
|
||||
cfg,
|
||||
f'Delete your existing MMGen regtest setup at {data_dir!r} and create a new one?'):
|
||||
shutil.rmtree(data_dir)
|
||||
f'Delete your existing MMGen regtest setup at {rt_dir!r} and create a new one?'):
|
||||
shutil.rmtree(rt_dir)
|
||||
os.makedirs(rt_dir)
|
||||
else:
|
||||
die(1, 'Exiting')
|
||||
|
||||
try:
|
||||
os.makedirs(data_dir)
|
||||
except:
|
||||
pass
|
||||
|
||||
class MMGenRegtest(MMGenObject):
|
||||
|
||||
rpc_user = 'bobandalice'
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ indent-style = "tab"
|
|||
ignore = [
|
||||
"B006", # Do not use mutable data structures for argument defaults
|
||||
"BLE001", # Do not catch blind exception: `Exception`
|
||||
"E722", # bare except
|
||||
"I001", # Import block is un-sorted or un-formatted
|
||||
"N999", # Invalid module name: 'import'...
|
||||
"PLW1510", # `subprocess.run` without explicit `check` argument
|
||||
|
|
|
|||
|
|
@ -195,7 +195,10 @@ if not po.user_opts.get('skip_deps'):
|
|||
for fn in (data_dir, autosign_data_dir):
|
||||
try:
|
||||
os.unlink(fn)
|
||||
except:
|
||||
except IsADirectoryError:
|
||||
import shutil
|
||||
shutil.rmtree(fn)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
# step 2: opts.init will create new data_dir in test/tmp (if not po.user_opts['skip_deps'])
|
||||
|
|
|
|||
|
|
@ -245,11 +245,11 @@ class CmdTestAutosignBase(CmdTestBase):
|
|||
target = joinpath(getattr(self.asi, tx_dir), fn)
|
||||
if op != 'remove_signed':
|
||||
shutil.copyfile(src, target)
|
||||
try:
|
||||
if target.endswith('.rawtx'):
|
||||
if target.endswith('.rawtx'):
|
||||
try:
|
||||
os.unlink(target.replace('.rawtx', '.sigtx'))
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
self.do_umount()
|
||||
self.remove_device()
|
||||
|
|
|
|||
|
|
@ -1636,7 +1636,7 @@ class CmdTestRegtest(CmdTestBase, CmdTestShared):
|
|||
time.sleep(0.2)
|
||||
t = self.spawn('mmgen-regtest', self.regtest_opts + ['cli', 'unloadwallet', 'carol'])
|
||||
t.ok()
|
||||
wdir = joinpath((await self.rt.rpc).daemon.network_datadir, 'wallets', 'carol')
|
||||
wdir = joinpath((await self.rt.rpc).daemon.network_datadir, 'carol')
|
||||
from shutil import rmtree
|
||||
imsg('Deleting Carol’s tracking wallet')
|
||||
rmtree(wdir)
|
||||
|
|
|
|||
Loading…
Reference in a new issue