1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-10-02 09:10:11 +02:00

Merge branch 'fix_pylint' into 'master'

explicitly re-raising exceptions

See merge request fdroid/fdroidserver!1139
This commit is contained in:
Hans-Christoph Steiner 2022-06-03 10:53:33 +00:00
commit 94faece5ba
7 changed files with 22 additions and 22 deletions

View File

@ -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):

View File

@ -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:

View File

@ -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

View File

@ -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<value>[0-9][0-9.]*) *(?P<unit>' + 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):

View File

@ -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()

View File

@ -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)

View File

@ -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):