From 4ce79a7eaa5cfa1f438d9934b13e74eff896c079 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Wed, 1 Jun 2022 22:52:22 +0200 Subject: [PATCH] explicitly re-raising exceptions To fix pylint. --- fdroidserver/apksigcopier.py | 4 ++-- fdroidserver/build.py | 6 +++--- fdroidserver/checkupdates.py | 4 ++-- fdroidserver/common.py | 24 ++++++++++++------------ fdroidserver/update.py | 2 +- fdroidserver/verify.py | 2 +- fdroidserver/vmtools.py | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/fdroidserver/apksigcopier.py b/fdroidserver/apksigcopier.py index adc3e507..50a26945 100644 --- a/fdroidserver/apksigcopier.py +++ b/fdroidserver/apksigcopier.py @@ -147,8 +147,8 @@ def noautoyes(value): return value try: return {False: NO, None: AUTO, True: YES}[value] - except KeyError: - raise ValueError("expected False, None, or True") + except KeyError as exc: + raise ValueError("expected False, None, or True") from exc def is_meta(filename): diff --git a/fdroidserver/build.py b/fdroidserver/build.py index d7cf8ca5..a358d7d3 100644 --- a/fdroidserver/build.py +++ b/fdroidserver/build.py @@ -131,7 +131,7 @@ def build_server(app, build, vcs, build_dir, output_dir, log_dir, force): sshinfo['user'] + "@" + sshinfo['hostname'] + ":" + ftp.getcwd()], stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: - raise FDroidException(str(e), e.output.decode()) + raise FDroidException(str(e), e.output.decode()) from e logging.info("Preparing server for build...") serverpath = os.path.abspath(os.path.dirname(__file__)) @@ -290,10 +290,10 @@ def build_server(app, build, vcs, build_dir, output_dir, log_dir, force): ftp.get(apkfile, os.path.join(output_dir, apkfile)) if not options.notarball: ftp.get(tarball, os.path.join(output_dir, tarball)) - except Exception: + except Exception as exc: raise BuildException( "Build failed for {0}:{1} - missing output files".format( - app.id, build.versionName), str(output, 'utf-8')) + app.id, build.versionName), str(output, 'utf-8')) from exc ftp.close() finally: diff --git a/fdroidserver/checkupdates.py b/fdroidserver/checkupdates.py index 86a18c2e..d781fc4e 100644 --- a/fdroidserver/checkupdates.py +++ b/fdroidserver/checkupdates.py @@ -495,8 +495,8 @@ def checkupdates_app(app): if pattern.startswith('+'): try: suffix, pattern = pattern[1:].split(' ', 1) - except ValueError: - raise MetaDataException("Invalid AutoUpdateMode: " + mode) + except ValueError as exc: + raise MetaDataException("Invalid AutoUpdateMode: " + mode) from exc gotcur = False latest = None diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 36ec0071..cf490682 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -480,14 +480,14 @@ def parse_human_readable_size(size): } try: return int(float(size)) - except (ValueError, TypeError): + except (ValueError, TypeError) as exc: if type(size) != str: raise ValueError(_('Could not parse size "{size}", wrong type "{type}"') - .format(size=size, type=type(size))) + .format(size=size, type=type(size))) from exc s = size.lower().replace(' ', '') m = re.match(r'^(?P[0-9][0-9.]*) *(?P' + r'|'.join(units.keys()) + r')$', s) if not m: - raise ValueError(_('Not a valid size definition: "{}"').format(size)) + raise ValueError(_('Not a valid size definition: "{}"').format(size)) from exc return int(float(m.group("value")) * units[m.group("unit")]) @@ -793,8 +793,8 @@ def publishednameinfo(filename): m = publish_name_regex.match(filename) try: result = (m.group(1), m.group(2)) - except AttributeError: - raise FDroidException(_("Invalid name for published file: %s") % filename) + except AttributeError as exc: + raise FDroidException(_("Invalid name for published file: %s") % filename) from exc return result @@ -1350,7 +1350,7 @@ class vcs_gitsvn(vcs): r = requests.head(remote) r.raise_for_status() except Exception as e: - raise VCSException('SVN certificate pre-validation failed: ' + str(e)) + raise VCSException('SVN certificate pre-validation failed: ' + str(e)) from e location = r.headers.get('location') if location and not location.startswith('https://'): raise VCSException(_('Invalid redirect to non-HTTPS: {before} -> {after} ') @@ -2605,8 +2605,8 @@ use_androguard.show_path = True # type: ignore def _get_androguard_APK(apkfile): try: from androguard.core.bytecodes.apk import APK - except ImportError: - raise FDroidException("androguard library is not installed") + except ImportError as exc: + raise FDroidException("androguard library is not installed") from exc return APK(apkfile) @@ -2835,7 +2835,7 @@ def FDroidPopenBytes(commands, cwd=None, envs=None, output=True, stderr_to_stdou stderr=stderr_param) except OSError as e: raise BuildException("OSError while trying to execute " - + ' '.join(commands) + ': ' + str(e)) + + ' '.join(commands) + ': ' + str(e)) from e # TODO are these AsynchronousFileReader threads always exiting? if not stderr_to_stdout and options.verbose: @@ -3535,7 +3535,7 @@ def verify_jar_signature(jar): if e.returncode == 4: logging.debug(_('JAR signature verified: {path}').format(path=jar)) else: - raise VerificationException(error + '\n' + e.output.decode('utf-8')) + raise VerificationException(error + '\n' + e.output.decode('utf-8')) from e def verify_apk_signature(apk, min_sdk_version=None): @@ -4200,10 +4200,10 @@ def calculate_math_string(expr): if '#' in expr: raise SyntaxError('no comments allowed') return execute_ast(ast.parse(expr, mode='eval').body) - except SyntaxError: + except SyntaxError as exc: raise SyntaxError("could not parse expression '{expr}', " "only basic math operations are allowed (+, -, *)" - .format(expr=expr)) + .format(expr=expr)) from exc def force_exit(exitvalue=0): diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 5ab7ad14..ad804041 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -1317,7 +1317,7 @@ def scan_apk_androguard(apk, apkfile): except (FileNotFoundError, zipfile.BadZipFile) as e: logging.error(_("Could not open APK {path} for analysis: ").format(path=apkfile) + str(e)) - raise BuildException(_("Invalid APK")) + raise BuildException(_("Invalid APK")) from e apk['packageName'] = apkobject.get_package() diff --git a/fdroidserver/verify.py b/fdroidserver/verify.py index f2348cc0..f117feaa 100644 --- a/fdroidserver/verify.py +++ b/fdroidserver/verify.py @@ -221,7 +221,7 @@ def main(): net.download_file(url.replace('/repo', '/archive'), dldir=tmp_dir) except requests.exceptions.HTTPError as e: raise FDroidException(_('Downloading {url} failed. {error}') - .format(url=url, error=e)) + .format(url=url, error=e)) from e unsigned_apk = os.path.join(unsigned_dir, apkfilename) compare_result = common.verify_apks(remote_apk, unsigned_apk, tmp_dir) diff --git a/fdroidserver/vmtools.py b/fdroidserver/vmtools.py index 2483a251..f4e3a416 100644 --- a/fdroidserver/vmtools.py +++ b/fdroidserver/vmtools.py @@ -401,7 +401,7 @@ class LibvirtBuildVm(FDroidBuildVm): try: self.conn = libvirt.open('qemu:///system') except libvirt.libvirtError as e: - raise FDroidBuildVmException('could not connect to libvirtd: %s' % (e)) + raise FDroidBuildVmException('could not connect to libvirtd: %s' % (e)) from e def destroy(self):