diff options
author | Christian Heimes <cheimes@redhat.com> | 2015-07-15 10:42:31 +0200 |
---|---|---|
committer | Christian Heimes <cheimes@redhat.com> | 2015-08-10 11:58:44 +0200 |
commit | 8ae5ec7f3774d81a1c3d79c2a05649de65b8658c (patch) | |
tree | 565f6b1b697fdcfcc2fef0b6b5860ef28b2d458d /base/server | |
parent | a51b8b657f90e69d4c6eaaaf4c24af6501331668 (diff) | |
download | pki-8ae5ec7f3774d81a1c3d79c2a05649de65b8658c.tar.gz pki-8ae5ec7f3774d81a1c3d79c2a05649de65b8658c.tar.xz pki-8ae5ec7f3774d81a1c3d79c2a05649de65b8658c.zip |
Simplify exception handling in pkihelper
Several methods except OSError before they except shutil.Error. In
Python 3 the second except clause will be ignored because in Python 3
shutil.Error is a subclass of OSError.
The body of the except clauses only differs in the logging message. A
single except clause with an isinstance() check has the same effect.
Diffstat (limited to 'base/server')
-rw-r--r-- | base/server/python/pki/server/deployment/pkihelper.py | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/base/server/python/pki/server/deployment/pkihelper.py b/base/server/python/pki/server/deployment/pkihelper.py index b6ee61b27..cf04e68bc 100644 --- a/base/server/python/pki/server/deployment/pkihelper.py +++ b/base/server/python/pki/server/deployment/pkihelper.py @@ -1460,14 +1460,12 @@ class Directory: dir_perms, file_perms, symlink_perms, dir_acls, file_acls, symlink_acls, recursive_flag, critical_failure) - except OSError as exc: - config.pki_log.error(log.PKI_OSERROR_1, exc, - extra=config.PKI_INDENTATION_LEVEL_2) - if critical_failure: - raise - except shutil.Error as exc: - config.pki_log.error(log.PKI_SHUTIL_ERROR_1, exc, - extra=config.PKI_INDENTATION_LEVEL_2) + except (shutil.Error, OSError) as exc: + if isinstance(exc, shutil.Error): + msg = log.PKI_SHUTIL_ERROR_1 + else: + msg = log.PKI_OSERROR_1 + config.pki_log.error(msg, exc, extra=config.PKI_INDENTATION_LEVEL_2) if critical_failure: raise return @@ -1665,14 +1663,12 @@ class File: record.permissions = perms record.acls = acls self.manifest_db.append(record) - except OSError as exc: - config.pki_log.error(log.PKI_OSERROR_1, exc, - extra=config.PKI_INDENTATION_LEVEL_2) - if critical_failure: - raise - except shutil.Error as exc: - config.pki_log.error(log.PKI_SHUTIL_ERROR_1, exc, - extra=config.PKI_INDENTATION_LEVEL_2) + except (shutil.Error, OSError) as exc: + if isinstance(exc, shutil.Error): + msg = log.PKI_SHUTIL_ERROR_1 + else: + msg = log.PKI_OSERROR_1 + config.pki_log.error(msg, exc, extra=config.PKI_INDENTATION_LEVEL_2) if critical_failure: raise return @@ -1725,14 +1721,12 @@ class File: record.permissions = perms record.acls = acls self.manifest_db.append(record) - except OSError as exc: - config.pki_log.error(log.PKI_OSERROR_1, exc, - extra=config.PKI_INDENTATION_LEVEL_2) - if critical_failure: - raise - except shutil.Error as exc: - config.pki_log.error(log.PKI_SHUTIL_ERROR_1, exc, - extra=config.PKI_INDENTATION_LEVEL_2) + except (shutil.Error, OSError) as exc: + if isinstance(exc, shutil.Error): + msg = log.PKI_SHUTIL_ERROR_1 + else: + msg = log.PKI_OSERROR_1 + config.pki_log.error(msg, exc, extra=config.PKI_INDENTATION_LEVEL_2) if critical_failure: raise return @@ -1797,14 +1791,12 @@ class File: record.permissions = perms record.acls = acls self.manifest_db.append(record) - except OSError as exc: - config.pki_log.error(log.PKI_OSERROR_1, exc, - extra=config.PKI_INDENTATION_LEVEL_2) - if critical_failure: - raise - except shutil.Error as exc: - config.pki_log.error(log.PKI_SHUTIL_ERROR_1, exc, - extra=config.PKI_INDENTATION_LEVEL_2) + except (shutil.Error, OSError) as exc: + if isinstance(exc, shutil.Error): + msg = log.PKI_SHUTIL_ERROR_1 + else: + msg = log.PKI_OSERROR_1 + config.pki_log.error(msg, exc, extra=config.PKI_INDENTATION_LEVEL_2) if critical_failure: raise return |