From 31cf4bd00fe00066ac4a49ddccb947f916013b97 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 1 Jan 2013 08:27:15 -0500 Subject: [PATCH] swc-installation-test-2.py: Add OS-version detection Using assorted functions from the `platform` module. On my Linux box: $ python2.7 Python 2.7.3 (default, Dec 5 2012, 10:56:01) [GCC 4.5.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import platform >>> platform.linux_distribution() ('Gentoo Base System', '2.1', '') >>> platform.mac_ver() ('', ('', '', ''), '') >>> platform.win32_ver() ('', '', '', '') On an OS X box: $ python2.6 Python 2.6.1 (r261:67515, Aug 2 2010, 20:10:18) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import platform >>> platform.linux_distribution() ('', '', '') >>> platform.mac_ver() ('10.6.8', ('', '', ''), 'i386') >>> platform.win32_ver() ('', '', '', '') I don't have access to an MS Windows box, but presumably it returns something like: >>> platform.linux_distribution() ('', '', '') >>> platform.mac_ver() ('', ('', '', ''), '') >>> platform.win32_ver() ('XP', '5.1.2600', 'SP2', 'Multiprocessor Free') We only want to print the one that applies (e.g. don't print a 'linux_distribution' entry on OS X), so we skip entries where value[0] is an empty string. --- swc-installation-test-2.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index f0ec903..373230d 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -471,7 +471,7 @@ for name,dependencies in [ del name, dependencies # cleanup namespace -def _print_info(key, value, indent=13): +def _print_info(key, value, indent=19): print('{0}{1}: {2}'.format(key, ' '*(indent-len(key)), value)) def print_system_info(): @@ -486,6 +486,14 @@ def print_system_info(): _print_info('os.uname', _platform.uname()) _print_info('platform', _sys.platform) _print_info('platform+', _platform.platform()) + for pversion in ( + 'linux_distribution', + 'mac_ver', + 'win32_ver', + ): + value = getattr(_platform, pversion)() + if value[0]: + _print_info(pversion, value) _print_info('prefix', _sys.prefix) _print_info('exec_prefix', _sys.exec_prefix) _print_info('executable', _sys.executable) -- 2.26.2