From fb44c5720e2d66392d17482bb72c2bd90695f45c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dirk=20M=C3=BCller?= Date: Thu, 27 Oct 2022 00:22:09 +0200 Subject: [PATCH 1/2] avoid bare except --- osc/build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osc/build.py b/osc/build.py index 6e867d59..1b01c957 100644 --- a/osc/build.py +++ b/osc/build.py @@ -78,7 +78,7 @@ class Buildinfo: localpkgs = localpkgs or [] try: tree = ET.parse(filename) - except: + except ET.ParseError: print('could not parse the buildinfo:', file=sys.stderr) print(open(filename).read(), file=sys.stderr) sys.exit(1) @@ -802,7 +802,7 @@ def main(apiurl, opts, argv): try: build_root = build_root % {'repo': repo, 'arch': arch, 'project': prj, 'package': pacname, 'apihost': apihost} - except: + except KeyError: pass # We configure sccache after pacname, so that in default cases we can have an sccache for each From adb1a9b4ef212b39fa092397579b43bf9538c973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dirk=20M=C3=BCller?= Date: Thu, 27 Oct 2022 00:22:28 +0200 Subject: [PATCH 2/2] mark boolean and integer_opts as private It is unused elsewhere, and only used for unit-testing --- osc/conf.py | 19 ++++++++++--------- tests/test_conf.py | 12 ++++-------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/osc/conf.py b/osc/conf.py index d663d809..7734b80c 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -186,28 +186,29 @@ if not os.path.isfile('/usr/bin/build') and os.path.isfile('/usr/bin/obs-build') if not os.path.isfile('/usr/lib/build/vc') and os.path.isfile('/usr/lib/obs-build/vc'): DEFAULTS['vc-cmd'] = '/usr/lib/obs-build/vc' -boolean_opts = ['debug', 'do_package_tracking', 'http_debug', 'post_mortem', 'traceback', 'check_filelist', - 'checkout_no_colon', 'checkout_rooted', 'check_for_request_on_action', 'linkcontrol', 'show_download_progress', 'request_show_interactive', - 'request_show_source_buildstatus', 'review_inherit_group', 'use_keyring', 'no_verify', 'builtin_signature_check', - 'http_full_debug', 'include_request_from_project', 'local_service_run', 'buildlog_strip_time', 'no_preinstallimage', - 'status_mtime_heuristic', 'print_web_links', 'ccache', 'sccache', 'build-shell-after-fail'] -integer_opts = ['build-jobs'] - api_host_options = ['user', 'pass', 'passx', 'aliases', 'http_headers', 'realname', 'email', 'sslcertck', 'cafile', 'capath', 'trusted_prj', 'downloadurl', 'sshkey'] +_integer_opts = ('build-jobs',) +_boolean_opts = ( + 'debug', 'do_package_tracking', 'http_debug', 'post_mortem', 'traceback', 'check_filelist', + 'checkout_no_colon', 'checkout_rooted', 'check_for_request_on_action', 'linkcontrol', 'show_download_progress', 'request_show_interactive', + 'request_show_source_buildstatus', 'review_inherit_group', 'use_keyring', 'no_verify', 'builtin_signature_check', + 'http_full_debug', 'include_request_from_project', 'local_service_run', 'buildlog_strip_time', 'no_preinstallimage', + 'status_mtime_heuristic', 'print_web_links', 'ccache', 'sccache', 'build-shell-after-fail') + def apply_option_types(config, conffile=""): """ Return a copy of `config` dictionary with values converted to their expected types - according to the enumerated option types (boolean_opts, integer_opts). + according to the enumerated option types (_boolean_opts, _integer_opts). """ config = config.copy() cp = OscConfigParser.OscConfigParser(config) cp.add_section("general") - typed_opts = ((boolean_opts, cp.getboolean), (integer_opts, cp.getint)) + typed_opts = ((_boolean_opts, cp.getboolean), (_integer_opts, cp.getint)) for opts, meth in typed_opts: for opt in opts: try: diff --git a/tests/test_conf.py b/tests/test_conf.py index 39e1f4dd..dd21ddd7 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -14,29 +14,25 @@ class TestConf(unittest.TestCase): importlib.reload(osc.conf) def test_bool_opts_defaults(self): - opts = osc.conf.boolean_opts config = osc.conf.config - for opt in opts: + for opt in osc.conf._boolean_opts: self.assertIsInstance(config[opt], bool, msg=f"option: '{opt}'") def test_int_opts_defaults(self): - opts = osc.conf.integer_opts config = osc.conf.config - for opt in opts: + for opt in osc.conf._integer_opts: self.assertIsInstance(config[opt], int, msg=f"option: '{opt}'") def test_bool_opts(self): osc.conf.get_config() - opts = osc.conf.boolean_opts config = osc.conf.config - for opt in opts: + for opt in osc.conf._boolean_opts: self.assertIsInstance(config[opt], bool, msg=f"option: '{opt}'") def test_int_opts(self): osc.conf.get_config() - opts = osc.conf.integer_opts config = osc.conf.config - for opt in opts: + for opt in osc.conf._integer_opts: self.assertIsInstance(config[opt], int, msg=f"option: '{opt}'")