| 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 13 matching lines...) Expand all Loading... |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 import re | 29 import re |
| 30 import sys | 30 import sys |
| 31 | 31 |
| 32 | 32 |
| 33 class PlatformInfo(object): | 33 class PlatformInfo(object): |
| 34 |
| 34 """This class provides a consistent (and mockable) interpretation of | 35 """This class provides a consistent (and mockable) interpretation of |
| 35 system-specific values (like sys.platform and platform.mac_ver()) | 36 system-specific values (like sys.platform and platform.mac_ver()) |
| 36 to be used by the rest of the webkitpy code base. | 37 to be used by the rest of the webkitpy code base. |
| 37 | 38 |
| 38 Public (static) properties: | 39 Public (static) properties: |
| 39 -- os_name | 40 -- os_name |
| 40 -- os_version | 41 -- os_version |
| 41 | 42 |
| 42 Note that 'future' is returned for os_version if the operating system is | 43 Note that 'future' is returned for os_version if the operating system is |
| 43 newer than one known to the code. | 44 newer than one known to the code. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 # From http://code.activestate.com/recipes/440694-determine-size
-of-console-window-on-windows/ | 104 # From http://code.activestate.com/recipes/440694-determine-size
-of-console-window-on-windows/ |
| 104 from ctypes import windll, create_string_buffer | 105 from ctypes import windll, create_string_buffer |
| 105 handle = windll.kernel32.GetStdHandle(-12) # -12 == stderr | 106 handle = windll.kernel32.GetStdHandle(-12) # -12 == stderr |
| 106 console_screen_buffer_info = create_string_buffer(22) # 22 == s
izeof(console_screen_buffer_info) | 107 console_screen_buffer_info = create_string_buffer(22) # 22 == s
izeof(console_screen_buffer_info) |
| 107 if windll.kernel32.GetConsoleScreenBufferInfo(handle, console_sc
reen_buffer_info): | 108 if windll.kernel32.GetConsoleScreenBufferInfo(handle, console_sc
reen_buffer_info): |
| 108 import struct | 109 import struct |
| 109 _, _, _, _, _, left, _, right, _, _, _ = struct.unpack("hhhh
Hhhhhhh", console_screen_buffer_info.raw) | 110 _, _, _, _, _, left, _, right, _, _, _ = struct.unpack("hhhh
Hhhhhhh", console_screen_buffer_info.raw) |
| 110 # Note that we return 1 less than the width since writing in
to the rightmost column | 111 # Note that we return 1 less than the width since writing in
to the rightmost column |
| 111 # automatically performs a line feed. | 112 # automatically performs a line feed. |
| 112 return right - left | 113 return right - left |
| 113 return sys.maxint | 114 return sys.maxsize |
| 114 else: | 115 else: |
| 115 import fcntl | 116 import fcntl |
| 116 import struct | 117 import struct |
| 117 import termios | 118 import termios |
| 118 packed = fcntl.ioctl(sys.stderr.fileno(), termios.TIOCGWINSZ, '\
0' * 8) | 119 packed = fcntl.ioctl(sys.stderr.fileno(), termios.TIOCGWINSZ, '\
0' * 8) |
| 119 _, columns, _, _ = struct.unpack('HHHH', packed) | 120 _, columns, _, _ = struct.unpack('HHHH', packed) |
| 120 return columns | 121 return columns |
| 121 except: | 122 except: |
| 122 return sys.maxint | 123 return sys.maxsize |
| 123 | 124 |
| 124 def linux_distribution(self): | 125 def linux_distribution(self): |
| 125 if not self.is_linux(): | 126 if not self.is_linux(): |
| 126 return None | 127 return None |
| 127 | 128 |
| 128 if self._filesystem.exists('/etc/redhat-release'): | 129 if self._filesystem.exists('/etc/redhat-release'): |
| 129 return 'redhat' | 130 return 'redhat' |
| 130 if self._filesystem.exists('/etc/debian_version'): | 131 if self._filesystem.exists('/etc/debian_version'): |
| 131 return 'debian' | 132 return 'debian' |
| 132 if self._filesystem.exists('/etc/arch-release'): | 133 if self._filesystem.exists('/etc/arch-release'): |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 if hasattr(sys_module, 'getwindowsversion'): | 184 if hasattr(sys_module, 'getwindowsversion'): |
| 184 return sys_module.getwindowsversion() | 185 return sys_module.getwindowsversion() |
| 185 return self._win_version_tuple_from_cmd() | 186 return self._win_version_tuple_from_cmd() |
| 186 | 187 |
| 187 def _win_version_tuple_from_cmd(self): | 188 def _win_version_tuple_from_cmd(self): |
| 188 # Note that this should only ever be called on windows, so this should a
lways work. | 189 # Note that this should only ever be called on windows, so this should a
lways work. |
| 189 ver_output = self._executive.run_command(['cmd', '/c', 'ver'], decode_ou
tput=False) | 190 ver_output = self._executive.run_command(['cmd', '/c', 'ver'], decode_ou
tput=False) |
| 190 match_object = re.search(r'(?P<major>\d+)\.(?P<minor>\d)\.(?P<build>\d+)
', ver_output) | 191 match_object = re.search(r'(?P<major>\d+)\.(?P<minor>\d)\.(?P<build>\d+)
', ver_output) |
| 191 assert match_object, 'cmd returned an unexpected version string: ' + ver
_output | 192 assert match_object, 'cmd returned an unexpected version string: ' + ver
_output |
| 192 return tuple(map(int, match_object.groups())) | 193 return tuple(map(int, match_object.groups())) |
| OLD | NEW |