ruff exceptions: FileNotFoundError

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

View file

@ -44,7 +44,7 @@ class cfg_file:
try:
with open(fn) as fp:
return fp.read().splitlines()
except:
except FileNotFoundError:
if self.warn_missing:
self.warn_missing_file(div=fn, fmt_args=(self.desc, fn))
return ''

View file

@ -58,7 +58,7 @@ def get_terminfo_colors(term=None):
try:
cmdout = run(cmd, stdout=PIPE, check=True, text=True).stdout
except:
except FileNotFoundError:
return None
else:
s = next(iter(e.split('#', 1)[1] for e in cmdout.split(',') if e.startswith('colors')))

View file

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

View file

@ -80,7 +80,7 @@ def _check_file_type_and_access(fname, ftype, *, blkdev_ok=False):
try:
mode = os.stat(fname).st_mode
except:
except FileNotFoundError:
die('FileNotFound', f'Requested {ftype} ‘{fname}’ not found')
for t in ok_types:
@ -190,7 +190,7 @@ def write_data_to_file(
else:
try:
of = os.readlink(f'/proc/{os.getpid()}/fd/1') # Linux
except:
except FileNotFoundError:
of = None # Windows
if of:
@ -250,7 +250,7 @@ def write_data_to_file(
try:
with open(outfile, ('r', 'rb')[bool(binary)]) as fp:
d = fp.read()
except:
except FileNotFoundError:
pass
if d != cmp_data:
die(3, f'{desc} in file {outfile!r} has been altered by some other program! Aborting file write')

View file

@ -315,7 +315,7 @@ class MMGenRegtest(MMGenObject):
try:
os.stat(source_rt.d.datadir)
except:
except FileNotFoundError:
die(1, f'Source directory {source_rt.d.datadir!r} does not exist!')
# stop the source daemon

View file

@ -97,7 +97,7 @@ class wallet(wallet):
check_offset = True
try:
os.stat(fn)
except:
except FileNotFoundError:
from ..ui import keypress_confirm, line_input
keypress_confirm(
self.cfg,

View file

@ -116,10 +116,9 @@ class OpWallet(OpBase):
def stat_wallet(fn):
try:
fn.stat()
except:
return False
else:
return True
except FileNotFoundError:
return False
@classmethod
def get_idx_from_fn(cls, fn):

View file

@ -100,7 +100,7 @@ def check_solc_version():
"""
try:
cp = run(['solc', '--version'], check=True, text=True, stdout=PIPE)
except:
except FileNotFoundError:
msg('solc missing or could not be executed') # this must go to stderr
return False

View file

@ -108,7 +108,7 @@ from test.include.common import (
try:
os.unlink(os.path.join(repo_root, cmdtest_py_error_fn))
except:
except FileNotFoundError:
pass
os.environ['MMGEN_TEST_SUITE_LEGACY_TX'] = '1' # disabled for spawned scripts

View file

@ -143,7 +143,7 @@ class CmdTestAutosignBase(CmdTestBase):
try:
run([cmd, str(self.txdev.img_path), label], check=True)
break
except:
except FileNotFoundError:
if cmd == 'e2label':
raise
@ -161,7 +161,7 @@ class CmdTestAutosignBase(CmdTestBase):
try:
run([cmd] + args, stdout=redir, stderr=redir, check=True)
break
except:
except FileNotFoundError:
if cmd == 'mkfs.ext2':
raise
self.txdev.detach(silent=True)
@ -248,7 +248,7 @@ class CmdTestAutosignBase(CmdTestBase):
try:
if target.endswith('.rawtx'):
os.unlink(target.replace('.rawtx', '.sigtx'))
except:
except FileNotFoundError:
pass
self.do_umount()
@ -887,7 +887,7 @@ class CmdTestAutosign(CmdTestAutosignBase):
for fn in fns:
try:
os.unlink(fn)
except:
except FileNotFoundError:
pass
self.bad_tx_count = 0
self.do_umount()

View file

@ -342,7 +342,7 @@ def get_ethkey():
for cmdname in cmdnames:
try:
cp = run([cmdname, '--help'], stdout=PIPE, text=True)
except:
except FileNotFoundError:
pass
else:
if 'Parity' in cp.stdout:

View file

@ -30,7 +30,7 @@ class unit_tests:
try:
run([cmd, '-f'], check=True, stdout=DEVNULL)
break
except:
except FileNotFoundError:
if cmd == 'losetup':
raise
return True