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

4.10
Last change on this file since b0fa2ae was b0fa2ae, checked in by Chris Johns <chrisj@…>, on Mar 3, 2016 at 5:46:18 AM

Update rtems-tool to support Python 2 and 3.

Add solaris and netbsd.

Close #2619.

  • Property mode set to 100644
File size: 4.6 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
35from __future__ import print_function
36
37import glob
38import pprint
39import re
40import os
41import string
42
43from rtemstoolkit import error
44from rtemstoolkit import execute
45from rtemstoolkit import git
46from rtemstoolkit import log
47from rtemstoolkit import macros
48from rtemstoolkit import options
49from rtemstoolkit import path
50from rtemstoolkit import version
51
52#
53# The path for the defaults.
54#
55defaults_mc = 'rtems/testing/defaults.mc'
56
57class command_line(options.command_line):
58    """Process the command line in a common way for all Tool Builder commands."""
59
60    def __init__(self, argv = None, optargs = None, defaults = None, command_path = None):
61        if argv is None:
62            return
63        long_opts = {
64            # key             macro            handler      param  defs   init
65            '--target'     : ('_target',       "triplet",   True,  None,  False),
66            '--timeout'    : ('timeout',       "int",       True,  None,  False),
67        }
68        long_opts_help = {
69            '--target': 'Set the target triplet',
70            '--timeout': 'Set the test timeout in seconds (default 180 seconds)'
71        }
72        super(command_line, self).__init__('rt', argv, optargs, defaults,
73                                           long_opts, long_opts_help, command_path);
74
75    def __copy__(self):
76        return super(command_line, self).__copy__()
77
78def load(args, optargs = None,
79         command_path = None,
80         defaults = '%s' % (defaults_mc)):
81    #
82    # The path to this command if not supplied by the upper layers.
83    #
84    if command_path is None:
85        command_path = path.dirname(args[0])
86        if len(command_path) == 0:
87            command_path = '.'
88    #
89    # Check if there is a defaults.mc file under the command path. If so this is
90    # the tester being run from within the git repo. If not found assume the tools
91    # have been installed and the defaults is in the install prefix.
92    #
93    if path.exists(path.join(command_path, defaults_mc)):
94        rtdir = command_path
95    else:
96        rtdir = '%{_prefix}/share/rtems/tester'
97    defaults = '%s/%s' % (rtdir, defaults_mc)
98    #
99    # The command line contains the base defaults object all build objects copy
100    # and modify by loading a configuration.
101    #
102    opts = command_line(args,
103                        optargs,
104                        macros.macros(name = defaults, rtdir = rtdir),
105                        command_path)
106    options.load(opts)
107    return opts
108
109def run(args):
110    try:
111        _opts = load(args = args, defaults = defaults_mc)
112        log.notice('RTEMS Test - Defaults, v%s' % (version.str()))
113        _opts.log_info()
114        log.notice('Options:')
115        log.notice(str(_opts))
116        log.notice('Defaults:')
117        log.notice(str(_opts.defaults))
118    except error.general as gerr:
119        print(gerr, file = sys.stderr)
120        sys.exit(1)
121    except error.internal as ierr:
122        print(ierr, file = sys.stderr)
123        sys.exit(1)
124    except error.exit:
125        pass
126    except KeyboardInterrupt:
127        log.notice('abort: user terminated')
128        sys.exit(1)
129    sys.exit(0)
130
131if __name__ == '__main__':
132    import sys
133    run(sys.argv)
Note: See TracBrowser for help on using the repository browser.