[PATCH 1/2] python: Provide support to select a valid python version.

chrisj at rtems.org chrisj at rtems.org
Wed Nov 7 04:01:40 UTC 2018


From: Chris Johns <chrisj at rtems.org>

- Update imports after wrapping the code.
- Fix python3 issues.
- Fix config path issues for in repo and install runs.

Closes #3537
---
 rtemstoolkit/configuration.py  | 30 +++++++++++++----------
 rtemstoolkit/python-wrapper.sh | 54 ++++++++++++++++++++++++++++++++++++++++++
 rtemstoolkit/rtems.py          | 32 +++++++++++++++----------
 rtemstoolkit/wscript           |  3 +++
 tester/rt/check.py             | 19 ++++++++-------
 tester/rt/cmd-bsp-builder.py   | 45 +++++++++++++++++++++++++++++++++++
 tester/rt/cmd-run.py           | 44 ++++++++++++++++++++++++++++++++++
 tester/rt/cmd-test.py          | 45 +++++++++++++++++++++++++++++++++++
 tester/rt/config.py            |  6 ++---
 tester/rt/console.py           |  4 ++--
 tester/rt/coverage.py          |  2 +-
 tester/rt/gdb.py               | 12 ++--------
 tester/rt/run.py               | 19 ++++++---------
 tester/rt/test.py              | 16 ++++++-------
 tester/rt/tftp.py              |  9 +------
 tester/rtems-bsp-builder       | 29 +++++++++++------------
 tester/rtems-run               | 29 +++++++++++------------
 tester/rtems-test              | 29 +++++++++++------------
 tester/wscript                 |  3 +++
 19 files changed, 308 insertions(+), 122 deletions(-)
 create mode 100644 rtemstoolkit/python-wrapper.sh
 create mode 100755 tester/rt/cmd-bsp-builder.py
 create mode 100755 tester/rt/cmd-run.py
 create mode 100755 tester/rt/cmd-test.py

diff --git a/rtemstoolkit/configuration.py b/rtemstoolkit/configuration.py
index 10d97e5..3b03296 100644
--- a/rtemstoolkit/configuration.py
+++ b/rtemstoolkit/configuration.py
@@ -37,18 +37,20 @@ from __future__ import print_function
 import os
 import re
 
-try:
-    import configparser
-except:
-    import ConfigParser as configparser
-
 from rtemstoolkit import error
 from rtemstoolkit import path
 
 class configuration:
 
-    def __init__(self):
-        self.config = configparser.ConfigParser()
+    def __init__(self, raw = True):
+        self.raw = True
+        try:
+            import configparser
+            self.config = configparser.ConfigParser(strict = False)
+        except:
+            # python2
+            import ConfigParser as configparser
+            self.config = configparser.ConfigParser()
         self.ini = None
         self.macro_filter = re.compile('\$\{.+\}')
 
@@ -66,12 +68,15 @@ class configuration:
         for section in self.config.sections():
             s += [' [%s]' % (section)]
             for option in self.config.options(section):
-                s += ['  %s = %s' % (option, self.config.get(section, option))]
+                s += ['  %s = %s' % (option,
+                                     self.config.get(section,
+                                                     option,
+                                                     raw = self.raw))]
         return os.linesep.join(s)
 
     def get_item(self, section, label, err = True):
         try:
-            rec = self.config.get(section, label).replace(os.linesep, ' ')
+            rec = self.config.get(section, label, raw = self.raw).replace(os.linesep, ' ')
         except:
             if err:
                 raise error.general('config: no "%s" found in "%s"' % (label, section))
@@ -89,7 +94,8 @@ class configuration:
                 raise error.general('config: interpolation is ${section:value}: %s' % (m))
             try:
                 ref = self.config.get(section_value[0],
-                                      section_value[1]).replace(os.linesep, ' ')
+                                      section_value[1],
+                                      raw = self.raw).replace(os.linesep, ' ')
                 rec = rec.replace(m, ref)
             except:
                 pass
@@ -98,7 +104,7 @@ class configuration:
     def get_items(self, section, err = True, flatten = True):
         try:
             items = []
