[rtems-tools commit] Python 2 and python 3 refactor fixes.

Chris Johns chrisj at rtems.org
Wed Mar 9 03:31:59 UTC 2016


Module:    rtems-tools
Branch:    master
Commit:    2de37f3432d67e7cbaa1891769cc5ddb9fb24bc3
Changeset: http://git.rtems.org/rtems-tools/commit/?id=2de37f3432d67e7cbaa1891769cc5ddb9fb24bc3

Author:    Chris Johns <chrisj at rtems.org>
Date:      Wed Mar  9 14:27:42 2016 +1100

Python 2 and python 3 refactor fixes.

Updates #2619.

---

 rtemstoolkit/config.py  | 16 +++++++++-------
 rtemstoolkit/execute.py |  3 ++-
 rtemstoolkit/log.py     |  2 +-
 rtemstoolkit/macros.py  |  1 +
 tester/rt/test.py       |  4 ++++
 5 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/rtemstoolkit/config.py b/rtemstoolkit/config.py
index 4b2e8e1..697bcaf 100644
--- a/rtemstoolkit/config.py
+++ b/rtemstoolkit/config.py
@@ -44,6 +44,10 @@ import os
 import re
 import sys
 
+#
+# Support to handle use in a package and as a unit test.
+# If there is a better way to let us know.
+#
 try:
     from . import error
     from . import execute
@@ -51,11 +55,11 @@ try:
     from . import options
     from . import path
 except (ValueError, SystemError):
-     import error
-     import execute
-     import log
-     import options
-     import path
+    import error
+    import execute
+    import log
+    import options
+    import path
 
 def _check_bool(value):
     if value.isdigit():
@@ -849,8 +853,6 @@ def run():
                                     argv = sys.argv,
                                     long_opts = long_opts)
         options.load(opts)
-        if '_file' not in opts.defaults:
-            raise error.general('no --file option provided')
         s = file(opts.defaults['_file'], opts)
         s.load(opts.defaults['_file'])
         print(s)
diff --git a/rtemstoolkit/execute.py b/rtemstoolkit/execute.py
index 982e35f..7c168af 100755
--- a/rtemstoolkit/execute.py
+++ b/rtemstoolkit/execute.py
@@ -192,7 +192,8 @@ class execute(object):
                     data = fh.read(1)
                     if len(data) == 0:
                         break
-                    if type(data) == bytes:
+                    # str and bytes are the same type in Python2
+                    if type(data) is not str and type(data) is bytes:
                         data = data.decode(sys.stdout.encoding)
                     for c in data:
                         line += c
diff --git a/rtemstoolkit/log.py b/rtemstoolkit/log.py
index 61a3b02..4d89b77 100755
--- a/rtemstoolkit/log.py
+++ b/rtemstoolkit/log.py
@@ -89,7 +89,7 @@ def _output(text = os.linesep, log = None):
 def stderr(text = os.linesep, log = None):
     lock.acquire()
     for l in text.replace(chr(13), '').splitlines():
-        print >> sys.stderr, l
+        print(l, file = sys.stderr)
     lock.release()
 
 def output(text = os.linesep, log = None):
diff --git a/rtemstoolkit/macros.py b/rtemstoolkit/macros.py
index c92a6c9..2ebc132 100644
--- a/rtemstoolkit/macros.py
+++ b/rtemstoolkit/macros.py
@@ -188,6 +188,7 @@ class macros:
         return macro[2]
 
     def __setitem__(self, key, value):
+        key = self._unicode_to_str(key)
         if type(key) is not str:
             raise TypeError('bad key type (want str): %s' % (type(key)))
         if type(value) is not tuple:
diff --git a/tester/rt/test.py b/tester/rt/test.py
index 3e1bb96..0288822 100644
--- a/tester/rt/test.py
+++ b/tester/rt/test.py
@@ -99,6 +99,7 @@ class test_run(object):
     def runner(self):
         self.start_time = datetime.datetime.now()
         try:
+            xx
             self.test = test(self.index, self.total, self.report,
                              self.executable, self.rtems_tools,
                              self.bsp, self.bsp_config,
@@ -120,6 +121,9 @@ class test_run(object):
 
     def reraise(self):
         if self.result is not None:
+            with_tb = getattr(self.result[1], 'with_traceback', None)
+            if with_tb:
+                raise self.result[1].with_traceback(self.result[2])
             raise (self.result[0], self.result[1], self.result[2])
 
     def kill(self):




More information about the vc mailing list