Changeset e058db0 in rtems-tools


Ignore:
Timestamp:
Nov 7, 2018, 3:55:20 AM (5 months ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
f24e116
Parents:
087be8c
git-author:
Chris Johns <chrisj@…> (11/07/18 03:55:20)
git-committer:
Chris Johns <chrisj@…> (11/08/18 07:13:45)
Message:

python: Provide support to select a valid python version.

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

Closes #3537

Files:
4 added
17 edited

Legend:

Unmodified
Added
Removed
  • rtemstoolkit/configuration.py

    r087be8c re058db0  
    3838import re
    3939
    40 try:
    41     import configparser
    42 except:
    43     import ConfigParser as configparser
    44 
    4540from rtemstoolkit import error
    4641from rtemstoolkit import path
     
    4843class configuration:
    4944
    50     def __init__(self):
    51         self.config = configparser.ConfigParser()
     45    def __init__(self, raw = True):
     46        self.raw = True
     47        try:
     48            import configparser
     49            self.config = configparser.ConfigParser(strict = False)
     50        except:
     51            # python2
     52            import ConfigParser as configparser
     53            self.config = configparser.ConfigParser()
    5254        self.ini = None
    5355        self.macro_filter = re.compile('\$\{.+\}')
     
    6769            s += [' [%s]' % (section)]
    6870            for option in self.config.options(section):
    69                 s += ['  %s = %s' % (option, self.config.get(section, option))]
     71                s += ['  %s = %s' % (option,
     72                                     self.config.get(section,
     73                                                     option,
     74                                                     raw = self.raw))]
    7075        return os.linesep.join(s)
    7176
    7277    def get_item(self, section, label, err = True):
    7378        try:
    74             rec = self.config.get(section, label).replace(os.linesep, ' ')
     79            rec = self.config.get(section, label, raw = self.raw).replace(os.linesep, ' ')
    7580        except:
    7681            if err:
     
    9095            try:
    9196                ref = self.config.get(section_value[0],
    92                                       section_value[1]).replace(os.linesep, ' ')
     97                                      section_value[1],
     98                                      raw = self.raw).replace(os.linesep, ' ')
    9399                rec = rec.replace(m, ref)
    94100            except:
     
    99105        try:
    100106            items = []
    101             for name, key in self.config.items(section):
     107            for name, key in self.config.items(section, raw = self.raw):
    102108                if flatten:
    103109                    items += [(name, key.replace(os.linesep, ' '))]
     
    118124    def get_item_names(self, section, err = True):
    119125        try:
    120             return [item[0] for item in self.config.items(section)]
     126            return [item[0] for item in self.config.items(section, raw = self.raw)]
    121127        except:
    122128            if err:
  • rtemstoolkit/log.py

    r087be8c re058db0  
    7979    if type(text) is list:
    8080        text = os.linesep.join(text) + os.linesep
     81    if isinstance(text, bytes):
     82        text = text.decode('utf-8', 'ignore')
    8183    if log:
    8284        log.output(text)
     
    176178        self._tail(text)
    177179        out = os.linesep.join(text) + os.linesep
     180        if isinstance(out, bytes):
     181            out = out.decode('utf-8', 'ignore')
    178182        self.lock.acquire()
    179183        try:
  • rtemstoolkit/rtems.py

    r087be8c re058db0  
    6363            os.environ['PATH'] = os.pathsep.join(cspath[1:])
    6464
    65 def configuration_path():
     65def configuration_path(prog = None):
    6666    '''Return the path the configuration data path for RTEMS. The path is relative
    6767    to the installed executable. Mangage the installed package and the in source
    6868    tree when running from within the rtems-tools repo.
    69 
     69    Note:
     70     1. This code assumes the executable is wrapped and not using 'env'.
     71     2. Ok to directly call os.path.
    7072    '''
    71     exec_name = os.path.abspath(sys.argv[0])
    72     for top in [os.path.dirname(exec_name),
    73                 os.path.dirname(os.path.dirname(exec_name))]:
     73    if prog is None:
     74        exec_name = sys.argv[1]
     75    else:
     76        exec_name = prog
     77    exec_name = os.path.abspath(exec_name)
     78    for top in [os.path.dirname(os.path.dirname(exec_name)),
     79                os.path.dirname(exec_name)]:
    7480        config_path = path.join(top, 'share', 'rtems', 'config')
    7581        if path.exists(config_path):
     
    8187    return config_path
    8288
    83 def configuration_file(config):
     89def configuration_file(config, prog = None):
    8490    '''Return the path to a configuration file for RTEMS. The path is relative to
    8591    the installed executable or we are testing and running from within the
     
    8793
    8894    '''
    89     return path.join(configuration_path(), config)
    90 
    91 def bsp_configuration_file():
     95    return path.join(configuration_path(prog = prog), config)
     96
     97def bsp_configuration_file(prog = None):
    9298    '''Return the path to the BSP configuration file for RTEMS. The path is
    9399    relative to the installed executable or we are testing and running from
     
    95101
    96102    '''
    97     return configuration_file('rtems-bsps.ini')
     103    return configuration_file('rtems-bsps.ini', prog = prog)
    98104
    99105class configuration:
     
    228234
    229235    def archs(self):
    230         return sorted(self.archs.keys())
     236        return sorted(list(self.archs.keys()))
    231237
    232238    def arch_present(self, arch):
     
    234240
    235241    def arch_excludes(self, arch):
    236         excludes = self.archs[arch]['excludes'].keys()
     242        excludes = list(self.archs[arch]['excludes'].keys())
    237243        for exclude in self.archs[arch]['excludes']:
    238244            if 'all' not in self.archs[arch]['excludes'][exclude]:
     
    247253
    248254    def bsp_excludes(self, arch, bsp):
    249         excludes = self.archs[arch]['excludes'].keys()
     255        excludes = list(self.archs[arch]['excludes'].keys())
    250256        for exclude in self.archs[arch]['excludes']:
    251257            if 'all' not in self.archs[arch]['excludes'][exclude] and \
     
    363369        if architectures:
    364370            s += textbox.line(cols_1, line = '=', marker = '+', indent = 1)
    365             archs = sorted(self.archs.keys())
     371            archs = sorted(list(self.archs.keys()))
    366372            bsps = 0
    367373            asize = 0
  • rtemstoolkit/wscript

    r087be8c re058db0  
    156156        install_from = '.',
    157157        install_path = '${PREFIX}/share/rtems/rtemstoolkit')
     158    bld.install_files('${PREFIX}/share/rtems/rtemstoolkit',
     159                      'python-wrapper.sh',
     160                      relative_trick = True)
    158161
    159162def rebuild(ctx):
  • tester/rt/check.py

    r087be8c re058db0  
    972972        for c in cmds:
    973973            c = c.replace('@PREFIX@', self.prefix)
    974             c = c.replace('@RTEMS_VERSION@', self.rtems_version)
     974            c = c.replace('@RTEMS_VERSION@', str(self.rtems_version))
    975975            c = c.replace('@ARCH@', build.arch)
    976976            c = c.replace('@BSP@', build.bsp)
     
    11191119        self.run_jobs(self.profile_jobs(profiles))
    11201120
    1121 def run_args(args):
     1121def run(args):
    11221122    b = None
    11231123    ec = 0
     
    11301130        build_dir = 'bsp-builds'
    11311131        logf = 'bsp-build-%s.txt' % (_now().strftime('%Y%m%d-%H%M%S'))
    1132         config_file = rtems.bsp_configuration_file()
    1133 
    1134         argsp = argparse.ArgumentParser()
     1132        config_file = rtems.bsp_configuration_file(prog = args[0])
     1133
     1134        description  = 'RTEMS BSP Builder is a BSP build tester. It builds BSPs '
     1135        description += 'in various ways to test build regressions in the kernel. You '
     1136        description += 'can build based on tier, architecture, or BSP. You can control '
     1137        description += 'the profile of build with various build configuration settings.'
     1138
     1139        argsp = argparse.ArgumentParser(prog = 'rtems-bsp-builder',
     1140                                        description = description)
    11351141        argsp.add_argument('--prefix', help = 'Prefix to build the BSP.',
    11361142                           type = str)
     
    12981304    sys.exit(ec)
    12991305
    1300 def run():
    1301     run_args(sys.argv)
    1302 
    13031306if __name__ == "__main__":
    1304     run()
     1307    run(sys.argv)
  • tester/rt/config.py

    r087be8c re058db0  
    4747from rtemstoolkit import path
    4848
    49 from . import console
    50 from . import gdb
    51 from . import tftp
     49import console
     50import gdb
     51import tftp
    5252
    5353timeout = 15
  • tester/rt/console.py

    r087be8c re058db0  
    4242from rtemstoolkit import path
    4343
    44 from . import telnet
     44import telnet
    4545
    4646#
     
    4848#
    4949if os.name != 'nt':
    50     from . import stty
     50    import stty
    5151else:
    5252    stty = None
     
    108108                try:
    109109                    data = me.tty.read()
     110                    if isinstance(data, bytes):
     111                        data = data.decode('utf-8', 'ignore')
     112                    data = [c for c in data if ord(c) < 128]
    110113                except IOError as ioe:
    111114                    if ioe.errno == errno.EAGAIN:
  • tester/rt/coverage.py

    r087be8c re058db0  
    4848
    4949
    50 from . import options
     50import options
    5151
    5252class summary:
  • tester/rt/gdb.py

    r087be8c re058db0  
    4949from rtemstoolkit import path
    5050
    51 #
    52 # Support to handle use in a package and as a unit test.
    53 # If there is a better way to let us know.
    54 #
    55 try:
    56     from . import console
    57     from . import pygdb
    58 except (ValueError, SystemError):
    59     import console
    60     import pygdb
     51import console
     52import pygdb
    6153
    6254#
  • tester/rt/run.py

    r087be8c re058db0  
    3333import copy
    3434import datetime
    35 import fnmatch
    36 import os
    37 import re
    3835import sys
    3936import threading
    40 import time
    4137
    4238from rtemstoolkit import error
     
    4743from rtemstoolkit import version
    4844
    49 from . import bsps
    50 from . import config
    51 from . import console
    52 from . import options
    53 from . import report
     45import bsps
     46import config
     47import console
     48import options
     49import report
    5450
    5551class test(object):
     
    9995    raise error.exit()
    10096
    101 def run(command_path = None):
    102     import sys
     97def run(args, command_path = None):
    10398    tests = []
    10499    stdtty = console.save()
     
    112107                    '--debug-trace': 'Debug trace based on specific flags',
    113108                    '--stacktrace':  'Dump a stack trace on a user termination (^C)' }
    114         opts = options.load(sys.argv,
     109        opts = options.load(args,
    115110                            optargs = optargs,
    116111                            command_path = command_path)
  • tester/rt/stty.py

    r087be8c re058db0  
    5959        termios.tcsetattr(sys.stderr, termios.TCSANOW, attributes[2])
    6060
    61 class tty:
     61class tty(object):
    6262
    6363    raw = 'B115200,~BRKINT,IGNBRK,IGNCR,~ICANON,~ISIG,~IEXTEN,~ECHO,CLOCAL,~CRTSCTS'
  • tester/rt/test.py

    r087be8c re058db0  
    5151from rtemstoolkit import check
    5252
    53 from . import bsps
    54 from . import config
    55 from . import console
    56 from . import options
    57 from . import report
    58 from . import coverage
     53import bsps
     54import config
     55import console
     56import options
     57import report
     58import coverage
    5959
    6060class log_capture(object):
     
    217217        test.kill()
    218218
    219 def run(command_path = None):
     219def run(args, command_path = None):
    220220    import sys
    221221    tests = []
     
    235235                    '--coverage':       'Perform coverage analysis of test executables.'}
    236236        mailer.append_options(optargs)
    237         opts = options.load(sys.argv,
     237        opts = options.load(args,
    238238                            optargs = optargs,
    239239                            command_path = command_path)
  • tester/rt/tftp.py

    r087be8c re058db0  
    4444from rtemstoolkit import reraise
    4545
    46 #
    47 # Support to handle use in a package and as a unit test.
    48 # If there is a better way to let us know.
    49 #
    50 try:
    51     from . import tftpy
    52 except (ValueError, SystemError):
    53     import tftpy
     46import tftpy
    5447
    5548class tftp(object):
  • tester/rtems-bsp-builder

    r087be8c re058db0  
    1 #! /usr/bin/env python
     1#! /bin/sh
    22#
    33# RTEMS Tools Project (http://www.rtems.org/)
    4 # Copyright 2016 Chris Johns (chrisj@rtems.org)
     4# Copyright 2018 Chris Johns (chrisj@rtems.org)
    55# All rights reserved.
    66#
     
    2929# POSSIBILITY OF SUCH DAMAGE.
    3030#
    31 
    32 import sys, os
    33 base = os.path.dirname(os.path.abspath(sys.argv[0]))
    34 parent = os.path.dirname(base)
    35 rtems = os.path.join(parent, 'share', 'rtems')
    36 sys.path = [parent, rtems, os.path.join(rtems, 'tester')] + sys.path
    37 
    38 try:
    39     import rt.check
    40     rt.check.run()
    41 except ImportError:
    42     print >> sys.stderr, "Incorrect RTEMS Tools installation"
    43     sys.exit(1)
     31set -e
     32base=$(dirname $(dirname $0))
     33cmd=tester/rt/cmd-bsp-builder.py
     34PYTHON_WRAPPER=rtemstoolkit/python-wrapper.sh
     35if test -f ${base}/${PYTHON_WRAPPER}; then
     36  PYTHON_CMD=${base}/${cmd}
     37  . ${base}/${PYTHON_WRAPPER}
     38elif test -f ${base}/share/rtems/${PYTHON_WRAPPER}; then
     39  PYTHON_CMD=${base}/share/rtems/${cmd}
     40  . ${base}/share/rtems/${PYTHON_WRAPPER}
     41fi
     42echo "error: RTEMS Toolkit python wrapper not found, plrease report"
  • tester/rtems-run

    r087be8c re058db0  
    1 #! /usr/bin/env python
     1#! /bin/sh
    22#
    33# RTEMS Tools Project (http://www.rtems.org/)
    4 # Copyright 2017 Chris Johns (chrisj@rtems.org)
     4# Copyright 2018 Chris Johns (chrisj@rtems.org)
    55# All rights reserved.
    66#
     
    2929# POSSIBILITY OF SUCH DAMAGE.
    3030#
    31 
    32 import sys, os
    33 base = os.path.dirname(os.path.abspath(sys.argv[0]))
    34 parent = os.path.dirname(base)
    35 rtems = os.path.join(parent, 'share', 'rtems')
    36 sys.path = [parent, rtems, os.path.join(rtems, 'tester')] + sys.path
    37 
    38 try:
    39     import rt.run
    40     rt.run.run()
    41 except ImportError:
    42     print >> sys.stderr, "Incorrect RTEMS Tools installation"
    43     sys.exit(1)
     31set -e
     32base=$(dirname $(dirname $0))
     33cmd=tester/rt/cmd-run.py
     34PYTHON_WRAPPER=rtemstoolkit/python-wrapper.sh
     35if test -f ${base}/${PYTHON_WRAPPER}; then
     36  PYTHON_CMD=${base}/${cmd}
     37  . ${base}/${PYTHON_WRAPPER}
     38elif test -f ${base}/share/rtems/${PYTHON_WRAPPER}; then
     39  PYTHON_CMD=${base}/share/rtems/${cmd}
     40  . ${base}/share/rtems/${PYTHON_WRAPPER}
     41fi
     42echo "error: RTEMS Toolkit python wrapper not found, plrease report"
  • tester/rtems-test

    r087be8c re058db0  
    1 #! /usr/bin/env python
     1#! /bin/sh
    22#
    33# RTEMS Tools Project (http://www.rtems.org/)
    4 # Copyright 2013, 2015 Chris Johns (chrisj@rtems.org)
     4# Copyright 2018 Chris Johns (chrisj@rtems.org)
    55# All rights reserved.
    66#
     
    2929# POSSIBILITY OF SUCH DAMAGE.
    3030#
    31 
    32 import sys, os
    33 base = os.path.dirname(os.path.abspath(sys.argv[0]))
    34 parent = os.path.dirname(base)
    35 rtems = os.path.join(parent, 'share', 'rtems')
    36 sys.path = [parent, rtems, os.path.join(rtems, 'tester')] + sys.path
    37 
    38 try:
    39     import rt.test
    40     rt.test.run()
    41 except ImportError:
    42     print >> sys.stderr, "Incorrect RTEMS Tools installation"
    43     sys.exit(1)
     31set -e
     32base=$(dirname $(dirname $0))
     33cmd=tester/rt/cmd-test.py
     34PYTHON_WRAPPER=rtemstoolkit/python-wrapper.sh
     35if test -f ${base}/${PYTHON_WRAPPER}; then
     36  PYTHON_CMD=${base}/${cmd}
     37  . ${base}/${PYTHON_WRAPPER}
     38elif test -f ${base}/share/rtems/${PYTHON_WRAPPER}; then
     39  PYTHON_CMD=${base}/share/rtems/${cmd}
     40  . ${base}/share/rtems/${PYTHON_WRAPPER}
     41fi
     42echo "error: RTEMS Toolkit python wrapper not found, plrease report"
  • tester/wscript

    r087be8c re058db0  
    5555                  'rt/bsps.py',
    5656                  'rt/check.py',
     57                  'rt/cmd-bsp-builder.py',
     58                  'rt/cmd-run.py',
     59                  'rt/cmd-test.py',
    5760                  'rt/config.py',
    5861                  'rt/console.py',
Note: See TracChangeset for help on using the changeset viewer.