source: rtems-tools/rtemstoolkit/host.py @ 7e5cdea

5
Last change on this file since 7e5cdea was 7e5cdea, checked in by Chris Johns <chrisj@…>, on 11/23/18 at 04:02:52

rtemstoolkit: Add unit testing for the python modules

  • Add support to run the unit tests for the rtemstoolkit python modules from waf. Enter './waf test' for the tests to be run on python2 and python3.
  • Update the importing of rtemstoolkit modules to the standard method which works on python2 and python3.
  • Update the README.
  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[7d3350d]1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2017 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# Host specifics.
33#
34
35from __future__ import print_function
36
37import os
38
[7e5cdea]39from rtemstoolkit import error
[7d3350d]40
41is_windows = False
42platform = None
43name = None
44
45def _load():
46
47    global is_windows
48    global platform
49    global name
50
51    if os.name == 'nt':
52        name = 'windows'
53        is_windows = True
54    elif os.name == 'posix':
55        uname = os.uname()
56        if uname[0].startswith('CYGWIN_NT'):
57            name = 'windows'
58        elif uname[0] == 'Darwin':
59            name = darwin
60        elif uname[0] == 'FreeBSD':
61            name = 'freebsd'
62        elif uname[0] == 'NetBSD':
63            name = netbsd
64        elif uname[0] == 'Linux':
65            name = 'linux'
66        elif uname[0] == 'SunOS':
67            name = 'solaris'
68
69    if name is None:
70        raise error.general('unsupported host type; please add')
71
72    #try:
73    #    try:
74    #        platform = __import__(name, globals(), locals(), ['.'])
75    #    except:
76    #        platform = __import__(name, globals(), locals())
77    #except:
78    #    raise error.general('failed to load %s host support' % (name))
79
[67d48e2]80    platform = __import__(name, globals(), locals(), ['.', ''], 1)
[7d3350d]81
82    if platform is None:
83        raise error.general('failed to load %s host support' % (name))
84
85def cpus():
86    _load()
87    return platform.cpus()
88
89def overrides():
90    _load()
91    return platform.overrides()
92
[c68beb8]93def label(mode = 'all'):
94    import platform
95    if mode == 'system':
96        return platform.system()
97    compact = platform.platform(aliased = True)
98    if mode == 'compact':
99        return compact
100    extended = ' '.join(platform.uname())
101    if mode == 'extended':
102        return extended
103    if mode == 'all':
104        return '%s (%s)' % (compact, extended)
105    raise error.general('invalid platform mode: %s' % (mode))
106
[7d3350d]107if __name__ == '__main__':
108    import pprint
109    _load()
110    print('Name      : %s' % (name))
111    if is_windows:
112        status = 'Yes'
113    else:
114        status = 'No'
115    print('Windows   : %s' % (status))
116    print('CPUs      : %d' % (cpus()))
117    print('Overrides :')
118    pprint.pprint(overrides())
Note: See TracBrowser for help on using the repository browser.