source: rtems-tools/rtemstoolkit/host.py @ 6d30de6

Last change on this file since 6d30de6 was 6d30de6, checked in by Chris Johns <chrisj@…>, on Nov 28, 2018 at 9:13:51 PM

rtemstoolkit: Fix unittests on Windows

  • Fix Windows host support so MSYS pythons can be used.
  • Fix Windows host support for python3.
  • Improve the mailer unittest.
  • Property mode set to 100644
File size: 3.6 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()
[6d30de6]56        if uname[0].startswith('MINGW64_NT') or uname[0].startswith('CYGWIN_NT'):
[7d3350d]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
[6d30de6]109    print('Python\'s OS name: %s' % (os.name))
[7d3350d]110    _load()
111    print('Name      : %s' % (name))
112    if is_windows:
113        status = 'Yes'
114    else:
115        status = 'No'
116    print('Windows   : %s' % (status))
117    print('CPUs      : %d' % (cpus()))
118    print('Overrides :')
119    pprint.pprint(overrides())
Note: See TracBrowser for help on using the repository browser.