diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-05-20 11:57:44 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-06-02 08:24:01 +0100 |
commit | 3b3997174831931ea472167ba6cc854a4972ccce (patch) | |
tree | 861b0bcb54e70fbe59bf7920862954dcec40a1e8 /meta/lib/oeqa/utils | |
parent | 52c4b7f247618f185a11dfb1cf15d0490d074379 (diff) | |
download | poky-3b3997174831931ea472167ba6cc854a4972ccce.tar.gz |
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>
Diffstat (limited to 'meta/lib/oeqa/utils')
-rw-r--r-- | meta/lib/oeqa/utils/commands.py | 4 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/decorators.py | 17 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/dump.py | 2 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/httpserver.py | 6 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/logparser.py | 2 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/qemurunner.py | 22 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/qemutinyrunner.py | 2 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/targetbuild.py | 4 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/testexport.py | 2 |
9 files changed, 38 insertions, 23 deletions
diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py index 9a7c1d1375..18fe39ecfe 100644 --- a/meta/lib/oeqa/utils/commands.py +++ b/meta/lib/oeqa/utils/commands.py | |||
@@ -41,7 +41,7 @@ class Command(object): | |||
41 | self.data = data | 41 | self.data = data |
42 | 42 | ||
43 | self.options = dict(self.defaultopts) | 43 | self.options = dict(self.defaultopts) |
44 | if isinstance(self.cmd, basestring): | 44 | if isinstance(self.cmd, str): |
45 | self.options["shell"] = True | 45 | self.options["shell"] = True |
46 | if self.data: | 46 | if self.data: |
47 | self.options['stdin'] = subprocess.PIPE | 47 | self.options['stdin'] = subprocess.PIPE |
@@ -123,7 +123,7 @@ def bitbake(command, ignore_status=False, timeout=None, postconfig=None, **optio | |||
123 | else: | 123 | else: |
124 | extra_args = "" | 124 | extra_args = "" |
125 | 125 | ||
126 | if isinstance(command, basestring): | 126 | if isinstance(command, str): |
127 | cmd = "bitbake " + extra_args + " " + command | 127 | cmd = "bitbake " + extra_args + " " + command |
128 | else: | 128 | else: |
129 | cmd = [ "bitbake" ] + [a for a in (command + extra_args.split(" ")) if a not in [""]] | 129 | cmd = [ "bitbake" ] + [a for a in (command + extra_args.split(" ")) if a not in [""]] |
diff --git a/meta/lib/oeqa/utils/decorators.py b/meta/lib/oeqa/utils/decorators.py index 6fb09db417..0b23565485 100644 --- a/meta/lib/oeqa/utils/decorators.py +++ b/meta/lib/oeqa/utils/decorators.py | |||
@@ -115,6 +115,8 @@ class NoParsingFilter(logging.Filter): | |||
115 | def filter(self, record): | 115 | def filter(self, record): |
116 | return record.levelno == 100 | 116 | return record.levelno == 100 |
117 | 117 | ||
118 | import inspect | ||
119 | |||
118 | def LogResults(original_class): | 120 | def LogResults(original_class): |
119 | orig_method = original_class.run | 121 | orig_method = original_class.run |
120 | 122 | ||
@@ -124,6 +126,19 @@ def LogResults(original_class): | |||
124 | logfile = os.path.join(os.getcwd(),'results-'+caller+'.'+timestamp+'.log') | 126 | logfile = os.path.join(os.getcwd(),'results-'+caller+'.'+timestamp+'.log') |
125 | linkfile = os.path.join(os.getcwd(),'results-'+caller+'.log') | 127 | linkfile = os.path.join(os.getcwd(),'results-'+caller+'.log') |
126 | 128 | ||
129 | def get_class_that_defined_method(meth): | ||
130 | if inspect.ismethod(meth): | ||
131 | for cls in inspect.getmro(meth.__self__.__class__): | ||
132 | if cls.__dict__.get(meth.__name__) is meth: | ||
133 | return cls | ||
134 | meth = meth.__func__ # fallback to __qualname__ parsing | ||
135 | if inspect.isfunction(meth): | ||
136 | cls = getattr(inspect.getmodule(meth), | ||
137 | meth.__qualname__.split('.<locals>', 1)[0].rsplit('.', 1)[0]) | ||
138 | if isinstance(cls, type): | ||
139 | return cls | ||
140 | return None | ||
141 | |||
127 | #rewrite the run method of unittest.TestCase to add testcase logging | 142 | #rewrite the run method of unittest.TestCase to add testcase logging |
128 | def run(self, result, *args, **kws): | 143 | def run(self, result, *args, **kws): |
129 | orig_method(self, result, *args, **kws) | 144 | orig_method(self, result, *args, **kws) |
@@ -135,7 +150,7 @@ def LogResults(original_class): | |||
135 | except AttributeError: | 150 | except AttributeError: |
136 | test_case = self._testMethodName | 151 | test_case = self._testMethodName |
137 | 152 | ||
138 | class_name = str(testMethod.im_class).split("'")[1] | 153 | class_name = str(get_class_that_defined_method(testMethod)).split("'")[1] |
139 | 154 | ||
140 | #create custom logging level for filtering. | 155 | #create custom logging level for filtering. |
141 | custom_log_level = 100 | 156 | custom_log_level = 100 |
diff --git a/meta/lib/oeqa/utils/dump.py b/meta/lib/oeqa/utils/dump.py index 63a591d366..71422a9aea 100644 --- a/meta/lib/oeqa/utils/dump.py +++ b/meta/lib/oeqa/utils/dump.py | |||
@@ -3,7 +3,7 @@ import sys | |||
3 | import errno | 3 | import errno |
4 | import datetime | 4 | import datetime |
5 | import itertools | 5 | import itertools |
6 | from commands import runCmd | 6 | from .commands import runCmd |
7 | 7 | ||
8 | def get_host_dumper(d): | 8 | def get_host_dumper(d): |
9 | cmds = d.getVar("testimage_dump_host", True) | 9 | cmds = d.getVar("testimage_dump_host", True) |
diff --git a/meta/lib/oeqa/utils/httpserver.py b/meta/lib/oeqa/utils/httpserver.py index 76518d8ef9..bd76f36468 100644 --- a/meta/lib/oeqa/utils/httpserver.py +++ b/meta/lib/oeqa/utils/httpserver.py | |||
@@ -1,8 +1,8 @@ | |||
1 | import SimpleHTTPServer | 1 | import http.server |
2 | import multiprocessing | 2 | import multiprocessing |
3 | import os | 3 | import os |
4 | 4 | ||
5 | class HTTPServer(SimpleHTTPServer.BaseHTTPServer.HTTPServer): | 5 | class HTTPServer(http.server.HTTPServer): |
6 | 6 | ||
7 | def server_start(self, root_dir): | 7 | def server_start(self, root_dir): |
8 | import signal | 8 | import signal |
@@ -10,7 +10,7 @@ class HTTPServer(SimpleHTTPServer.BaseHTTPServer.HTTPServer): | |||
10 | os.chdir(root_dir) | 10 | os.chdir(root_dir) |
11 | self.serve_forever() | 11 | self.serve_forever() |
12 | 12 | ||
13 | class HTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): | 13 | class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler): |
14 | 14 | ||
15 | def log_message(self, format_str, *args): | 15 | def log_message(self, format_str, *args): |
16 | pass | 16 | pass |
diff --git a/meta/lib/oeqa/utils/logparser.py b/meta/lib/oeqa/utils/logparser.py index 87b50354cd..b377dcd271 100644 --- a/meta/lib/oeqa/utils/logparser.py +++ b/meta/lib/oeqa/utils/logparser.py | |||
@@ -3,7 +3,7 @@ | |||
3 | import sys | 3 | import sys |
4 | import os | 4 | import os |
5 | import re | 5 | import re |
6 | import ftools | 6 | from . import ftools |
7 | 7 | ||
8 | 8 | ||
9 | # A parser that can be used to identify weather a line is a test result or a section statement. | 9 | # A parser that can be used to identify weather a line is a test result or a section statement. |
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py index 3d60433cae..e408fbbf3a 100644 --- a/meta/lib/oeqa/utils/qemurunner.py +++ b/meta/lib/oeqa/utils/qemurunner.py | |||
@@ -23,8 +23,8 @@ logger = logging.getLogger("BitBake.QemuRunner") | |||
23 | 23 | ||
24 | # Get Unicode non printable control chars | 24 | # Get Unicode non printable control chars |
25 | control_range = list(range(0,32))+list(range(127,160)) | 25 | control_range = list(range(0,32))+list(range(127,160)) |
26 | control_chars = [unichr(x) for x in control_range | 26 | control_chars = [chr(x) for x in control_range |
27 | if unichr(x) not in string.printable] | 27 | if chr(x) not in string.printable] |
28 | re_control_char = re.compile('[%s]' % re.escape("".join(control_chars))) | 28 | re_control_char = re.compile('[%s]' % re.escape("".join(control_chars))) |
29 | 29 | ||
30 | class QemuRunner: | 30 | class QemuRunner: |
@@ -220,6 +220,7 @@ class QemuRunner: | |||
220 | stopread = False | 220 | stopread = False |
221 | qemusock = None | 221 | qemusock = None |
222 | bootlog = '' | 222 | bootlog = '' |
223 | data = b'' | ||
223 | while time.time() < endtime and not stopread: | 224 | while time.time() < endtime and not stopread: |
224 | sread, swrite, serror = select.select(socklist, [], [], 5) | 225 | sread, swrite, serror = select.select(socklist, [], [], 5) |
225 | for sock in sread: | 226 | for sock in sread: |
@@ -283,13 +284,14 @@ class QemuRunner: | |||
283 | if hasattr(self, "origchldhandler"): | 284 | if hasattr(self, "origchldhandler"): |
284 | signal.signal(signal.SIGCHLD, self.origchldhandler) | 285 | signal.signal(signal.SIGCHLD, self.origchldhandler) |
285 | if self.runqemu: | 286 | if self.runqemu: |
286 | os.kill(self.monitorpid, signal.SIGKILL) | 287 | if hasattr(self, "monitorpid"): |
287 | logger.info("Sending SIGTERM to runqemu") | 288 | os.kill(self.monitorpid, signal.SIGKILL) |
288 | try: | 289 | logger.info("Sending SIGTERM to runqemu") |
289 | os.killpg(os.getpgid(self.runqemu.pid), signal.SIGTERM) | 290 | try: |
290 | except OSError as e: | 291 | os.killpg(os.getpgid(self.runqemu.pid), signal.SIGTERM) |
291 | if e.errno != errno.ESRCH: | 292 | except OSError as e: |
292 | raise | 293 | if e.errno != errno.ESRCH: |
294 | raise | ||
293 | endtime = time.time() + self.runqemutime | 295 | endtime = time.time() + self.runqemutime |
294 | while self.runqemu.poll() is None and time.time() < endtime: | 296 | while self.runqemu.poll() is None and time.time() < endtime: |
295 | time.sleep(1) | 297 | time.sleep(1) |
@@ -448,7 +450,7 @@ class LoggingThread(threading.Thread): | |||
448 | def stop(self): | 450 | def stop(self): |
449 | self.logger.info("Stopping logging thread") | 451 | self.logger.info("Stopping logging thread") |
450 | if self.running: | 452 | if self.running: |
451 | os.write(self.writepipe, "stop") | 453 | os.write(self.writepipe, bytes("stop", "utf-8")) |
452 | 454 | ||
453 | def teardown(self): | 455 | def teardown(self): |
454 | self.logger.info("Tearing down logging thread") | 456 | self.logger.info("Tearing down logging thread") |
diff --git a/meta/lib/oeqa/utils/qemutinyrunner.py b/meta/lib/oeqa/utils/qemutinyrunner.py index 054ab0ec5d..c823157ad6 100644 --- a/meta/lib/oeqa/utils/qemutinyrunner.py +++ b/meta/lib/oeqa/utils/qemutinyrunner.py | |||
@@ -13,7 +13,7 @@ import re | |||
13 | import socket | 13 | import socket |
14 | import select | 14 | import select |
15 | import bb | 15 | import bb |
16 | from qemurunner import QemuRunner | 16 | from .qemurunner import QemuRunner |
17 | 17 | ||
18 | class QemuTinyRunner(QemuRunner): | 18 | class QemuTinyRunner(QemuRunner): |
19 | 19 | ||
diff --git a/meta/lib/oeqa/utils/targetbuild.py b/meta/lib/oeqa/utils/targetbuild.py index f850d78df1..d538f6b65f 100644 --- a/meta/lib/oeqa/utils/targetbuild.py +++ b/meta/lib/oeqa/utils/targetbuild.py | |||
@@ -10,9 +10,7 @@ import bb.utils | |||
10 | import subprocess | 10 | import subprocess |
11 | from abc import ABCMeta, abstractmethod | 11 | from abc import ABCMeta, abstractmethod |
12 | 12 | ||
13 | class BuildProject(): | 13 | class BuildProject(metaclass=ABCMeta): |
14 | |||
15 | __metaclass__ = ABCMeta | ||
16 | 14 | ||
17 | def __init__(self, d, uri, foldername=None, tmpdir="/tmp/"): | 15 | def __init__(self, d, uri, foldername=None, tmpdir="/tmp/"): |
18 | self.d = d | 16 | self.d = d |
diff --git a/meta/lib/oeqa/utils/testexport.py b/meta/lib/oeqa/utils/testexport.py index 4fbf4bdcb3..57be2ca449 100644 --- a/meta/lib/oeqa/utils/testexport.py +++ b/meta/lib/oeqa/utils/testexport.py | |||
@@ -6,7 +6,7 @@ | |||
6 | 6 | ||
7 | import os, re, glob as g, shutil as sh,sys | 7 | import os, re, glob as g, shutil as sh,sys |
8 | from time import sleep | 8 | from time import sleep |
9 | from commands import runCmd | 9 | from .commands import runCmd |
10 | from difflib import SequenceMatcher as SM | 10 | from difflib import SequenceMatcher as SM |
11 | 11 | ||
12 | try: | 12 | try: |