[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 | |
---|
| 35 | from __future__ import print_function |
---|
| 36 | |
---|
| 37 | import os |
---|
| 38 | |
---|
[7e5cdea] | 39 | from rtemstoolkit import error |
---|
[7d3350d] | 40 | |
---|
| 41 | is_windows = False |
---|
| 42 | platform = None |
---|
| 43 | name = None |
---|
| 44 | |
---|
| 45 | def _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 | |
---|
| 85 | def cpus(): |
---|
| 86 | _load() |
---|
| 87 | return platform.cpus() |
---|
| 88 | |
---|
| 89 | def overrides(): |
---|
| 90 | _load() |
---|
| 91 | return platform.overrides() |
---|
| 92 | |
---|
[c68beb8] | 93 | def 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] | 107 | if __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()) |
---|