From 1152d4c419ab94674a983198fbf402f019db1cb8 Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Fri, 18 Feb 2022 11:25:26 +0100 Subject: [PATCH] Remove bare excepts - https://www.flake8rules.com/rules/E722.html The bare except in osc-credentials lead me to remove it and the scripts using it --- .flake8 | 2 +- CONTENTS.md | 8 ---- build-fail-reminder.py | 2 +- check_source.py | 2 +- dist/ci/osc-credentials | 13 ------ dist/ci/osc-init | 19 -------- dist/package/openSUSE-release-tools.spec | 1 - k8s-secret.py | 56 ------------------------ osc-cycle.py | 3 +- osclib/memoize.py | 5 +-- osclib/stagingapi.py | 2 +- tests/OBSLocal.py | 2 +- 12 files changed, 8 insertions(+), 107 deletions(-) delete mode 100755 dist/ci/osc-credentials delete mode 100755 dist/ci/osc-init delete mode 100755 k8s-secret.py diff --git a/.flake8 b/.flake8 index b8fca05d..25e0ae17 100644 --- a/.flake8 +++ b/.flake8 @@ -1,4 +1,4 @@ [flake8] exclude = abichecker max-line-length = 100 -ignore = E501,F401,E128,E251,E201,E202,E302,E305,F841,E261,E712,E126,E711,E125,E123,E101,E124,E127,E701,E714,W504,E129,E741,E722 +ignore = E501,F401,E128,E251,E201,E202,E302,E305,F841,E261,E712,E126,E711,E125,E123,E101,E124,E127,E701,E714,W504,E129,E741 diff --git a/CONTENTS.md b/CONTENTS.md index b5bc180b..5760bb66 100644 --- a/CONTENTS.md +++ b/CONTENTS.md @@ -342,11 +342,3 @@ directly. * Package: openSUSE-release-tools * Usage: obsolete -#### k8s-secret.py - -Applies kubernetes secrets for OSRT tool osc configuration. - -* Sources: [k8s-secret.py](k8s-secret.py) -* Documentation: -- -* Package: openSUSE-release-tools -* Usage: obsolete diff --git a/build-fail-reminder.py b/build-fail-reminder.py index 9d3e0dd8..fb11f8d9 100755 --- a/build-fail-reminder.py +++ b/build-fail-reminder.py @@ -116,7 +116,7 @@ def main(args): with open(reminded_json) as json_data: RemindedLoaded = json.load(json_data) json_data.close() - except: + except FileNotFoundError: RemindedLoaded = {} pass diff --git a/check_source.py b/check_source.py index a98d7df7..d7c426e3 100755 --- a/check_source.py +++ b/check_source.py @@ -432,7 +432,7 @@ class CheckSource(ReviewBot.ReviewBot): if not f.get('name').endswith('.changes'): return False return True - except: + except HTTPError: pass return False diff --git a/dist/ci/osc-credentials b/dist/ci/osc-credentials deleted file mode 100755 index 52afe121..00000000 --- a/dist/ci/osc-credentials +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/python3 - -try: - from osc import conf -except: - import sys - sys.exit() - -apiurl = conf.config['apiurl'] -cp = conf.get_configParser() - -for key in ('apiurl', 'user', 'pass', 'email'): - print('{}="{}"'.format(key, cp.get(apiurl, key, raw=True))) diff --git a/dist/ci/osc-init b/dist/ci/osc-init deleted file mode 100755 index 790fc952..00000000 --- a/dist/ci/osc-init +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -: ${OSCRC:=~/.oscrc} -OBS_API="${OBS_API:-https://api.opensuse.org}" -if [ -z ${OBS_PASS+x} ] || [ -z "$OBS_PASS" ] ; then - OBS_API="$OBS_API/public" -fi - -echo "OBS_API=$OBS_API" -echo "OBS_USER=$OBS_USER" - -cat << eom > "$OSCRC" -[general] -apiurl = $OBS_API -[$OBS_API] -user = ${OBS_USER:-example} -pass = ${OBS_PASS:-example} -email = ${OBS_EMAIL:-example@example.com} -eom diff --git a/dist/package/openSUSE-release-tools.spec b/dist/package/openSUSE-release-tools.spec index 7760e2ac..7d1ca9db 100644 --- a/dist/package/openSUSE-release-tools.spec +++ b/dist/package/openSUSE-release-tools.spec @@ -376,7 +376,6 @@ exit 0 %{_bindir}/osrt-deptool %{_bindir}/osrt-fcc_submitter %{_bindir}/osrt-issue-diff -%{_bindir}/osrt-k8s-secret %{_bindir}/osrt-legal-auto %{_bindir}/osrt-openqa-maintenance %{_bindir}/osrt-requestfinder diff --git a/k8s-secret.py b/k8s-secret.py deleted file mode 100755 index 3aa45451..00000000 --- a/k8s-secret.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/python3 - -import argparse -import os -from osclib.cache_manager import CacheManager -import subprocess -import sys - -CACHE_DIR = CacheManager.directory('k8s-secret') -SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__)) - - -def secret_create(cache_file): - environment = {'OSCRC': cache_file} - - print('Username: ', end='') - environment['OBS_USER'] = input() - - print('Password: ', end='') - environment['OBS_PASS'] = input() - - osc_init = os.path.join(SCRIPT_PATH, 'dist/ci/osc-init') - subprocess.Popen([osc_init], env=environment).wait() - -def secret_apply(prefix, cache_file): - print(subprocess.check_output([ - 'kubectl', 'create', 'secret', 'generic', - '{}-oscrc'.format(prefix), '--from-file={}={}'.format('.oscrc', cache_file)])) - -def main(args): - cache_file = os.path.join(CACHE_DIR, args.prefix) - if not os.path.exists(cache_file) or args.create: - secret_create(cache_file) - - with open(cache_file, 'r') as f: - print(f.read()) - - print('Apply secret for {} [y/n] (y): '.format(args.prefix), end='') - response = input().lower() - if response != '' and response != 'y': - return - - secret_apply(args.prefix, cache_file) - - if args.delete: - os.remove(cache_file) - -if __name__ == '__main__': - description = 'Apply kubernetes secrets for OSRT tool osc configuration.' - parser = argparse.ArgumentParser(description=description) - parser.add_argument('--create', action='store_true', help='create regardless of existing file') - parser.add_argument('--delete', action='store_true', help='delete cached secret after application') - parser.add_argument('prefix', help='prefix for which to create secret (ex. check-source, repo-checker)') - args = parser.parse_args() - - sys.exit(main(args)) diff --git a/osc-cycle.py b/osc-cycle.py index 4609796a..4182ead2 100644 --- a/osc-cycle.py +++ b/osc-cycle.py @@ -2,6 +2,7 @@ import osc.core from osc.core import get_dependson from xml.etree import cElementTree as ET from osc import cmdln +from urllib.error import HTTPError @cmdln.option('-p', '--project', metavar='PROJECT', dest='project', default='openSUSE:Factory') @cmdln.option('-r', '--repository', metavar='REPOSITORY', dest='repository', default='standard') @@ -30,7 +31,7 @@ def do_cycle(self, subcmd, opts, *args): for deps in pkg.findall('pkgdep'): if deps.text in args: print("\"%s\" -> \"%s\"" % (deps.text, pkgname)) - except: + except HTTPError: # Ignore packages that do not exist print("[color=red]") continue diff --git a/osclib/memoize.py b/osclib/memoize.py index d8b66b18..57480cfe 100644 --- a/osclib/memoize.py +++ b/osclib/memoize.py @@ -4,10 +4,7 @@ from functools import wraps import os from osclib.cache_manager import CacheManager import shelve -try: - import cPickle as pickle -except: - import pickle +import pickle # Where the cache files are stored CACHEDIR = CacheManager.directory('memoize') diff --git a/osclib/stagingapi.py b/osclib/stagingapi.py index ad3acc6d..304c0e38 100644 --- a/osclib/stagingapi.py +++ b/osclib/stagingapi.py @@ -1328,7 +1328,7 @@ class StagingAPI(object): try: print("tried to trigger rebuild for project '%s' package '%s'" % (prj, pkg)) http_POST(u) - except: + except HTTPError: print("could not trigger rebuild for project '%s' package '%s'" % (prj, pkg)) def _candidate_adi_project(self): diff --git a/tests/OBSLocal.py b/tests/OBSLocal.py index ba817352..d07f35a9 100644 --- a/tests/OBSLocal.py +++ b/tests/OBSLocal.py @@ -574,7 +574,7 @@ class StagingWorkflow(ABC): return try: self.remove() - except: + except Exception: # normally exceptions in destructors are ignored but a info # message is displayed. Make this a little more useful by # printing it into the capture log