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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 # automatically performs a line feed. | 111 # automatically performs a line feed. |
112 return right - left | 112 return right - left |
113 return sys.maxsize | 113 return sys.maxsize |
114 else: | 114 else: |
115 import fcntl | 115 import fcntl |
116 import struct | 116 import struct |
117 import termios | 117 import termios |
118 packed = fcntl.ioctl(sys.stderr.fileno(), termios.TIOCGWINSZ, '\
0' * 8) | 118 packed = fcntl.ioctl(sys.stderr.fileno(), termios.TIOCGWINSZ, '\
0' * 8) |
119 _, columns, _, _ = struct.unpack('HHHH', packed) | 119 _, columns, _, _ = struct.unpack('HHHH', packed) |
120 return columns | 120 return columns |
121 except: | 121 except Exception: # pylint: disable=broad-except |
122 return sys.maxsize | 122 return sys.maxsize |
123 | 123 |
124 def linux_distribution(self): | 124 def linux_distribution(self): |
125 if not self.is_linux(): | 125 if not self.is_linux(): |
126 return None | 126 return None |
127 | 127 |
128 if self._filesystem.exists('/etc/redhat-release'): | 128 if self._filesystem.exists('/etc/redhat-release'): |
129 return 'redhat' | 129 return 'redhat' |
130 if self._filesystem.exists('/etc/debian_version'): | 130 if self._filesystem.exists('/etc/debian_version'): |
131 return 'debian' | 131 return 'debian' |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 if win_version_tuple[:2] == (6, 2): | 164 if win_version_tuple[:2] == (6, 2): |
165 return '8' | 165 return '8' |
166 if win_version_tuple[:3] == (6, 1, 7601): | 166 if win_version_tuple[:3] == (6, 1, 7601): |
167 return '7sp1' | 167 return '7sp1' |
168 if win_version_tuple[:3] == (6, 1, 7600): | 168 if win_version_tuple[:3] == (6, 1, 7600): |
169 return '7sp0' | 169 return '7sp0' |
170 if win_version_tuple[:2] == (6, 0): | 170 if win_version_tuple[:2] == (6, 0): |
171 return 'vista' | 171 return 'vista' |
172 if win_version_tuple[:2] == (5, 1): | 172 if win_version_tuple[:2] == (5, 1): |
173 return 'xp' | 173 return 'xp' |
174 assert (win_version_tuple[0] > 10 or | 174 assert ( |
175 win_version_tuple[0] == 10 and win_version_tuple[1] > 0), ( | 175 win_version_tuple[0] > 10 or |
176 'Unrecognized Windows version tuple: "%s"' % (win_version_tuple,)) | 176 win_version_tuple[0] == 10 and win_version_tuple[1] > 0), ( |
| 177 'Unrecognized Windows version tuple: "%s"' % (win_version_tuple,
)) |
177 return 'future' | 178 return 'future' |
178 | 179 |
179 def _win_version_tuple(self, sys_module): | 180 def _win_version_tuple(self, sys_module): |
180 if hasattr(sys_module, 'getwindowsversion'): | 181 if hasattr(sys_module, 'getwindowsversion'): |
181 return sys_module.getwindowsversion() | 182 return sys_module.getwindowsversion() |
182 return self._win_version_tuple_from_cmd() | 183 return self._win_version_tuple_from_cmd() |
183 | 184 |
184 def _win_version_tuple_from_cmd(self): | 185 def _win_version_tuple_from_cmd(self): |
185 # Note that this should only ever be called on windows, so this should a
lways work. | 186 # 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) | 187 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) | 188 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 | 189 assert match_object, 'cmd returned an unexpected version string: ' + ver
_output |
189 return tuple(map(int, match_object.groups())) | 190 return tuple(map(int, match_object.groups())) |
OLD | NEW |