source: rtems-tools/rtemstoolkit/host.py @ 3618a62

Last change on this file since 3618a62 was c68beb8, checked in by Chris Johns <chrisj@…>, on Nov 3, 2017 at 6:57:37 AM

tester: Add the rtems-run command.

  • Property mode set to 100644
File size: 3.7 KB
Line 
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
39#
40# Support to handle use in a package and as a unit test.
41# If there is a better way to let us know.
42#
43try:
44    from . import error
45except (ValueError, SystemError):
46    import error
47
48is_windows = False
49platform = None
50name = None
51
52def _load():
53
54    global is_windows
55    global platform
56    global name
57
58    if os.name == 'nt':
59        name = 'windows'
60        is_windows = True
61    elif os.name == 'posix':
62        uname = os.uname()
63        if uname[0].startswith('CYGWIN_NT'):
64            name = 'windows'
65        elif uname[0] == 'Darwin':
66            name = darwin
67        elif uname[0] == 'FreeBSD':
68            name = 'freebsd'
69        elif uname[0] == 'NetBSD':
70            name = netbsd
71        elif uname[0] == 'Linux':
72            name = 'linux'
73        elif uname[0] == 'SunOS':
74            name = 'solaris'
75
76    if name is None:
77        raise error.general('unsupported host type; please add')
78
79    #try:
80    #    try:
81    #        platform = __import__(name, globals(), locals(), ['.'])
82    #    except:
83    #        platform = __import__(name, globals(), locals())
84    #except:
85    #    raise error.general('failed to load %s host support' % (name))
86
87    platform = __import__(name, globals(), locals(), ['.', ''], 1)
88
89    if platform is None:
90        raise error.general('failed to load %s host support' % (name))
91
92def cpus():
93    _load()
94    return platform.cpus()
95
96def overrides():
97    _load()
98    return platform.overrides()
99
100def label(mode = 'all'):
101    import platform
102    if mode == 'system':
103        return platform.system()
104    compact = platform.platform(aliased = True)
105    if mode == 'compact':
106        return compact
107    extended = ' '.join(platform.uname())
108    if mode == 'extended':
109        return extended
110    if mode == 'all':
111        return '%s (%s)' % (compact, extended)
112    raise error.general('invalid platform mode: %s' % (mode))
113
114if __name__ == '__main__':
115    import pprint
116    pprint.pprint(platform())
117    _load()
118    print('Name      : %s' % (name))
119    if is_windows:
120        status = 'Yes'
121    else:
122        status = 'No'
123    print('Windows   : %s' % (status))
124    print('CPUs      : %d' % (cpus()))
125    print('Overrides :')
126    pprint.pprint(overrides())
Note: See TracBrowser for help on using the repository browser.