source: rtems-tools/tester/rt/options.py @ 0e5d89d

4.105
Last change on this file since 0e5d89d was 04a5204, checked in by Sebastian Huber <sebastian.huber@…>, on 11/12/15 at 10:15:23

Python 3 compatibility

  • Property mode set to 100644
File size: 4.5 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2013-2015 Chris Johns (chrisj@rtems.org)
4# All rights reserved.
5#
6# This file is part of the RTEMS Tools package in 'rtems-tools'.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions are met:
10#
11# 1. Redistributions of source code must retain the above copyright notice,
12# this list of conditions and the following disclaimer.
13#
14# 2. Redistributions in binary form must reproduce the above copyright notice,
15# this list of conditions and the following disclaimer in the documentation
16# and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGE.
29#
30
31#
32# Determine the defaults and load the specific file.
33#
34
35import glob
36import pprint
37import re
38import os
39import string
40
41from rtemstoolkit import error
42from rtemstoolkit import execute
43from rtemstoolkit import git
44from rtemstoolkit import log
45from rtemstoolkit import macros
46from rtemstoolkit import options
47from rtemstoolkit import path
48
49import version
50
51#
52# The path for the defaults.
53#
54defaults_mc = 'rtems/testing/defaults.mc'
55
56class command_line(options.command_line):
57    """Process the command line in a common way for all Tool Builder commands."""
58
59    def __init__(self, argv = None, optargs = None, defaults = None, command_path = None):
60        if argv is None:
61            return
62        long_opts = {
63            # key             macro            handler      param  defs   init
64            '--target'     : ('_target',       "triplet",   True,  None,  False),
65            '--timeout'    : ('timeout',       "int",       True,  None,  False),
66        }
67        long_opts_help = {
68            '--target': 'Set the target triplet',
69            '--timeout': 'Set the test timeout in seconds (default 180 seconds)'
70        }
71        super(command_line, self).__init__('rt', argv, optargs, defaults,
72                                           long_opts, long_opts_help, command_path);
73
74    def __copy__(self):
75        return super(command_line, self).__copy__()
76
77def load(args, optargs = None,
78         command_path = None,
79         defaults = '%s' % (defaults_mc)):
80    #
81    # The path to this command if not supplied by the upper layers.
82    #
83    if command_path is None:
84        command_path = path.dirname(args[0])
85        if len(command_path) == 0:
86            command_path = '.'
87    #
88    # Check if there is a defaults.mc file under the command path. If so this is
89    # the tester being run from within the git repo. If not found assume the tools
90    # have been installed and the defaults is in the install prefix.
91    #
92    if path.exists(path.join(command_path, defaults_mc)):
93        rtdir = command_path
94    else:
95        rtdir = '%{_prefix}/share/rtems/tester'
96    defaults = '%s/%s' % (rtdir, defaults_mc)
97    #
98    # The command line contains the base defaults object all build objects copy
99    # and modify by loading a configuration.
100    #
101    opts = command_line(args,
102                        optargs,
103                        macros.macros(name = defaults, rtdir = rtdir),
104                        command_path)
105    options.load(opts)
106    return opts
107
108def run(args):
109    try:
110        _opts = load(args = args, defaults = defaults_mc)
111        log.notice('RTEMS Test - Defaults, v%s' % (version.str()))
112        _opts.log_info()
113        log.notice('Options:')
114        log.notice(str(_opts))
115        log.notice('Defaults:')
116        log.notice(str(_opts.defaults))
117    except error.general as gerr:
118        print(gerr)
119        sys.exit(1)
120    except error.internal as ierr:
121        print(ierr)
122        sys.exit(1)
123    except error.exit:
124        pass
125    except KeyboardInterrupt:
126        log.notice('abort: user terminated')
127        sys.exit(1)
128    sys.exit(0)
129
130if __name__ == '__main__':
131    import sys
132    run(sys.argv)
Note: See TracBrowser for help on using the repository browser.