mirror of
https://git.yoctoproject.org/poky
synced 2026-06-02 01:19:52 +00:00
classes/lib: Complete transition to python3
This patch contains all the other misc pieces of the transition to python3 which didn't make sense to be broken into individual patches. (From OE-Core rev: fcd6b38bab8517d83e1ed48eef1bca9a9a190f57) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
@@ -41,7 +41,7 @@ class Command(object):
|
||||
self.data = data
|
||||
|
||||
self.options = dict(self.defaultopts)
|
||||
if isinstance(self.cmd, basestring):
|
||||
if isinstance(self.cmd, str):
|
||||
self.options["shell"] = True
|
||||
if self.data:
|
||||
self.options['stdin'] = subprocess.PIPE
|
||||
@@ -123,7 +123,7 @@ def bitbake(command, ignore_status=False, timeout=None, postconfig=None, **optio
|
||||
else:
|
||||
extra_args = ""
|
||||
|
||||
if isinstance(command, basestring):
|
||||
if isinstance(command, str):
|
||||
cmd = "bitbake " + extra_args + " " + command
|
||||
else:
|
||||
cmd = [ "bitbake" ] + [a for a in (command + extra_args.split(" ")) if a not in [""]]
|
||||
|
||||
@@ -115,6 +115,8 @@ class NoParsingFilter(logging.Filter):
|
||||
def filter(self, record):
|
||||
return record.levelno == 100
|
||||
|
||||
import inspect
|
||||
|
||||
def LogResults(original_class):
|
||||
orig_method = original_class.run
|
||||
|
||||
@@ -124,6 +126,19 @@ def LogResults(original_class):
|
||||
logfile = os.path.join(os.getcwd(),'results-'+caller+'.'+timestamp+'.log')
|
||||
linkfile = os.path.join(os.getcwd(),'results-'+caller+'.log')
|
||||
|
||||
def get_class_that_defined_method(meth):
|
||||
if inspect.ismethod(meth):
|
||||
for cls in inspect.getmro(meth.__self__.__class__):
|
||||
if cls.__dict__.get(meth.__name__) is meth:
|
||||
return cls
|
||||
meth = meth.__func__ # fallback to __qualname__ parsing
|
||||
if inspect.isfunction(meth):
|
||||
cls = getattr(inspect.getmodule(meth),
|
||||
meth.__qualname__.split('.<locals>', 1)[0].rsplit('.', 1)[0])
|
||||
if isinstance(cls, type):
|
||||
return cls
|
||||
return None
|
||||
|
||||
#rewrite the run method of unittest.TestCase to add testcase logging
|
||||
def run(self, result, *args, **kws):
|
||||
orig_method(self, result, *args, **kws)
|
||||
@@ -135,7 +150,7 @@ def LogResults(original_class):
|
||||
except AttributeError:
|
||||
test_case = self._testMethodName
|
||||
|
||||
class_name = str(testMethod.im_class).split("'")[1]
|
||||
class_name = str(get_class_that_defined_method(testMethod)).split("'")[1]
|
||||
|
||||
#create custom logging level for filtering.
|
||||
custom_log_level = 100
|
||||
|
||||
@@ -3,7 +3,7 @@ import sys
|
||||
import errno
|
||||
import datetime
|
||||
import itertools
|
||||
from commands import runCmd
|
||||
from .commands import runCmd
|
||||
|
||||
def get_host_dumper(d):
|
||||
cmds = d.getVar("testimage_dump_host", True)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import SimpleHTTPServer
|
||||
import http.server
|
||||
import multiprocessing
|
||||
import os
|
||||
|
||||
class HTTPServer(SimpleHTTPServer.BaseHTTPServer.HTTPServer):
|
||||
class HTTPServer(http.server.HTTPServer):
|
||||
|
||||
def server_start(self, root_dir):
|
||||
import signal
|
||||
@@ -10,7 +10,7 @@ class HTTPServer(SimpleHTTPServer.BaseHTTPServer.HTTPServer):
|
||||
os.chdir(root_dir)
|
||||
self.serve_forever()
|
||||
|
||||
class HTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||
class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
|
||||
|
||||
def log_message(self, format_str, *args):
|
||||
pass
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import ftools
|
||||
from . import ftools
|
||||
|
||||
|
||||
# A parser that can be used to identify weather a line is a test result or a section statement.
|
||||
|
||||
@@ -23,8 +23,8 @@ logger = logging.getLogger("BitBake.QemuRunner")
|
||||
|
||||
# Get Unicode non printable control chars
|
||||
control_range = list(range(0,32))+list(range(127,160))
|
||||
control_chars = [unichr(x) for x in control_range
|
||||
if unichr(x) not in string.printable]
|
||||
control_chars = [chr(x) for x in control_range
|
||||
if chr(x) not in string.printable]
|
||||
re_control_char = re.compile('[%s]' % re.escape("".join(control_chars)))
|
||||
|
||||
class QemuRunner:
|
||||
@@ -220,6 +220,7 @@ class QemuRunner:
|
||||
stopread = False
|
||||
qemusock = None
|
||||
bootlog = ''
|
||||
data = b''
|
||||
while time.time() < endtime and not stopread:
|
||||
sread, swrite, serror = select.select(socklist, [], [], 5)
|
||||
for sock in sread:
|
||||
@@ -283,13 +284,14 @@ class QemuRunner:
|
||||
if hasattr(self, "origchldhandler"):
|
||||
signal.signal(signal.SIGCHLD, self.origchldhandler)
|
||||
if self.runqemu:
|
||||
os.kill(self.monitorpid, signal.SIGKILL)
|
||||
logger.info("Sending SIGTERM to runqemu")
|
||||
try:
|
||||
os.killpg(os.getpgid(self.runqemu.pid), signal.SIGTERM)
|
||||
except OSError as e:
|
||||
if e.errno != errno.ESRCH:
|
||||
raise
|
||||
if hasattr(self, "monitorpid"):
|
||||
os.kill(self.monitorpid, signal.SIGKILL)
|
||||
logger.info("Sending SIGTERM to runqemu")
|
||||
try:
|
||||
os.killpg(os.getpgid(self.runqemu.pid), signal.SIGTERM)
|
||||
except OSError as e:
|
||||
if e.errno != errno.ESRCH:
|
||||
raise
|
||||
endtime = time.time() + self.runqemutime
|
||||
while self.runqemu.poll() is None and time.time() < endtime:
|
||||
time.sleep(1)
|
||||
@@ -448,7 +450,7 @@ class LoggingThread(threading.Thread):
|
||||
def stop(self):
|
||||
self.logger.info("Stopping logging thread")
|
||||
if self.running:
|
||||
os.write(self.writepipe, "stop")
|
||||
os.write(self.writepipe, bytes("stop", "utf-8"))
|
||||
|
||||
def teardown(self):
|
||||
self.logger.info("Tearing down logging thread")
|
||||
|
||||
@@ -13,7 +13,7 @@ import re
|
||||
import socket
|
||||
import select
|
||||
import bb
|
||||
from qemurunner import QemuRunner
|
||||
from .qemurunner import QemuRunner
|
||||
|
||||
class QemuTinyRunner(QemuRunner):
|
||||
|
||||
|
||||
@@ -10,9 +10,7 @@ import bb.utils
|
||||
import subprocess
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
class BuildProject():
|
||||
|
||||
__metaclass__ = ABCMeta
|
||||
class BuildProject(metaclass=ABCMeta):
|
||||
|
||||
def __init__(self, d, uri, foldername=None, tmpdir="/tmp/"):
|
||||
self.d = d
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import os, re, glob as g, shutil as sh,sys
|
||||
from time import sleep
|
||||
from commands import runCmd
|
||||
from .commands import runCmd
|
||||
from difflib import SequenceMatcher as SM
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user