bitbake: lib: fix most undefined code picked up by pylint

Correctly import, and inherit functions, and variables.
Also fix some typos and remove some Python 2 code that isn't recognised.

(Bitbake rev: b0c807be5c2170c9481c1a04d4c11972135d7dc5)

Signed-off-by: Frazer Clews <frazerleslieclews@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Frazer Clews 2020-08-24 15:51:37 +01:00 committed by Richard Purdie
parent ac3593f6ed
commit abc6f864b9
22 changed files with 51 additions and 42 deletions

View File

@ -93,7 +93,7 @@ class BBLoggerAdapter(logging.LoggerAdapter, BBLoggerMixin):
def __repr__(self): def __repr__(self):
logger = self.logger logger = self.logger
level = getLevelName(logger.getEffectiveLevel()) level = logger.getLevelName(logger.getEffectiveLevel())
return '<%s %s (%s)>' % (self.__class__.__name__, logger.name, level) return '<%s %s (%s)>' % (self.__class__.__name__, logger.name, level)
logging.LoggerAdapter = BBLoggerAdapter logging.LoggerAdapter = BBLoggerAdapter

View File

@ -14,6 +14,8 @@ import sys
import io import io
import traceback import traceback
import bb
def createDaemon(function, logfile): def createDaemon(function, logfile):
""" """
Detach a process from the controlling terminal and run it in the Detach a process from the controlling terminal and run it in the

View File

@ -189,7 +189,7 @@ class IncludeHistory(object):
if self.current.parent: if self.current.parent:
self.current = self.current.parent self.current = self.current.parent
else: else:
bb.warn("Include log: Tried to finish '%s' at top level." % filename) bb.warn("Include log: Tried to finish '%s' at top level." % self.filename)
return False return False
def emit(self, o, level = 0): def emit(self, o, level = 0):

View File

@ -8,12 +8,15 @@ Based on the svn "Fetch" implementation.
""" """
import logging import logging
import os
import bb import bb
from bb.fetch2 import FetchMethod from bb.fetch2 import FetchMethod
from bb.fetch2 import FetchError from bb.fetch2 import FetchError
from bb.fetch2 import MissingParameterError from bb.fetch2 import MissingParameterError
from bb.fetch2 import runfetchcmd from bb.fetch2 import runfetchcmd
logger = logging.getLogger(__name__)
class Osc(FetchMethod): class Osc(FetchMethod):
"""Class to fetch a module or modules from Opensuse build server """Class to fetch a module or modules from Opensuse build server
repositories.""" repositories."""

View File

@ -31,8 +31,7 @@ IETF secsh internet draft:
# #
import re, os import re, os
from bb.fetch2 import FetchMethod from bb.fetch2 import check_network_access, FetchMethod, ParameterError, runfetchcmd
from bb.fetch2 import runfetchcmd
__pattern__ = re.compile(r''' __pattern__ = re.compile(r'''
@ -65,7 +64,7 @@ class SSH(FetchMethod):
def urldata_init(self, urldata, d): def urldata_init(self, urldata, d):
if 'protocol' in urldata.parm and urldata.parm['protocol'] == 'git': if 'protocol' in urldata.parm and urldata.parm['protocol'] == 'git':
raise bb.fetch2.ParameterError( raise ParameterError(
"Invalid protocol - if you wish to fetch from a git " + "Invalid protocol - if you wish to fetch from a git " +
"repository using ssh, you need to use " + "repository using ssh, you need to use " +
"git:// prefix with protocol=ssh", urldata.url) "git:// prefix with protocol=ssh", urldata.url)
@ -105,7 +104,7 @@ class SSH(FetchMethod):
dldir dldir
) )
bb.fetch2.check_network_access(d, cmd, urldata.url) check_network_access(d, cmd, urldata.url)
runfetchcmd(cmd, d) runfetchcmd(cmd, d)

View File

@ -14,6 +14,7 @@ import sys
import copy import copy
import logging import logging
import logging.config import logging.config
import os
from itertools import groupby from itertools import groupby
import bb import bb
import bb.event import bb.event

View File

