Target F841 - Remove unused variables

This commit is contained in:
Stephan Kulow 2022-02-18 17:01:38 +01:00
parent 0561e06cb1
commit 579145b52c
29 changed files with 44 additions and 115 deletions

View File

@ -1,4 +1,4 @@
[flake8]
exclude = abichecker
max-line-length = 100
ignore = W503,W504,E501,F401,E128,E251,E201,E202,E302,E305,F841
ignore = W503,W504,E501,F401,E128,E251,E201,E202,E302,E305

View File

@ -619,7 +619,6 @@ class ReviewBot(object):
def can_accept_review(self, request_id):
"""return True if there is a new review for the specified reviewer"""
states = set()
url = osc.core.makeurl(self.apiurl, ('request', str(request_id)))
try:
root = ET.parse(osc.core.http_GET(url)).getroot()
@ -793,7 +792,7 @@ class ReviewBot(object):
u = osc.core.makeurl(self.apiurl, [ 'source', project, package, '_history' ], { 'limit': history_limit })
try:
r = osc.core.http_GET(u)
except HTTPError as e:
except HTTPError:
self.logger.debug("package has no history!?")
return None
@ -895,7 +894,7 @@ class CommandLineInterface(cmdln.Cmdln):
if self.options.fallback_group:
self.checker.fallback_group = self.options.fallback_group
sentry_sdk = sentry_init(conf.config['apiurl'], {
sentry_init(conf.config['apiurl'], {
'review_bot': self.clazz.__name__,
'review_user': self.checker.review_user,
})

View File

@ -139,32 +139,10 @@ class BiArchTool(ToolBase.ToolBase):
if packages == '__all__':
self.packages = self.meta_get_packagelist(self.project)
elif packages == '__latest__':
# only works when called in packagelists loop
# self.packages = self._filter_packages_by_time(self.latest_packages(self.project))
self.packages = self.latest_packages(self.project)
else:
self.packages = packages
# check when 000product was last changed, eg by packagelist
# generator. Yield only packges that got checked in after that
# point in time.
def _filter_packages_by_time(self, packages):
x = ET.fromstring(self.cached_GET(self.makeurl(['source', self.project, '000product', '_history'], {'limit': '1'})))
producttime = int(x.find('./revision/time').text)
for pkg in packages:
try:
x = ET.fromstring(self.cached_GET(self.makeurl(['source', self.project, pkg, '_history'], {'rev': '1'})))
# catch deleted packages
except HTTPError as e:
if e.code == 404:
continue
raise e
packagetime = int(x.find('./revision/time').text)
# if producttime > packagetime:
# continue
yield pkg
def remove_explicit_enable(self):
self._init_biarch_packages()
@ -206,9 +184,6 @@ class BiArchTool(ToolBase.ToolBase):
self._init_biarch_packages()
resulturl = self.makeurl(['source', self.project])
result = ET.fromstring(self.cached_GET(resulturl))
for pkg in self.packages:
changed = False
@ -254,7 +229,6 @@ class BiArchTool(ToolBase.ToolBase):
is_enabled = None
is_disabled = None
has_baselibs = None
must_disable = None
changed = None

View File

@ -2,27 +2,16 @@
import argparse
import logging
import pika
import sys
import json
import osc
import re
import yaml
from time import sleep
from osc.core import http_GET, http_POST, makeurl, show_project_meta
from osc.core import http_GET, makeurl, show_project_meta
from M2Crypto.SSL import SSLError as SSLError
from osclib.conf import Config
from osclib.core import attribute_value_load
from osclib.stagingapi import StagingAPI
from lxml import etree as ET
from openqa_client.client import OpenQA_Client
from openqa_client.exceptions import ConnectionError, RequestError
from urllib.error import HTTPError, URLError
from urllib.parse import quote_plus
from urllib.error import HTTPError
from datetime import datetime, timezone
import requests
from osclib.PubSubConsumer import PubSubConsumer
from flask import Flask, render_template
class Fetcher(object):
@ -31,10 +20,8 @@ class Fetcher(object):
self.opts = opts
self.apiurl = apiurl
if apiurl.endswith('suse.de'):
amqp_prefix = 'suse'
openqa_url = 'https://openqa.suse.de'
else:
amqp_prefix = 'opensuse'
openqa_url = 'https://openqa.opensuse.org'
self.openqa = OpenQA_Client(openqa_url)
@ -46,7 +33,6 @@ class Fetcher(object):
for job in result['jobs']:
if job['clone_id'] or job['result'] == 'obsoleted':
continue
name = job['name'].replace(snapshot, '')
key = job['result']
if job['state'] != 'done':
key = job['state']
@ -63,7 +49,7 @@ class Fetcher(object):
url = makeurl(self.apiurl, ['build', project, '_result'], { 'repository': repository, 'view': 'summary' })
try:
f = http_GET(url)
except HTTPError as e:
except HTTPError:
return { 'building': -1 }
root = ET.parse(f).getroot()
failed = 0

View File

@ -143,7 +143,7 @@ in charge of the following packages:
try:
mail_send(apiurl, args.project, email, subject, message, dry=args.dry)
print(log)
except smtplib.SMTPRecipientsRefused as e:
except smtplib.SMTPRecipientsRefused:
print('[FAILED ADDRESS] {} ({})'.format(log, email))
except smtplib.SMTPException as e:
print('[FAILED SMTP] {} ({})'.format(log, e))

View File

@ -21,7 +21,7 @@ class EmlServer(SMTPServer):
def run():
foo = EmlServer(('0.0.0.0', 25), None)
EmlServer(('0.0.0.0', 25), None)
try:
asyncore.loop()
except KeyboardInterrupt:

View File

@ -111,11 +111,6 @@ class ChangeLogger(cmdln.Cmdln):
for stat in file_stats:
filename = stat[0]
LSN = stat[1]
size = stat[2]
sec_size = stat[3]
is_dir = stat[4] == 2
# print("%s [LSN %6d] %8d %s%s" % (dir_tr[is_dir], LSN, size, path,
# iso9660.name_translate(filename)))
if (filename.endswith('.rpm')):
os.lseek(fd, LSN * pycdio.ISO_BLOCKSIZE, io.SEEK_SET)

View File

@ -81,7 +81,7 @@ class LegalAuto(ReviewBot.ReviewBot):
package = package['saved']
url = osc.core.makeurl(self.legaldb, ['requests'], {'external_link': self.request_nick(),
'package': package['id']})
request = REQ.post(url, headers=self.legaldb_headers).json()
REQ.post(url, headers=self.legaldb_headers)
return [package['id']]
def valid_for_opensuse(self, target_project, report):
@ -128,7 +128,7 @@ class LegalAuto(ReviewBot.ReviewBot):
if state == 'obsolete':
url = osc.core.makeurl(self.legaldb, ['packages', 'import', str(pack)], {
'result': 'reopened in obs', 'state': 'new'})
package = REQ.post(url, headers=self.legaldb_headers).json()
REQ.post(url, headers=self.legaldb_headers)
# reopen
return None
if state == 'new' and self.valid_for_opensuse(target_project, report):
@ -227,7 +227,7 @@ class LegalAuto(ReviewBot.ReviewBot):
with open(yaml_path, 'w') as file:
yaml.dump(self.pkg_cache, file)
url = osc.core.makeurl(self.legaldb, ['products', project])
request = REQ.patch(url, headers=self.legaldb_headers, data={'id': self.packages}).json()
REQ.patch(url, headers=self.legaldb_headers, data={'id': self.packages})
def _query_sources_for_product_import(self, project):
url = osc.core.makeurl(

View File

@ -360,7 +360,7 @@ def revision_index(api):
try:
root = ET.fromstringlist(
get_commitlog(api.apiurl, project, package, None, format='xml'))
except HTTPError as e:
except HTTPError:
return revision_index.index
for logentry in root.findall('logentry'):

View File

@ -54,10 +54,10 @@ class RequestHandler(BaseHTTPRequestHandler):
def do_OPTIONS(self):
try:
with OSCRequestEnvironment(self, require_session=False) as oscrc_file:
with OSCRequestEnvironment(self, require_session=False):
self.send_header('Access-Control-Allow-Methods', 'GET, POST')
self.send_header('Access-Control-Allow-Headers', 'Access-Control-Allow-Origin, Content-Type, X-Requested-With')
except OSCRequestEnvironmentException as e:
except OSCRequestEnvironmentException:
self.send_header('Allow', 'OPTIONS, GET, POST')
self.end_headers()
@ -365,7 +365,7 @@ class OSCRequestEnvironmentException(Exception):
def main(args):
conf.get_config() # Allow sentry DSN to be available.
sentry_sdk = sentry_init()
sentry_init()
RequestHandler.apiurl = args.apiurl
RequestHandler.session = args.session

View File

@ -526,7 +526,7 @@ def do_staging(self, subcmd, opts, *args):
editor = os.getenv('EDITOR')
if not editor:
editor = 'xdg-open'
return_code = subprocess.call(editor.split(' ') + [temp.name])
subprocess.call(editor.split(' ') + [temp.name])
proposal = yaml.safe_load(open(temp.name).read())

View File

@ -355,7 +355,7 @@ def origin_annotation_load(request, action, user):
try:
annotation = yaml.safe_load(review.comment)
except yaml.scanner.ScannerError as e:
except yaml.scanner.ScannerError:
# OBS used to prefix subsequent review lines with two spaces. At some
# point it was changed to no longer indent, but still need to be able
# to load older annotations.

View File

@ -47,7 +47,7 @@ class RepairCommand(object):
else:
# this situation should only happen on adi staging
print('Project is not exist, re-creating "{}"'.format(staging_project))
name = self.api.create_adi_project(staging_project)
self.api.create_adi_project(staging_project)
# a bad request setup found
print('Repairing "{}"'.format(reqid))

View File

@ -365,7 +365,7 @@ class RequestSplitter(object):
group = splitter_info['group']
if group in self.grouped:
key = self.requests_assign(group, staging, merge=True)
self.requests_assign(group, staging, merge=True)
def merge(self, strategy_none=False):
stagings = self.stagings_mergeable_none if strategy_none else self.stagings_mergeable

View File

@ -366,12 +366,6 @@ class StagingAPI(object):
return sorted(projects, key=lambda project: self.extract_adi_number(project))
def find_devel_project_from_adi_frozenlinks(self, prj):
try:
url = self.makeurl(['source', prj, '_project', '_frozenlinks'], {'meta': '1'})
root = ET.parse(http_GET(url)).getroot()
except HTTPError as e:
if e.code == 404:
return None
meta = self.get_prj_pseudometa(prj)
# the first package's devel project is good enough
return devel_project_get(self.apiurl, self.project, meta['requests'][0].get('package'))[0]
@ -572,13 +566,13 @@ class StagingAPI(object):
def add_ignored_request(self, request_id, comment):
url = self.makeurl(['staging', self.project, 'excluded_requests'])
root = ET.Element('excluded_requests')
req = ET.SubElement(root, 'request', { 'id': str(request_id), 'description': comment })
ET.SubElement(root, 'request', { 'id': str(request_id), 'description': comment })
http_POST(url, data=ET.tostring(root))
def del_ignored_request(self, request_id):
url = self.makeurl(['staging', self.project, 'excluded_requests'])
root = ET.Element('excluded_requests')
req = ET.SubElement(root, 'request', { 'id': str(request_id) })
ET.SubElement(root, 'request', { 'id': str(request_id) })
http_DELETE(url, data=ET.tostring(root))
@memoize(session=True, add_invalidate=True)
@ -681,7 +675,6 @@ class StagingAPI(object):
print('no package or no request_id')
return False
orig_project = project
if self._supersede:
self.is_package_disabled(project, package, store=True)
@ -902,7 +895,6 @@ class StagingAPI(object):
:param project: project to link into
"""
# read info from sr
tar_pkg = None
act_type = None
req = get_request(self.apiurl, str(request_id))
@ -927,7 +919,7 @@ class StagingAPI(object):
if remove_exclusion:
opts['remove_exclusion'] = 1
u = makeurl(self.apiurl, ['staging', self.project, 'staging_projects', project, 'staged_requests'], opts)
f = http_POST(u, data=requestxml)
http_POST(u, data=requestxml)
if act_type == 'delete':
self.delete_to_prj(act[0], project)

View File

@ -19,7 +19,6 @@ class UnignoreCommand(object):
"""
requests_ignored = self.api.get_ignored_requests()
length = len(requests_ignored)
if len(requests) == 1 and requests[0] == 'all':
requests_ignored = {}

View File

@ -324,10 +324,8 @@ class Group(object):
root.append(c)
if arch != '*':
cond = ET.SubElement(root, 'conditional', {
'name': 'only_{}'.format(arch)})
packagelist = ET.SubElement(
root, 'packagelist', {'relationship': 'recommends'})
ET.SubElement(root, 'conditional', {'name': 'only_{}'.format(arch)})
packagelist = ET.SubElement(root, 'packagelist', {'relationship': 'recommends'})
missing = dict()
if arch == '*':

View File

@ -403,7 +403,6 @@ class PkgListGen(ToolBase.ToolBase):
root = yaml.safe_load(open(os.path.join(directory, 'config.yml')))
for item in root:
key = list(item)[0]
opts = item[key]
# cast 15.1 to string :)
key = str(key)
@ -419,7 +418,7 @@ class PkgListGen(ToolBase.ToolBase):
defvendorid = oldsysrepo.meta.lookup_id(solv.SUSETAGS_DEFAULTVENDOR)
f = tempfile.TemporaryFile()
# FIXME: port to lzma module with python3
st = subprocess.call(['xz', '-cd', oldrepo], stdout=f.fileno())
subprocess.call(['xz', '-cd', oldrepo], stdout=f.fileno())
os.lseek(f.fileno(), 0, os.SEEK_SET)
oldsysrepo.add_susetags(solv.xfopen_fd(None, f.fileno()), defvendorid, None, solv.Repo.REPO_NO_INTERNALIZE | solv.Repo.SUSETAGS_RECORD_SHARES)

View File

@ -185,7 +185,7 @@ def merge_susetags(output, files):
oldsysrepo = pool.add_repo(file)
defvendorid = oldsysrepo.meta.lookup_id(solv.SUSETAGS_DEFAULTVENDOR)
f = tempfile.TemporaryFile()
st = subprocess.call(['xz', '-cd', file], stdout=f.fileno())
subprocess.call(['xz', '-cd', file], stdout=f.fileno())
os.lseek(f.fileno(), 0, os.SEEK_SET)
oldsysrepo.add_susetags(solv.xfopen_fd(None, f.fileno()), defvendorid, None, solv.Repo.REPO_NO_INTERNALIZE | solv.Repo.SUSETAGS_RECORD_SHARES)
@ -274,7 +274,7 @@ def update_project(apiurl, project):
defvendorid = repo.meta.lookup_id(solv.SUSETAGS_DEFAULTVENDOR)
f = tempfile.TemporaryFile()
# FIXME: port to lzma module with python3
st = subprocess.call(['xz', '-cd', file], stdout=f.fileno())
subprocess.call(['xz', '-cd', file], stdout=f.fileno())
os.lseek(f.fileno(), 0, os.SEEK_SET)
repo.add_susetags(solv.xfopen_fd(None, f.fileno()), defvendorid, None, solv.Repo.REPO_NO_INTERNALIZE | solv.Repo.SUSETAGS_RECORD_SHARES)

View File

@ -44,8 +44,6 @@ class RepoChecker():
self.logger.error('a repository must be specified via OSRT:Config main-repo for {}'.format(project))
return
config = Config.get(self.apiurl, project)
archs = target_archs(self.apiurl, project, repository)
if not len(archs):
self.logger.debug('{} has no relevant architectures'.format(project))

View File

@ -29,7 +29,6 @@ class TestReviewBotComment(OBSLocal.TestCase):
del self.wf
def test_basic_logger(self):
comment_count = len(self.api.get_comments(project_name=PROJECT))
self.assertFalse(self.comments_filtered(self.bot)[0])
# Initial comment.

View File

@ -64,7 +64,7 @@ class TestAccept(unittest.TestCase):
package.create_commit('<multibuild><flavor>gcc9-tests.spec</flavor></multibuild>', filename='_multibuild')
wf.submit_package(package)
ret = SelectCommand(wf.api, staging.name).perform(['gcc9'])
SelectCommand(wf.api, staging.name).perform(['gcc9'])
ac = AcceptCommand(wf.api)
self.assertEqual(True, ac.accept_all(['A'], True))
@ -83,7 +83,7 @@ class TestAccept(unittest.TestCase):
package.create_commit(filename='gcc9-tests.spec')
wf.submit_package(package)
ret = SelectCommand(wf.api, staging.name).perform(['gcc9'])
SelectCommand(wf.api, staging.name).perform(['gcc9'])
ac = AcceptCommand(wf.api)
self.assertEqual(True, ac.accept_all(['A'], True))
@ -110,7 +110,7 @@ class TestAccept(unittest.TestCase):
wf.submit_package(package)
ret = SelectCommand(wf.api, staging.name).perform(['gcc9'])
SelectCommand(wf.api, staging.name).perform(['gcc9'])
ac = AcceptCommand(wf.api)
self.assertEqual(True, ac.accept_all(['A'], True))

View File

@ -43,9 +43,9 @@ class TestApiCalls(OBSLocal.TestCase):
curl = self.wf.create_package('target', 'curl')
curl.create_file('curl.spec')
curl.create_file('curl-mini.spec')
cmini = self.wf.create_link(curl, target_project=self.wf.projects['target'], target_package='curl-mini')
self.wf.create_link(curl, target_project=self.wf.projects['target'], target_package='curl-mini')
cring1 = self.wf.create_link(curl, target_project=self.wf.projects['ring1'], target_package='curl')
cring0 = self.wf.create_link(cring1, target_project=self.wf.projects['ring0'], target_package='curl-mini')
self.wf.create_link(cring1, target_project=self.wf.projects['ring0'], target_package='curl-mini')
# test content for listonly ie. list command
ring_packages = {
@ -127,8 +127,6 @@ class TestApiCalls(OBSLocal.TestCase):
def test_add_sr(self):
# setup is already adding the request, we just verify
prj = self.staging_b.name
pkg = 'wine'
num = self.winerq.reqid
# Verify that review is there
@ -217,7 +215,7 @@ class TestApiCalls(OBSLocal.TestCase):
def test_move(self):
"""Test package movement."""
staging_a = self.wf.create_staging('A')
self.wf.create_staging('A')
self.assertTrue(self.wf.api.item_exists('openSUSE:Factory:Staging:B', 'wine'))
self.assertFalse(self.wf.api.item_exists('openSUSE:Factory:Staging:A', 'wine'))

View File

@ -191,8 +191,7 @@ class TestCheckSource(OBSLocal.TestCase):
self.wf.create_group(group_name)
self.wf.remote_config_set({ 'required-source-maintainer': FACTORY_MAINTAINERS })
root_project = self.wf.create_project(SRC_PROJECT.rsplit(':', 1)[0],
maintainer={'groups': [group_name]})
self.wf.create_project(SRC_PROJECT.rsplit(':', 1)[0], maintainer={'groups': [group_name]})
self._setup_devel_project()

View File

@ -65,7 +65,7 @@ class TestConfig(unittest.TestCase):
# Ensure each pattern is match instead of catch-all pattern.
patterns = set()
for project in projects:
config = Config(wf.apiurl, project)
Config(wf.apiurl, project)
patterns.add(conf.config[project]['pattern'])
self.assertEqual(len(patterns), len(DEFAULT))

View File

@ -18,7 +18,6 @@ class MockedContainerCleaner(ContainerCleaner):
return list(set(all_archs))
elif path[0:3] == ["build", "mock:prj", "containers"] and len(path) == 4:
arch = path[3]
ret = []
for srccontainer in self.container_arch_map:
ret += [srccontainer]

View File

@ -292,7 +292,7 @@ class TestOrigin(OBSLocal.TestCase):
devel_project = self.randomString('devel')
package = self.randomString('package')
target_package = self.wf.create_package(self.target_project, package)
self.wf.create_package(self.target_project, package)
upstream1_package = self.wf.create_package(upstream1_project, package)
upstream2_package = self.wf.create_package(upstream2_project, package)
devel_package = self.wf.create_package(devel_project, package)
@ -365,9 +365,9 @@ class TestOrigin(OBSLocal.TestCase):
package2 = self.randomString('package2')
package3 = self.randomString('package3')
target_package1 = self.wf.create_package(self.target_project, package1)
self.wf.create_package(self.target_project, package1)
upstream1_package1 = self.wf.create_package(upstream1_project, package1)
upstream2_package1 = self.wf.create_package(upstream2_project, package1)
self.wf.create_package(upstream2_project, package1)
upstream1_package1.create_commit()
copy_package(self.wf.apiurl, upstream1_project, package1,
@ -394,7 +394,7 @@ class TestOrigin(OBSLocal.TestCase):
request_future = origin_update(self.wf.apiurl, self.wf.project, package1)
self.assertNotEqual(request_future, False)
if request_future:
request_id_package1 = request_future.print_and_create()
request_future.print_and_create()
# Ensure a second request is not triggered.
memoize_session_reset()
@ -443,7 +443,7 @@ class TestOrigin(OBSLocal.TestCase):
upstream1_project = self.randomString('upstream1')
package1 = self.randomString('package1')
target_package1 = self.wf.create_package(self.target_project, package1)
self.wf.create_package(self.target_project, package1)
upstream1_package1 = self.wf.create_package(upstream1_project, package1)
upstream1_package1.create_commit()
@ -492,8 +492,7 @@ class TestOrigin(OBSLocal.TestCase):
# Accept request and ensure update since no request to supersede.
self.assertReviewScript(request_id_package1_1, self.bot_user, 'new', 'accepted')
request_state_change(self.wf.apiurl, request_id_package1_1, 'accepted')
request_id_package1_2 = self.assertUpdate(package1)
self.assertUpdate(package1)
# Track time since last request created for testing frequency.
start = datetime.now()
@ -508,4 +507,4 @@ class TestOrigin(OBSLocal.TestCase):
self.waitDelta(start, delay)
upstream1_package1.create_commit()
request_id_package1_3 = self.assertUpdate(package1)
self.assertUpdate(package1)

View File

@ -100,7 +100,7 @@ class TestSelect(OBSLocal.TestCase):
staging = self.wf.create_staging('A', freeze=True)
rq1 = self.wf.create_submit_request('devel:wine', 'wine')
ret = SelectCommand(self.wf.api, staging.name).perform(['wine'])
SelectCommand(self.wf.api, staging.name).perform(['wine'])
rq2 = self.wf.create_submit_request('devel:wine', 'wine', text='Something new')
self.wf.api._packages_staged = None
@ -120,7 +120,7 @@ class TestSelect(OBSLocal.TestCase):
package = self.wf.create_package(self.wf.project, 'wine')
package.create_commit('<multibuild><flavor>libs</flavor></multibuild>', filename='_multibuild')
rq = self.wf.request_package_delete(package)
self.wf.request_package_delete(package)
ret = SelectCommand(self.wf.api, staging.name).perform(['wine'])
self.assertEqual(True, ret)

View File

@ -171,8 +171,6 @@ class ToTestPublisher(ToTestManager):
current_snapshot = self.get_status('testing')
group_id = self.openqa_group_id()
if self.get_status('publishing') == current_snapshot:
self.logger.info('{} is already publishing'.format(current_snapshot))
# migrating - if there is no published entry, the last publish call
@ -255,9 +253,6 @@ class ToTestPublisher(ToTestManager):
if self.dryrun:
return
url = makeurl(self.project.openqa_server,
['api', 'v1', 'groups', str(group_id), 'comments'])
status_flag = 'published'
data = {'text': 'tag:{}:{}:{}'.format(snapshot, status_flag, status_flag) }
self.openqa.openqa_request('POST', 'groups/%s/comments' % group_id, data=data)