1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-19 21:30:10 +01: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 return value
try: try:
return {False: NO, None: AUTO, True: YES}[value] return {False: NO, None: AUTO, True: YES}[value]
except KeyError: except KeyError as exc:
raise ValueError("expected False, None, or True") raise ValueError("expected False, None, or True") from exc
def is_meta(filename): 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()], sshinfo['user'] + "@" + sshinfo['hostname'] + ":" + ftp.getcwd()],
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: 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...") logging.info("Preparing server for build...")
serverpath = os.path.abspath(os.path.dirname(__file__)) 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)) ftp.get(apkfile, os.path.join(output_dir, apkfile))
if not options.notarball: if not options.notarball:
ftp.get(tarball, os.path.join(output_dir, tarball)) ftp.get(tarball, os.path.join(output_dir, tarball))
except Exception: except Exception as exc:
raise BuildException( raise BuildException(
"Build failed for {0}:{1} - missing output files".format( "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() ftp.close()
finally: finally:

View File

@ -495,8 +495,8 @@ def checkupdates_app(app):
if pattern.startswith('+'): if pattern.startswith('+'):
try: try:
suffix, pattern = pattern[1:].split(' ', 1) suffix, pattern = pattern[1:].split(' ', 1)
except ValueError: except ValueError as exc:
raise MetaDataException("Invalid AutoUpdateMode: " + mode) raise MetaDataException("Invalid AutoUpdateMode: " + mode) from exc
gotcur = False gotcur = False
latest = None latest = None

View File

@ -480,14 +480,14 @@ def parse_human_readable_size(size):
} }
try: try:
return int(float(size)) return int(float(size))
except (ValueError, TypeError): except (ValueError, TypeError) as exc:
if type(size) != str: if type(size) != str:
raise ValueError(_('Could not parse size "{size}", wrong type "{type}"') 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(' ', '') s = size.lower().replace(' ', '')
m = re.match(r'^(?P<value>[0-9][0-9.]*) *(?P<unit>' + r'|'.join(units.keys()) + r')$', s) m = re.match(r'^(?P<value>[0-9][0-9.]*) *(?P<unit>' + r'|'.join(units.keys()) + r')$', s)
if not m: 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")]) return int(float(m.group("value")) * units[m.group("unit")])
@ -793,8 +793,8 @@ def publishednameinfo(filename):
m = publish_name_regex.match(filename) m = publish_name_regex.match(filename)
try: try:
result = (m.group(1), m.group(2)) result = (m.group(1), m.group(2))
except AttributeError: except AttributeError as exc:
raise FDroidException(_("Invalid name for published file: %s") % filename) raise FDroidException(_("Invalid name for published file: %s") % filename) from exc
return result return result
@ -1350,7 +1350,7 @@ class vcs_gitsvn(vcs):
r = requests.head(remote) r = requests.head(remote)
r.raise_for_status() r.raise_for_status()
except Exception as e: 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') location = r.headers.get('location')
if location and not location.startswith('https://'): if location and not location.startswith('https://'):
raise VCSException(_('Invalid redirect to non-HTTPS: {before} -> {after} ') 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): def _get_androguard_APK(apkfile):
try: try:
from androguard.core.bytecodes.apk import APK from androguard.core.bytecodes.apk import APK
except ImportError: except ImportError as exc:
raise FDroidException("androguard library is not installed") raise FDroidException("androguard library is not installed") from exc
return APK(apkfile) return APK(apkfile)
@ -2835,7 +2835,7 @@ def FDroidPopenBytes(commands, cwd=None, envs=None, output=True, stderr_to_stdou
stderr=stderr_param) stderr=stderr_param)
except OSError as e: except OSError as e:
raise BuildException("OSError while trying to execute " raise BuildException("OSError while trying to execute "
+ ' '.join(commands) + ': ' + str(e)) + ' '.join(commands) + ': ' + str(e)) from e
# TODO are these AsynchronousFileReader threads always exiting? # TODO are these AsynchronousFileReader threads always exiting?
if not stderr_to_stdout and options.verbose: if not stderr_to_stdout and options.verbose:
@ -3535,7 +3535,7 @@ def verify_jar_signature(jar):
if e.returncode == 4: if e.returncode == 4:
logging.debug(_('JAR signature verified: {path}').format(path=jar)) logging.debug(_('JAR signature verified: {path}').format(path=jar))
else: 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): def verify_apk_signature(apk, min_sdk_version=None):
@ -4200,10 +4200,10 @@ def calculate_math_string(expr):
if '#' in expr: if '#' in expr:
raise SyntaxError('no comments allowed') raise SyntaxError('no comments allowed')
return execute_ast(ast.parse(expr, mode='eval').body) return execute_ast(ast.parse(expr, mode='eval').body)
except SyntaxError: except SyntaxError as exc:
raise SyntaxError("could not parse expression '{expr}', " raise SyntaxError("could not parse expression '{expr}', "
"only basic math operations are allowed (+, -, *)" "only basic math operations are allowed (+, -, *)"
.format(expr=expr)) .format(expr=expr)) from exc
def force_exit(exitvalue=0): def force_exit(exitvalue=0):

View File

@ -1317,7 +1317,7 @@ def scan_apk_androguard(apk, apkfile):
except (FileNotFoundError, zipfile.BadZipFile) as e: except (FileNotFoundError, zipfile.BadZipFile) as e:
logging.error(_("Could not open APK {path} for analysis: ").format(path=apkfile) logging.error(_("Could not open APK {path} for analysis: ").format(path=apkfile)
+ str(e)) + str(e))
raise BuildException(_("Invalid APK")) raise BuildException(_("Invalid APK")) from e
apk['packageName'] = apkobject.get_package() apk['packageName'] = apkobject.get_package()

View File

@ -221,7 +221,7 @@ def main():
net.download_file(url.replace('/repo', '/archive'), dldir=tmp_dir) net.download_file(url.replace('/repo', '/archive'), dldir=tmp_dir)
except requests.exceptions.HTTPError as e: except requests.exceptions.HTTPError as e:
raise FDroidException(_('Downloading {url} failed. {error}') 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) unsigned_apk = os.path.join(unsigned_dir, apkfilename)
compare_result = common.verify_apks(remote_apk, unsigned_apk, tmp_dir) compare_result = common.verify_apks(remote_apk, unsigned_apk, tmp_dir)

View File

@ -401,7 +401,7 @@ class LibvirtBuildVm(FDroidBuildVm):
try: try:
self.conn = libvirt.open('qemu:///system') self.conn = libvirt.open('qemu:///system')
except libvirt.libvirtError as e: 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): def destroy(self):