@ -61,17 +61,9 @@ class _NamedTupleABCMeta(ABCMeta):
return ABCMeta.__new__(mcls, name, bases, namespace) return ABCMeta.__new__(mcls, name, bases, namespace)
exec( class _NamedTupleABC(metaclass=_NamedTupleABCMeta):
# Python 2.x metaclass declaration syntax '''The abstract base class + mix-in for named tuples.'''
"""class _NamedTupleABC(object): _fields = abstractproperty()
'''The abstract base class + mix-in for named tuples.'''
__metaclass__ = _NamedTupleABCMeta
_fields = abstractproperty()""" if version_info[0] < 3 else
# Python 3.x metaclass declaration syntax
"""class _NamedTupleABC(metaclass=_NamedTupleABCMeta):
'''The abstract base class + mix-in for named tuples.'''
_fields = abstractproperty()"""
)
_namedtuple.abc = _NamedTupleABC _namedtuple.abc = _NamedTupleABC

View File

@ -7,6 +7,7 @@ import signal
import subprocess import subprocess
import errno import errno
import select import select
import bb
logger = logging.getLogger('BitBake.Process') logger = logging.getLogger('BitBake.Process')

View File

@ -25,6 +25,7 @@ import subprocess
import errno import errno
import re import re
import datetime import datetime
import pickle
import bb.server.xmlrpcserver import bb.server.xmlrpcserver
from bb import daemonize from bb import daemonize
from multiprocessing import queues from multiprocessing import queues

View File

@ -12,6 +12,7 @@ import bb
import bb.data import bb.data
import bb.parse import bb.parse
import logging import logging
import os
class LogRecord(): class LogRecord():
def __enter__(self): def __enter__(self):

View File

@ -732,7 +732,7 @@ class Tinfoil:
continue continue
if helper.eventHandler(event): if helper.eventHandler(event):
if isinstance(event, bb.build.TaskFailedSilent): if isinstance(event, bb.build.TaskFailedSilent):
logger.warning("Logfile for failed setscene task is %s" % event.logfile) self.logger.warning("Logfile for failed setscene task is %s" % event.logfile)
elif isinstance(event, bb.build.TaskFailed): elif isinstance(event, bb.build.TaskFailed):
bb.ui.knotty.print_event_log(event, includelogs, loglines, termfilter) bb.ui.knotty.print_event_log(event, includelogs, loglines, termfilter)
continue continue

View File

@ -144,7 +144,7 @@ class TerminalFilter(object):
pass pass
if not cr: if not cr:
try: try:
cr = (env['LINES'], env['COLUMNS']) cr = (os.environ['LINES'], os.environ['COLUMNS'])
except: except:
cr = (25, 80) cr = (25, 80)
return cr return cr

View File

@ -48,6 +48,8 @@ import bb
import xmlrpc.client import xmlrpc.client
from bb.ui import uihelper from bb.ui import uihelper
logger = logging.getLogger(__name__)
parsespin = itertools.cycle( r'|/-\\' ) parsespin = itertools.cycle( r'|/-\\' )
X = 0 X = 0

View File

@ -11,9 +11,13 @@ server and queue them for the UI to process. This process must be used to avoid
client/server deadlocks. client/server deadlocks.
""" """
import socket, threading, pickle, collections import collections, logging, pickle, socket, threading
from xmlrpc.server import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler from xmlrpc.server import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
import bb
logger = logging.getLogger(__name__)
class BBUIEventQueue: class BBUIEventQueue:
def __init__(self, BBServer, clientinfo=("localhost, 0")): def __init__(self, BBServer, clientinfo=("localhost, 0")):

View File

@ -9,6 +9,7 @@ from . import create_server, create_client
import hashlib import hashlib
import logging import logging
import multiprocessing import multiprocessing
import os
import sys import sys
import tempfile import tempfile
import threading import threading

View File

