From 97f26015c6792e54e20fa7a77db0644ca563e486 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 2 Feb 2021 14:40:29 +0100 Subject: [PATCH] [fix] kill all bare exceptions --- src/yunohost/backup.py | 12 ++++++------ src/yunohost/certificate.py | 2 +- src/yunohost/dyndns.py | 2 +- src/yunohost/firewall.py | 14 +++++++------- src/yunohost/regenconf.py | 6 +++--- src/yunohost/service.py | 4 ++-- src/yunohost/settings.py | 2 +- src/yunohost/tools.py | 4 ++-- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index 0392619de..50765ba5f 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -735,7 +735,7 @@ class BackupManager: } write_to_yaml("%s/permissions.yml" % settings_dir, this_app_permissions) - except: + except Exception: abs_tmp_app_dir = os.path.join(self.work_dir, "apps/", app) shutil.rmtree(abs_tmp_app_dir, ignore_errors=True) logger.error(m18n.n("backup_app_failed", app=app)) @@ -1507,7 +1507,7 @@ class RestoreManager: raise_on_error=True, env=env_dict, )[0] - except: + except Exception: msg = m18n.n("restore_app_failed", app=app_instance_name) logger.error(msg) operation_logger.error(msg) @@ -1944,7 +1944,7 @@ class TarBackupMethod(BackupMethod): self._archive_file, "w:gz" if self._archive_file.endswith(".gz") else "w", ) - except: + except Exception: logger.debug( "unable to open '%s' for writing", self._archive_file, exc_info=1 ) @@ -1995,7 +1995,7 @@ class TarBackupMethod(BackupMethod): self._archive_file, "r:gz" if self._archive_file.endswith(".gz") else "r", ) - except: + except Exception: logger.debug( "cannot open backup archive '%s'", self._archive_file, exc_info=1 ) @@ -2466,7 +2466,7 @@ def backup_info(name, with_details=False, human_readable=False): with open(info_file) as f: # Retrieve backup info info = json.load(f) - except: + except Exception: logger.debug("unable to load '%s'", info_file, exc_info=1) raise YunohostError( "backup_archive_cant_retrieve_info_json", archive=archive_file @@ -2552,7 +2552,7 @@ def backup_delete(name): for backup_file in files_to_delete: try: os.remove(backup_file) - except: + except Exception: logger.debug("unable to delete '%s'", backup_file, exc_info=1) logger.warning(m18n.n("backup_delete_error", path=backup_file)) diff --git a/src/yunohost/certificate.py b/src/yunohost/certificate.py index 566c56df1..556af267b 100644 --- a/src/yunohost/certificate.py +++ b/src/yunohost/certificate.py @@ -107,7 +107,7 @@ def certificate_status(domain_list, full=False): try: _check_domain_is_ready_for_ACME(domain) status["ACME_eligible"] = True - except: + except Exception: status["ACME_eligible"] = False del status["domain"] diff --git a/src/yunohost/dyndns.py b/src/yunohost/dyndns.py index 50fa8cce1..d94748881 100644 --- a/src/yunohost/dyndns.py +++ b/src/yunohost/dyndns.py @@ -182,7 +182,7 @@ def dyndns_subscribe( os.system("rm -f %s" % key_file) try: error = json.loads(r.text)["error"] - except: + except Exception: error = 'Server error, code: %s. (Message: "%s")' % (r.status_code, r.text) raise YunohostError("dyndns_registration_failed", error=error) diff --git a/src/yunohost/firewall.py b/src/yunohost/firewall.py index f9b872c10..28fa768de 100644 --- a/src/yunohost/firewall.py +++ b/src/yunohost/firewall.py @@ -335,7 +335,7 @@ def firewall_upnp(action="status", no_refresh=False): try: # Remove old cron job os.remove("/etc/cron.d/yunohost-firewall") - except: + except Exception: pass action = "status" no_refresh = False @@ -360,7 +360,7 @@ def firewall_upnp(action="status", no_refresh=False): try: # Remove cron job os.remove(UPNP_CRON_JOB) - except: + except Exception: pass enabled = False if action == "status": @@ -384,7 +384,7 @@ def firewall_upnp(action="status", no_refresh=False): try: # Select UPnP device upnpc.selectigd() - except: + except Exception: logger.debug("unable to select UPnP device", exc_info=1) enabled = False else: @@ -396,7 +396,7 @@ def firewall_upnp(action="status", no_refresh=False): if upnpc.getspecificportmapping(port, protocol): try: upnpc.deleteportmapping(port, protocol) - except: + except Exception: pass firewall["uPnP"][protocol + "_TO_CLOSE"] = [] @@ -405,7 +405,7 @@ def firewall_upnp(action="status", no_refresh=False): if upnpc.getspecificportmapping(port, protocol): try: upnpc.deleteportmapping(port, protocol) - except: + except Exception: pass if not enabled: continue @@ -419,7 +419,7 @@ def firewall_upnp(action="status", no_refresh=False): "yunohost firewall: port %d" % port, "", ) - except: + except Exception: logger.debug( "unable to add port %d using UPnP", port, exc_info=1 ) @@ -488,7 +488,7 @@ def _get_ssh_port(default=22): m = searchf(r"^Port[ \t]+([0-9]+)$", "/etc/ssh/sshd_config", count=-1) if m: return int(m) - except: + except Exception: pass return default diff --git a/src/yunohost/regenconf.py b/src/yunohost/regenconf.py index c99f34a1c..924818e44 100644 --- a/src/yunohost/regenconf.py +++ b/src/yunohost/regenconf.py @@ -445,7 +445,7 @@ def _get_regenconf_infos(): try: with open(REGEN_CONF_FILE, "r") as f: return yaml.load(f) - except: + except Exception: return {} @@ -498,7 +498,7 @@ def _get_files_diff(orig_file, new_file, as_string=False, skip_header=True): try: next(diff) next(diff) - except: + except Exception: pass if as_string: @@ -683,7 +683,7 @@ def _process_regen_conf(system_conf, new_conf=None, save=True): # Raise an exception if an os.stat() call on either pathname fails. # (os.stats returns a series of information from a file like type, size...) copy_succeed = os.path.samefile(system_conf, new_conf) - except: + except Exception: copy_succeed = False finally: if not copy_succeed: diff --git a/src/yunohost/service.py b/src/yunohost/service.py index 00eeb1bd9..bc72301da 100644 --- a/src/yunohost/service.py +++ b/src/yunohost/service.py @@ -673,7 +673,7 @@ def _get_services(): try: with open("/etc/yunohost/services.yml", "r") as f: services = yaml.load(f) or {} - except: + except Exception: return {} # some services are marked as None to remove them from YunoHost @@ -807,7 +807,7 @@ def _get_journalctl_logs(service, number="all"): systemd_service, number ) ) - except: + except Exception: import traceback return ( diff --git a/src/yunohost/settings.py b/src/yunohost/settings.py index a56e40aad..9bf75ff1d 100644 --- a/src/yunohost/settings.py +++ b/src/yunohost/settings.py @@ -157,7 +157,7 @@ def settings_set(key, value): if isinstance(value, str): try: value = int(value) - except: + except Exception: raise YunohostError( "global_settings_bad_type_for_setting", setting=key, diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index b1d74883e..696dc4ece 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -171,7 +171,7 @@ def tools_adminpw(new_password, check_strength=True): "userPassword": [new_hash], }, ) - except: + except Exception: logger.error("unable to change admin password") raise YunohostError("admin_password_change_failed") else: @@ -315,7 +315,7 @@ def tools_postinstall( # If an exception is thrown, most likely we don't have internet # connectivity or something. Assume that this domain isn't manageable # and inform the user that we could not contact the dyndns host server. - except: + except Exception: logger.warning( m18n.n("dyndns_provider_unreachable", provider=dyndns_provider) )