From 6ae440da35ab6d1cafef47aecf0e64bad1be405a Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 26 Oct 2026 13:36:47 +0000 Subject: [PATCH] ruff exceptions: FileNotFoundError --- mmgen/cfgfile.py | 2 +- mmgen/color.py | 2 +- mmgen/filename.py | 2 +- mmgen/fileutil.py | 6 +++--- mmgen/proto/btc/regtest.py | 2 +- mmgen/wallet/incog_hidden.py | 2 +- mmgen/xmrwallet/ops/wallet.py | 5 ++--- scripts/create-token.py | 2 +- test/cmdtest.py | 2 +- test/cmdtest_d/autosign.py | 8 ++++---- test/include/common.py | 2 +- test/modtest_d/testdep.py | 2 +- 12 files changed, 18 insertions(+), 19 deletions(-) diff --git a/mmgen/cfgfile.py b/mmgen/cfgfile.py index 5916c6a3..c72b5b5c 100644 --- a/mmgen/cfgfile.py +++ b/mmgen/cfgfile.py @@ -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 '' diff --git a/mmgen/color.py b/mmgen/color.py index 63daebfc..b5c0d365 100644 --- a/mmgen/color.py +++ b/mmgen/color.py @@ -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'))) diff --git a/mmgen/filename.py b/mmgen/filename.py index 5b626a51..d75078b8 100644 --- a/mmgen/filename.py +++ b/mmgen/filename.py @@ -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 diff --git a/mmgen/fileutil.py b/mmgen/fileutil.py index 547a8cd2..b246f40a 100644 --- a/mmgen/fileutil.py +++ b/mmgen/fileutil.py @@ -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') diff --git a/mmgen/proto/btc/regtest.py b/mmgen/proto/btc/regtest.py index 6be6c1db..a146132a 100644 --- a/mmgen/proto/btc/regtest.py +++ b/mmgen/proto/btc/regtest.py @@ -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 diff --git a/mmgen/wallet/incog_hidden.py b/mmgen/wallet/incog_hidden.py index e39b94ea..1648d980 100644 --- a/mmgen/wallet/incog_hidden.py +++ b/mmgen/wallet/incog_hidden.py @@ -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, diff --git a/mmgen/xmrwallet/ops/wallet.py b/mmgen/xmrwallet/ops/wallet.py index 2acea2cd..a37ea9ee 100644 --- a/mmgen/xmrwallet/ops/wallet.py +++ b/mmgen/xmrwallet/ops/wallet.py @@ -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): diff --git a/scripts/create-token.py b/scripts/create-token.py index e2e203de..eb2dc323 100755 --- a/scripts/create-token.py +++ b/scripts/create-token.py @@ -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 diff --git a/test/cmdtest.py b/test/cmdtest.py index d998af3b..90953b21 100755 --- a/test/cmdtest.py +++ b/test/cmdtest.py @@ -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 diff --git a/test/cmdtest_d/autosign.py b/test/cmdtest_d/autosign.py index 82b5c5cd..c65c295d 100644 --- a/test/cmdtest_d/autosign.py +++ b/test/cmdtest_d/autosign.py @@ -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() diff --git a/test/include/common.py b/test/include/common.py index 7b654ea0..862b5bff 100644 --- a/test/include/common.py +++ b/test/include/common.py @@ -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: diff --git a/test/modtest_d/testdep.py b/test/modtest_d/testdep.py index 7b0fa24d..76273cad 100644 --- a/test/modtest_d/testdep.py +++ b/test/modtest_d/testdep.py @@ -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