@ -7,6 +7,7 @@ import datetime
import logging import logging
import imp import imp
import os
from collections import OrderedDict from collections import OrderedDict
from layerindexlib.plugin import LayerIndexPluginUrlError from layerindexlib.plugin import LayerIndexPluginUrlError
@ -70,7 +71,7 @@ class LayerIndex():
if self.__class__ != newIndex.__class__ or \ if self.__class__ != newIndex.__class__ or \
other.__class__ != newIndex.__class__: other.__class__ != newIndex.__class__:
raise TypeException("Can not add different types.") raise TypeError("Can not add different types.")
for indexEnt in self.indexes: for indexEnt in self.indexes:
newIndex.indexes.append(indexEnt) newIndex.indexes.append(indexEnt)
@ -266,8 +267,8 @@ will write out the individual elements split by layer and related components.
logger.debug(1, "Store not implemented in %s" % plugin.type) logger.debug(1, "Store not implemented in %s" % plugin.type)
pass pass
else: else:
logger.debug(1, "No plugins support %s" % url) logger.debug(1, "No plugins support %s" % indexURI)
raise LayerIndexException("No plugins support %s" % url) raise LayerIndexException("No plugins support %s" % indexURI)
def is_empty(self): def is_empty(self):
@ -657,7 +658,7 @@ class LayerIndexObj():
if obj.id in self._index[indexname]: if obj.id in self._index[indexname]:
if self._index[indexname][obj.id] == obj: if self._index[indexname][obj.id] == obj:
continue continue
raise LayerIndexError('Conflict adding object %s(%s) to index' % (indexname, obj.id)) raise LayerIndexException('Conflict adding object %s(%s) to index' % (indexname, obj.id))
self._index[indexname][obj.id] = obj self._index[indexname][obj.id] = obj
def add_raw_element(self, indexname, objtype, rawobjs): def add_raw_element(self, indexname, objtype, rawobjs):
@ -842,11 +843,11 @@ class LayerIndexObj():
def _resolve_dependencies(layerbranches, ignores, dependencies, invalid): def _resolve_dependencies(layerbranches, ignores, dependencies, invalid):
for layerbranch in layerbranches: for layerbranch in layerbranches:
if ignores and layerBranch.layer.name in ignores: if ignores and layerbranch.layer.name in ignores:
continue continue
for layerdependency in layerbranch.index.layerDependencies_layerBranchId[layerBranch.id]: for layerdependency in layerbranch.index.layerDependencies_layerBranchId[layerbranch.id]:
deplayerbranch = layerDependency.dependency_layerBranch deplayerbranch = layerdependency.dependency_layerBranch
if ignores and deplayerbranch.layer.name in ignores: if ignores and deplayerbranch.layer.name in ignores:
continue continue

View File

@ -4,6 +4,7 @@
# #
import logging import logging
import os
from collections import defaultdict from collections import defaultdict
@ -73,7 +74,7 @@ class CookerPlugin(layerindexlib.plugin.IndexPlugin):
d = self.layerindex.data d = self.layerindex.data
if not branches: if not branches:
raise LayerIndexFetchError("No branches specified for _load_bblayers!") raise layerindexlib.LayerIndexFetchError("No branches specified for _load_bblayers!")
index = layerindexlib.LayerIndexObj() index = layerindexlib.LayerIndexObj()
@ -202,7 +203,7 @@ class CookerPlugin(layerindexlib.plugin.IndexPlugin):
try: try:
depDict = bb.utils.explode_dep_versions2(deps) depDict = bb.utils.explode_dep_versions2(deps)
except bb.utils.VersionStringException as vse: except bb.utils.VersionStringException as vse:
bb.fatal('Error parsing LAYERDEPENDS_%s: %s' % (c, str(vse))) bb.fatal('Error parsing LAYERDEPENDS_%s: %s' % (collection, str(vse)))
for dep, oplist in list(depDict.items()): for dep, oplist in list(depDict.items()):
# We need to search ourselves, so use the _ version... # We need to search ourselves, so use the _ version...
@ -268,7 +269,7 @@ class CookerPlugin(layerindexlib.plugin.IndexPlugin):
layer = bb.utils.get_file_layer(realfn[0], self.config_data) layer = bb.utils.get_file_layer(realfn[0], self.config_data)
depBranchId = collection_layerbranch[layer] depBranchId = collection[layer]
recipeId += 1 recipeId += 1
recipe = layerindexlib.Recipe(index, None) recipe = layerindexlib.Recipe(index, None)

View File