-            for name, key in self.config.items(section):
+            for name, key in self.config.items(section, raw = self.raw):
                 if flatten:
                     items += [(name, key.replace(os.linesep, ' '))]
                 else:
@@ -117,7 +123,7 @@ class configuration:
 
     def get_item_names(self, section, err = True):
         try:
-            return [item[0] for item in self.config.items(section)]
+            return [item[0] for item in self.config.items(section, raw = self.raw)]
         except:
             if err:
                 raise error.general('config: section "%s" not found' % (section))
diff --git a/rtemstoolkit/python-wrapper.sh b/rtemstoolkit/python-wrapper.sh
new file mode 100644
index 0000000..105873f
--- /dev/null
+++ b/rtemstoolkit/python-wrapper.sh
@@ -0,0 +1,54 @@
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2018 Chris Johns (chrisj at rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+#
+# This script wraps python finding a suitable version to use.
+#
+set -e
+if test ! -f $PYTHON_CMD; then
+  echo "error: RTEMS Toolkit python command not found: $PYTHON_CMD"
+  exit 5
+fi
+for py in python2 python3 python
+do
+  set +e
+  py_cmd=$(command -v $py)
+  set -e
+  if test -n "$RTEMS_PYTHON_OVERRIDE"; then
+    if test "$RTEMS_PYTHON_OVERRIDE" != "$py"; then
+      py_cmd=""
+    fi
+  fi
+  if test -n "$py_cmd"; then
+    exec $py_cmd $PYTHON_CMD $0 $*
+  fi
+done
+echo "error: RTEMS Toolkit no valid python found"
+exit 5
diff --git a/rtemstoolkit/rtems.py b/rtemstoolkit/rtems.py
index 8aa22e5..157cb5b 100755
--- a/rtemstoolkit/rtems.py
+++ b/rtemstoolkit/rtems.py
@@ -62,15 +62,21 @@ def clean_windows_path():
         if 'msys' in cspath[0] and cspath[0].endswith('bin'):
             os.environ['PATH'] = os.pathsep.join(cspath[1:])
 
-def configuration_path():
+def configuration_path(prog = None):
     '''Return the path the configuration data path for RTEMS. The path is relative
     to the installed executable. Mangage the installed package and the in source
     tree when running from within the rtems-tools repo.
-
+    Note:
+     1. This code assumes the executable is wrapped and not using 'env'.
+     2. Ok to directly call os.path.
     '''
-    exec_name = os.path.abspath(sys.argv[0])
-    for top in [os.path.dirname(exec_name),
-                os.path.dirname(os.path.dirname(exec_name))]:
+    if prog is None:
+        exec_name = sys.argv[1]
+    else:
+        exec_name = prog
+    exec_name = os.path.abspath(exec_name)
+    for top in [os.path.dirname(os.path.dirname(exec_name)),
+                os.path.dirname(exec_name)]:
         config_path = path.join(top, 'share', 'rtems', 'config')
         if path.exists(config_path):
             break
@@ -80,21 +86,21 @@ def configuration_path():
         config_path = None
     return config_path
 
-def configuration_file(config):
+def configuration_file(config, prog = None):
     '''Return the path to a configuration file for RTEMS. The path is relative to
     the installed executable or we are testing and running from within the
     rtems-tools repo.
 
     '''
-    return path.join(configuration_path(), config)
+    return path.join(configuration_path(prog = prog), config)
 
-def bsp_configuration_file():
+def bsp_configuration_file(prog = None):
     '''Return the path to the BSP configuration file for RTEMS. The path is
     relative to the installed executable or we are testing and running from
     within the rtems-tools repo.
 
     '''
-    return configuration_file('rtems-bsps.ini')
+    return configuration_file('rtems-bsps.ini', prog = prog)
 
 class configuration:
 
@@ -227,13 +233,13 @@ class configuration:
         return ' '.join([self.config_flags('no-' + e) for e in self.excludes(arch, bsp)])
 
     def archs(self):
-        return sorted(self.archs.keys())
+        return sorted(list(self.archs.keys()))
 
     def arch_present(self, arch):
         return arch in self.archs
 
     def arch_excludes(self, arch):
-        excludes = self.archs[arch]['excludes'].keys()
+        excludes = list(self.archs[arch]['excludes'].keys())
         for exclude in self.archs[arch]['excludes']:
             if 'all' not in self.archs[arch]['excludes'][exclude]:
                 excludes.remove(exclude)
@@ -246,7 +252,7 @@ class configuration:
         return bsp in self.archs[arch]['bsps']
 
     def bsp_excludes(self, arch, bsp):
-        excludes = self.archs[arch]['excludes'].keys()
+        excludes = list(self.archs[arch]['excludes'].keys())
         for exclude in self.archs[arch]['excludes']:
             if 'all' not in self.archs[arch]['excludes'][exclude] and \
                bsp not in self.archs[arch]['excludes'][exclude]:
@@ -362,7 +368,7 @@ class configuration:
             s += os.linesep
         if architectures:
             s += textbox.line(cols_1, line = '=', marker = '+', indent = 1)
-            archs = sorted(self.archs.keys())
+            archs = sorted(list(self.archs.keys()))
             bsps = 0
             asize = 0
             for arch in archs:
diff --git a/rtemstoolkit/wscript b/rtemstoolkit/wscript
index 1b124c7..82123e5 100644
--- a/rtemstoolkit/wscript
+++ b/rtemstoolkit/wscript
@@ -155,6 +155,9 @@ def build(bld):
                   'windows.py'],
         install_from = '.',
         install_path = '${PREFIX}/share/rtems/rtemstoolkit')
