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

4.104.115
Last change on this file since 50fdf12 was 50fdf12, checked in by Chris Johns <chrisj@…>, on 02/14/14 at 19:30:06

rt: Add the rtems-tester.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2013-2014 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
51class command_line(options.command_line):
52    """Process the command line in a common way for all Tool Builder commands."""
53
54    def __init__(self, argv = None, optargs = None, defaults = None, command_path = None):
55        if argv is None:
56            return
57        long_opts = {
58            # key             macro            handler      param  defs   init
59            '--target'     : ('_target',       "triplet",   True,  None,  False),
60            '--timeout'    : ('timeout',       "int",       True,  None,  False),
61        }
62        long_opts_help = {
63            '--target': 'Set the target triplet',
64            '--timeout': 'Set the test timeout in seconds (default 180 seconds)'
65        }
66        super(command_line, self).__init__('rt', argv, optargs, defaults,
67                                           long_opts, long_opts_help, command_path);
68
69    def __copy__(self):
70        return super(command_line, self).__copy__()
71
72def load(args, optargs = None,
73         command_path = None,
74         defaults = '%{_rtdir}/rtems/testing/defaults.mc'):
75    #
76    # The path to this command if not supplied by the upper layers.
77    #
78    if command_path is None:
79        command_path = path.dirname(args[0])
80        if len(command_path) == 0:
81            command_path = '.'
82    #
83    # The command line contains the base defaults object all build objects copy
84    # and modify by loading a configuration.
85    #
86    opts = command_line(args,
87                        optargs,
88                        macros.macros(name = defaults,
89                                      rtdir = command_path),
90                        command_path)
91    options.load(opts)
92    return opts
93
94def run(args):
95    try:
96        _opts = load(args = args, defaults = 'rtems/testing/defaults.mc')
97        log.notice('RTEMS Test - Defaults, v%s' % (version.str()))
98        _opts.log_info()
99        log.notice('Options:')
100        log.notice(str(_opts))
101        log.notice('Defaults:')
102        log.notice(str(_opts.defaults))
103    except error.general, gerr:
104        print gerr
105        sys.exit(1)
106    except error.internal, ierr:
107        print ierr
108        sys.exit(1)
109    except error.exit, eerr:
110        pass
111    except KeyboardInterrupt:
112        log.notice('abort: user terminated')
113        sys.exit(1)
114    sys.exit(0)
115
116if __name__ == '__main__':
117    import sys
118    run(sys.argv)
Note: See TracBrowser for help on using the repository browser.