@ -5,9 +5,13 @@
import logging import logging
import json import json
import os
from urllib.parse import unquote from urllib.parse import unquote
from urllib.parse import urlparse from urllib.parse import urlparse
import bb
import layerindexlib import layerindexlib
import layerindexlib.plugin import layerindexlib.plugin
@ -163,7 +167,7 @@ class RestApiPlugin(layerindexlib.plugin.IndexPlugin):
parsed = _get_json_response(apiurl=up_stripped.geturl(), username=username, password=password, retry=False) parsed = _get_json_response(apiurl=up_stripped.geturl(), username=username, password=password, retry=False)
logger.debug(1, "%s: retry successful.") logger.debug(1, "%s: retry successful.")
else: else:
raise LayerIndexFetchError('%s: Connection reset by peer. Is there a firewall blocking your connection?' % apiurl) raise layerindexlib.LayerIndexFetchError('%s: Connection reset by peer. Is there a firewall blocking your connection?' % apiurl)
return parsed return parsed

View File

@ -112,7 +112,7 @@ class LayerIndexWebRestApiTest(LayersTest):
break break
else: else:
self.logger.debug(1, "meta-python was not found") self.logger.debug(1, "meta-python was not found")
self.assetTrue(False) raise self.failureException
# Only check the first element... # Only check the first element...
break break

View File

@ -705,11 +705,7 @@ class LexerReflect(object):
# Sort the functions by line number # Sort the functions by line number
for f in self.funcsym.values(): for f in self.funcsym.values():
if sys.version_info[0] < 3: f.sort(key=lambda x: func_code(x[1]).co_firstlineno)
f.sort(lambda x,y: cmp(func_code(x[1]).co_firstlineno,func_code(y[1]).co_firstlineno))
else:
# Python 3.0
f.sort(key=lambda x: func_code(x[1]).co_firstlineno)
# Sort the strings by regular expression length # Sort the strings by regular expression length
for s in self.strsym.values(): for s in self.strsym.values():

View File

@ -1205,7 +1205,7 @@ class Production(object):
# Precompute the list of productions immediately following. Hack. Remove later # Precompute the list of productions immediately following. Hack. Remove later
try: try:
p.lr_after = Prodnames[p.prod[n+1]] p.lr_after = self.Prodnames[p.prod[n+1]]
except (IndexError,KeyError): except (IndexError,KeyError):
p.lr_after = [] p.lr_after = []
try: try:

View File

@ -75,7 +75,7 @@ class SeleniumFunctionalTestCase(SeleniumTestCaseBase):
try: try:
table_element = self.get_table_element(table_id) table_element = self.get_table_element(table_id)
element = table_element.find_element_by_link_text(link_text) element = table_element.find_element_by_link_text(link_text)
except NoSuchElementException as e: except self.NoSuchElementException:
print('no element found') print('no element found')
raise raise
return element return element
@ -86,7 +86,7 @@ class SeleniumFunctionalTestCase(SeleniumTestCaseBase):
element_xpath = "//*[@id='" + table_id + "']" element_xpath = "//*[@id='" + table_id + "']"
try: try:
element = self.driver.find_element_by_xpath(element_xpath) element = self.driver.find_element_by_xpath(element_xpath)
except NoSuchElementException as e: except self.NoSuchElementException:
raise raise
return element return element
row = coordinate[0] row = coordinate[0]
@ -96,7 +96,7 @@ class SeleniumFunctionalTestCase(SeleniumTestCaseBase):
element_xpath = "//*[@id='" + table_id + "']/tbody/tr[" + str(row) + "]" element_xpath = "//*[@id='" + table_id + "']/tbody/tr[" + str(row) + "]"
try: try:
element = self.driver.find_element_by_xpath(element_xpath) element = self.driver.find_element_by_xpath(element_xpath)
except NoSuchElementException as e: except self.NoSuchElementException:
return False return False
return element return element
#now we are looking for an element with specified X and Y #now we are looking for an element with specified X and Y
@ -105,6 +105,6 @@ class SeleniumFunctionalTestCase(SeleniumTestCaseBase):
element_xpath = "//*[@id='" + table_id + "']/tbody/tr[" + str(row) + "]/td[" + str(column) + "]" element_xpath = "//*[@id='" + table_id + "']/tbody/tr[" + str(row) + "]/td[" + str(column) + "]"
try: try:
element = self.driver.find_element_by_xpath(element_xpath) element = self.driver.find_element_by_xpath(element_xpath)
except NoSuchElementException as e: except self.NoSuchElementException:
return False return False
return element return element