source: rtems-tools/rtemstoolkit/host.py @ 37a0843

5
Last change on this file since 37a0843 was 7d3350d, checked in by Chris Johns <chrisj@…>, on 04/24/17 at 14:31:44

rtemstoolkit: Move host support access into a separate module.

Moving the host support into a module lets it get used where options
is not being used.

  • Property mode set to 100644
File size: 3.2 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(), ['.', ''])
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
100if __name__ == '__main__':
101    import pprint
102    _load()
103    print('Name      : %s' % (name))
104    if is_windows:
105        status = 'Yes'
106    else:
107        status = 'No'
108    print('Windows   : %s' % (status))
109    print('CPUs      : %d' % (cpus()))
110    print('Overrides :')
111    pprint.pprint(overrides())
Note: See TracBrowser for help on using the repository browser.