| OLD | NEW |
| 1 # Copyright (c) 2011 Google Inc. All rights reserved. | 1 # Copyright (c) 2011 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 self._platform_module = platform_module | 49 self._platform_module = platform_module |
| 50 self.os_name = self._determine_os_name(sys_module.platform) | 50 self.os_name = self._determine_os_name(sys_module.platform) |
| 51 if self.os_name == 'linux': | 51 if self.os_name == 'linux': |
| 52 self.os_version = self._determine_linux_version(platform_module) | 52 self.os_version = self._determine_linux_version(platform_module) |
| 53 if self.os_name == 'freebsd': | 53 if self.os_name == 'freebsd': |
| 54 self.os_version = platform_module.release() | 54 self.os_version = platform_module.release() |
| 55 if self.os_name.startswith('mac'): | 55 if self.os_name.startswith('mac'): |
| 56 self.os_version = self._determine_mac_version(platform_module.mac_ve
r()[0]) | 56 self.os_version = self._determine_mac_version(platform_module.mac_ve
r()[0]) |
| 57 if self.os_name.startswith('win'): | 57 if self.os_name.startswith('win'): |
| 58 self.os_version = self._determine_win_version(self._win_version_tupl
e(sys_module)) | 58 self.os_version = self._determine_win_version(self._win_version_tupl
e(sys_module)) |
| 59 self._is_cygwin = sys_module.platform == 'cygwin' | 59 assert sys.platform != 'cygwin', 'Cygwin is not supported.' |
| 60 | 60 |
| 61 def is_mac(self): | 61 def is_mac(self): |
| 62 return self.os_name == 'mac' | 62 return self.os_name == 'mac' |
| 63 | 63 |
| 64 def is_win(self): | 64 def is_win(self): |
| 65 return self.os_name == 'win' | 65 return self.os_name == 'win' |
| 66 | 66 |
| 67 def is_cygwin(self): | |
| 68 return self._is_cygwin | |
| 69 | |
| 70 def is_linux(self): | 67 def is_linux(self): |
| 71 return self.os_name == 'linux' | 68 return self.os_name == 'linux' |
| 72 | 69 |
| 73 def is_freebsd(self): | 70 def is_freebsd(self): |
| 74 return self.os_name == 'freebsd' | 71 return self.os_name == 'freebsd' |
| 75 | 72 |
| 76 def is_highdpi(self): | 73 def is_highdpi(self): |
| 77 if self.is_mac(): | 74 if self.is_mac(): |
| 78 output = self._executive.run_command(['system_profiler', 'SPDisplays
DataType'], | 75 output = self._executive.run_command(['system_profiler', 'SPDisplays
DataType'], |
| 79 error_handler=self._executive.i
gnore_error) | 76 error_handler=self._executive.i
gnore_error) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 if self._filesystem.exists('/etc/arch-release'): | 129 if self._filesystem.exists('/etc/arch-release'): |
| 133 return 'arch' | 130 return 'arch' |
| 134 | 131 |
| 135 return 'unknown' | 132 return 'unknown' |
| 136 | 133 |
| 137 def _determine_os_name(self, sys_platform): | 134 def _determine_os_name(self, sys_platform): |
| 138 if sys_platform == 'darwin': | 135 if sys_platform == 'darwin': |
| 139 return 'mac' | 136 return 'mac' |
| 140 if sys_platform.startswith('linux'): | 137 if sys_platform.startswith('linux'): |
| 141 return 'linux' | 138 return 'linux' |
| 142 if sys_platform in ('win32', 'cygwin'): | 139 if sys_platform == 'win32': |
| 143 return 'win' | 140 return 'win' |
| 144 if sys_platform.startswith('freebsd'): | 141 if sys_platform.startswith('freebsd'): |
| 145 return 'freebsd' | 142 return 'freebsd' |
| 146 raise AssertionError('unrecognized platform string "%s"' % sys_platform) | 143 raise AssertionError('unrecognized platform string "%s"' % sys_platform) |
| 147 | 144 |
| 148 def _determine_mac_version(self, mac_version_string): | 145 def _determine_mac_version(self, mac_version_string): |
| 149 minor_release = int(mac_version_string.split('.')[1]) | 146 minor_release = int(mac_version_string.split('.')[1]) |
| 150 assert minor_release >= 9, 'Unsupported mac OS version: %s' % mac_versio
n_string | 147 assert minor_release >= 9, 'Unsupported mac OS version: %s' % mac_versio
n_string |
| 151 if minor_release <= 12: | 148 if minor_release <= 12: |
| 152 return 'mac10.%d' % minor_release | 149 return 'mac10.%d' % minor_release |
| (...skipping 27 matching lines...) Expand all Loading... |
| 180 if hasattr(sys_module, 'getwindowsversion'): | 177 if hasattr(sys_module, 'getwindowsversion'): |
| 181 return sys_module.getwindowsversion() | 178 return sys_module.getwindowsversion() |
| 182 return self._win_version_tuple_from_cmd() | 179 return self._win_version_tuple_from_cmd() |
| 183 | 180 |
| 184 def _win_version_tuple_from_cmd(self): | 181 def _win_version_tuple_from_cmd(self): |
| 185 # Note that this should only ever be called on windows, so this should a
lways work. | 182 # Note that this should only ever be called on windows, so this should a
lways work. |
| 186 ver_output = self._executive.run_command(['cmd', '/c', 'ver'], decode_ou
tput=False) | 183 ver_output = self._executive.run_command(['cmd', '/c', 'ver'], decode_ou
tput=False) |
| 187 match_object = re.search(r'(?P<major>\d+)\.(?P<minor>\d)\.(?P<build>\d+)
', ver_output) | 184 match_object = re.search(r'(?P<major>\d+)\.(?P<minor>\d)\.(?P<build>\d+)
', ver_output) |
| 188 assert match_object, 'cmd returned an unexpected version string: ' + ver
_output | 185 assert match_object, 'cmd returned an unexpected version string: ' + ver
_output |
| 189 return tuple(map(int, match_object.groups())) | 186 return tuple(map(int, match_object.groups())) |
| OLD | NEW |