+    bld.install_files('${PREFIX}/share/rtems/rtemstoolkit',
+                      'python-wrapper.sh',
+                      relative_trick = True)
 
 def rebuild(ctx):
     import waflib.Options
diff --git a/tester/rt/check.py b/tester/rt/check.py
index f2addbd..f81ee70 100755
--- a/tester/rt/check.py
+++ b/tester/rt/check.py
@@ -971,7 +971,7 @@ class builder:
         cmd = [path.join(self.rtems, 'configure')]
         for c in cmds:
             c = c.replace('@PREFIX@', self.prefix)
-            c = c.replace('@RTEMS_VERSION@', self.rtems_version)
+            c = c.replace('@RTEMS_VERSION@', str(self.rtems_version))
             c = c.replace('@ARCH@', build.arch)
             c = c.replace('@BSP@', build.bsp)
             cmd += [c]
@@ -1118,7 +1118,7 @@ class builder:
         log.notice('Profile(s): %s' % (', '.join(profiles)))
         self.run_jobs(self.profile_jobs(profiles))
 
-def run_args(args):
+def run(args):
     b = None
     ec = 0
     try:
@@ -1129,9 +1129,15 @@ def run_args(args):
         tools = prefix
         build_dir = 'bsp-builds'
         logf = 'bsp-build-%s.txt' % (_now().strftime('%Y%m%d-%H%M%S'))
-        config_file = rtems.bsp_configuration_file()
+        config_file = rtems.bsp_configuration_file(prog = args[0])
 
-        argsp = argparse.ArgumentParser()
+        description  = 'RTEMS BSP Builder is a BSP build tester. It builds BSPs '
+        description += 'in various ways to test build regressions in the kernel. You '
+        description += 'can build based on tier, architecture, or BSP. You can control '
+        description += 'the profile of build with various build configuration settings.'
+
+        argsp = argparse.ArgumentParser(prog = 'rtems-bsp-builder',
+                                        description = description)
         argsp.add_argument('--prefix', help = 'Prefix to build the BSP.',
                            type = str)
         argsp.add_argument('--rtems-tools', help = 'The RTEMS tools directory.',
@@ -1297,8 +1303,5 @@ def run_args(args):
         b.results.report()
     sys.exit(ec)
 
-def run():
-    run_args(sys.argv)
-
 if __name__ == "__main__":
-    run()
+    run(sys.argv)
diff --git a/tester/rt/cmd-bsp-builder.py b/tester/rt/cmd-bsp-builder.py
new file mode 100755
index 0000000..c94aeaf
--- /dev/null
+++ b/tester/rt/cmd-bsp-builder.py
@@ -0,0 +1,45 @@
+#! /usr/bin/env python
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2016 Chris Johns (chrisj at rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+from __future__ import print_function
+
+import sys, os
+
+base = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
+rtems = os.path.dirname(base)
+sys.path = [rtems] + sys.path
+
+try:
+    import check
+    check.run(sys.argv[1:])
+except ImportError:
+    print("Incorrect RTEMS Tools installation", file = sys.stderr)
+    sys.exit(1)
diff --git a/tester/rt/cmd-run.py b/tester/rt/cmd-run.py
new file mode 100755
index 0000000..221c3f8
--- /dev/null
+++ b/tester/rt/cmd-run.py
@@ -0,0 +1,44 @@
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2017 Chris Johns (chrisj at rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+from __future__ import print_function
+
+import sys, os
+
+base = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
+rtems = os.path.dirname(base)
+sys.path = [rtems] + sys.path
+
+try:
+    import run
+    run.run(sys.argv[1:], command_path = base)
+except ImportError:
+    print("Incorrect RTEMS Tools installation", file = sys.stderr)
+    sys.exit(1)
diff --git a/tester/rt/cmd-test.py b/tester/rt/cmd-test.py
new file mode 100755
index 0000000..93e480f
--- /dev/null
+++ b/tester/rt/cmd-test.py
@@ -0,0 +1,45 @@
+#! /usr/bin/env python
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2013, 2015 Chris Johns (chrisj at rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+from __future__ import print_function
+
+import sys, os
+
+base = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
+rtems = os.path.dirname(base)
+sys.path = [rtems] + sys.path
+
+try:
+    import test
+    test.run(sys.argv[1:], command_path = base)
+except ImportError:
+    print("Incorrect RTEMS Tools installation", file = sys.stderr)
+    sys.exit(1)
diff --git a/tester/rt/config.py b/tester/rt/config.py
index 1c2670a..448581f 100644
--- a/tester/rt/config.py
+++ b/tester/rt/config.py
@@ -46,9 +46,9 @@ from rtemstoolkit import execute
 from rtemstoolkit import log
 from rtemstoolkit import path
 
-from . import console
-from . import gdb
-from . import tftp
+import console
+import gdb
+import tftp
 
 timeout = 15
 
diff --git a/tester/rt/console.py b/tester/rt/console.py
index 0545ace..ad298ea 100644
--- a/tester/rt/console.py
+++ b/tester/rt/console.py
@@ -41,13 +41,13 @@ import time
 
 from rtemstoolkit import path
 
-from . import telnet
+import telnet
 
 #
 # Not available on Windows. Not sure what this means.
 #
 if os.name != 'nt':
-    from . import stty
+    import stty
 else:
     stty = None
 
diff --git a/tester/rt/coverage.py b/tester/rt/coverage.py
index 978a8c4..cd5c501 100644
--- a/tester/rt/coverage.py
+++ b/tester/rt/coverage.py
@@ -47,7 +47,7 @@ from rtemstoolkit import execute
 from rtemstoolkit import macros
 
 
-from . import options
+import options
 
 class summary:
     def __init__(self, p_summary_dir):
diff --git a/tester/rt/gdb.py b/tester/rt/gdb.py
index 1669693..2416a50 100644
--- a/tester/rt/gdb.py
+++ b/tester/rt/gdb.py
@@ -48,16 +48,8 @@ from rtemstoolkit import execute
 from rtemstoolkit import options
 from rtemstoolkit import path
 
-#
-# 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 console
-    from . import pygdb
-except (ValueError, SystemError):
-    import console
-    import pygdb
+import console
+import pygdb
 
 #
 # The MI parser needs a global lock. It has global objects.
diff --git a/tester/rt/run.py b/tester/rt/run.py
index 1f4fa3a..ff95091 100644
--- a/tester/rt/run.py
+++ b/tester/rt/run.py
@@ -32,12 +32,8 @@ from __future__ import print_function
 
 import copy
 import datetime
-import fnmatch
-import os
-import re
 import sys
 import threading
-import time
 
 from rtemstoolkit import error
 from rtemstoolkit import host
@@ -46,11 +42,11 @@ from rtemstoolkit import path
 from rtemstoolkit import stacktraces
 from rtemstoolkit import version
 
-from . import bsps
-from . import config
-from . import console
-from . import options
-from . import report
+import bsps
+import config
+import console
+import options
+import report
 
 class test(object):
     def __init__(self, index, total, report, executable, rtems_tools, bsp, bsp_config, opts):
@@ -98,8 +94,7 @@ def list_bsps(opts):
         log.notice('  %s' % (path.basename(bsp[:-3])))
     raise error.exit()
 
-def run(command_path = None):
-    import sys
+def run(args, command_path = None):
     tests = []
     stdtty = console.save()
     opts = None
@@ -111,7 +106,7 @@ def run(command_path = None):
                     '--list-bsps':   'List the supported BSPs',
                     '--debug-trace': 'Debug trace based on specific flags',
                     '--stacktrace':  'Dump a stack trace on a user termination (^C)' }
-        opts = options.load(sys.argv,
+        opts = options.load(args,
                             optargs = optargs,
                             command_path = command_path)
         log.notice('RTEMS Testing - Run, %s' % (version.string()))
diff --git a/tester/rt/test.py b/tester/rt/test.py
index c5d61d8..13c1e6e 100644
--- a/tester/rt/test.py
+++ b/tester/rt/test.py
@@ -50,12 +50,12 @@ from rtemstoolkit import stacktraces
 from rtemstoolkit import version
 from rtemstoolkit import check
 
-from . import bsps
-from . import config
-from . import console
-from . import options
-from . import report
-from . import coverage
+import bsps
+import config
+import console
+import options
+import report
+import coverage
 
 class log_capture(object):
     def __init__(self):
@@ -216,7 +216,7 @@ def killall(tests):
     for test in tests:
         test.kill()
 
-def run(command_path = None):
+def run(args, command_path = None):
     import sys
     tests = []
     stdtty = console.save()
@@ -234,7 +234,7 @@ def run(command_path = None):
                     '--stacktrace':     'Dump a stack trace on a user termination (^C)',
                     '--coverage':       'Perform coverage analysis of test executables.'}
         mailer.append_options(optargs)
-        opts = options.load(sys.argv,
+        opts = options.load(args,
                             optargs = optargs,
                             command_path = command_path)
         mail = None
diff --git a/tester/rt/tftp.py b/tester/rt/tftp.py
index 243f9b3..52deabc 100644
--- a/tester/rt/tftp.py
+++ b/tester/rt/tftp.py
@@ -43,14 +43,7 @@ import sys
 from rtemstoolkit import error
 from rtemstoolkit import reraise
 
-#
-# 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 tftpy
-except (ValueError, SystemError):
-    import tftpy
+import tftpy
 
 class tftp(object):
     '''RTEMS Testing TFTP base.'''
diff --git a/tester/rtems-bsp-builder b/tester/rtems-bsp-builder
index ee5a62f..4901ff0 100755
--- a/tester/rtems-bsp-builder
+++ b/tester/rtems-bsp-builder
@@ -1,7 +1,7 @@
-#! /usr/bin/env python
+#! /bin/sh
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2016 Chris Johns (chrisj at rtems.org)
+# Copyright 2018 Chris Johns (chrisj at rtems.org)
 # All rights reserved.
 #
 # This file is part of the RTEMS Tools package in 'rtems-tools'.
@@ -28,16 +28,15 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 #
-
-import sys, os
-base = os.path.dirname(os.path.abspath(sys.argv[0]))
-parent = os.path.dirname(base)
-rtems = os.path.join(parent, 'share', 'rtems')
-sys.path = [parent, rtems, os.path.join(rtems, 'tester')] + sys.path
-
-try:
-    import rt.check
-    rt.check.run()
-except ImportError:
-    print >> sys.stderr, "Incorrect RTEMS Tools installation"
-    sys.exit(1)
+set -e
+base=$(dirname $(dirname $0))
+cmd=tester/rt/cmd-bsp-builder.py
+PYTHON_WRAPPER=rtemstoolkit/python-wrapper.sh
+if test -f ${base}/${PYTHON_WRAPPER}; then
+  PYTHON_CMD=${base}/${cmd}
+  . ${base}/${PYTHON_WRAPPER}
+elif test -f ${base}/share/rtems/${PYTHON_WRAPPER}; then
+  PYTHON_CMD=${base}/share/rtems/${cmd}
+  . ${base}/share/rtems/${PYTHON_WRAPPER}
+fi
+echo "error: RTEMS Toolkit python wrapper not found, plrease report"
diff --git a/tester/rtems-run b/tester/rtems-run
index d6f2f56..cf5f263 100755
--- a/tester/rtems-run
+++ b/tester/rtems-run
@@ -1,7 +1,7 @@
-#! /usr/bin/env python
+#! /bin/sh
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2017 Chris Johns (chrisj at rtems.org)
+# Copyright 2018 Chris Johns (chrisj at rtems.org)
 # All rights reserved.
 #
 # This file is part of the RTEMS Tools package in 'rtems-tools'.
@@ -28,16 +28,15 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 #
-
-import sys, os
-base = os.path.dirname(os.path.abspath(sys.argv[0]))
-parent = os.path.dirname(base)
-rtems = os.path.join(parent, 'share', 'rtems')
-sys.path = [parent, rtems, os.path.join(rtems, 'tester')] + sys.path
-
-try:
-    import rt.run
-    rt.run.run()
-except ImportError:
-    print >> sys.stderr, "Incorrect RTEMS Tools installation"
-    sys.exit(1)
+set -e
+base=$(dirname $(dirname $0))
+cmd=tester/rt/cmd-run.py
+PYTHON_WRAPPER=rtemstoolkit/python-wrapper.sh
+if test -f ${base}/${PYTHON_WRAPPER}; then
+  PYTHON_CMD=${base}/${cmd}
+  . ${base}/${PYTHON_WRAPPER}
+elif test -f ${base}/share/rtems/${PYTHON_WRAPPER}; then
+  PYTHON_CMD=${base}/share/rtems/${cmd}
+  . ${base}/share/rtems/${PYTHON_WRAPPER}
+fi
+echo "error: RTEMS Toolkit python wrapper not found, plrease report"
diff --git a/tester/rtems-test b/tester/rtems-test
index f573fea..3eb5701 100755
--- a/tester/rtems-test
+++ b/tester/rtems-test
@@ -1,7 +1,7 @@
-#! /usr/bin/env python
+#! /bin/sh
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2013, 2015 Chris Johns (chrisj at rtems.org)
+# Copyright 2018 Chris Johns (chrisj at rtems.org)
 # All rights reserved.
 #
 # This file is part of the RTEMS Tools package in 'rtems-tools'.
@@ -28,16 +28,15 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 #
-
-import sys, os
-base = os.path.dirname(os.path.abspath(sys.argv[0]))
-parent = os.path.dirname(base)
-rtems = os.path.join(parent, 'share', 'rtems')
-sys.path = [parent, rtems, os.path.join(rtems, 'tester')] + sys.path
-
-try:
-    import rt.test
-    rt.test.run()
-except ImportError:
-    print >> sys.stderr, "Incorrect RTEMS Tools installation"
-    sys.exit(1)
+set -e
+base=$(dirname $(dirname $0))
+cmd=tester/rt/cmd-test.py
+PYTHON_WRAPPER=rtemstoolkit/python-wrapper.sh
+if test -f ${base}/${PYTHON_WRAPPER}; then
+  PYTHON_CMD=${base}/${cmd}
+  . ${base}/${PYTHON_WRAPPER}
+elif test -f ${base}/share/rtems/${PYTHON_WRAPPER}; then
+  PYTHON_CMD=${base}/share/rtems/${cmd}
+  . ${base}/share/rtems/${PYTHON_WRAPPER}
+fi
+echo "error: RTEMS Toolkit python wrapper not found, plrease report"
diff --git a/tester/wscript b/tester/wscript
index 76cf79d..e923347 100644
--- a/tester/wscript
+++ b/tester/wscript
@@ -54,6 +54,9 @@ def build(bld):
         source = ['rt/__init__.py',
                   'rt/bsps.py',
                   'rt/check.py',
+                  'rt/cmd-bsp-builder.py',
+                  'rt/cmd-run.py',
+                  'rt/cmd-test.py',
                   'rt/config.py',
                   'rt/console.py',
                   'rt/coverage.py',
-- 
2.14.1



More information about the devel mailing list