MCPcopy Index your code
hub / github.com/RustPython/RustPython / _syscmd_ver

Function _syscmd_ver

Lib/platform.py:266–318  ·  view source on GitHub ↗

Tries to figure out the OS version used and returns a tuple (system, release, version). It uses the "ver" shell command for this which is known to exists on Windows, DOS. XXX Others too ? In case this fails, the given parameters are used as defaults.

(system='', release='', version='',

               supported_platforms=('win32', 'win16', 'dos'))

Source from the content-addressed store, hash-verified

264# Windows versions.
265
266def _syscmd_ver(system='', release='', version='',
267
268 supported_platforms=('win32', 'win16', 'dos')):
269
270 """ Tries to figure out the OS version used and returns
271 a tuple (system, release, version).
272
273 It uses the "ver" shell command for this which is known
274 to exists on Windows, DOS. XXX Others too ?
275
276 In case this fails, the given parameters are used as
277 defaults.
278
279 """
280 if sys.platform not in supported_platforms:
281 return system, release, version
282
283 # Try some common cmd strings
284 import subprocess
285 for cmd in ('ver', 'command /c ver', 'cmd /c ver'):
286 try:
287 info = subprocess.check_output(cmd,
288 stdin=subprocess.DEVNULL,
289 stderr=subprocess.DEVNULL,
290 text=True,
291 encoding="locale",
292 shell=True)
293 except (OSError, subprocess.CalledProcessError) as why:
294 #print('Command %s failed: %s' % (cmd, why))
295 continue
296 else:
297 break
298 else:
299 return system, release, version
300
301 ver_output = re.compile(r'(?:([\w ]+) ([\w.]+) '
302 r'.*'
303 r'\[.* ([\d.]+)\])')
304
305 # Parse the output
306 info = info.strip()
307 m = ver_output.match(info)
308 if m is not None:
309 system, release, version = m.groups()
310 # Strip trailing dots from version and release
311 if release[-1] == '.':
312 release = release[:-1]
313 if version[-1] == '.':
314 version = version[:-1]
315 # Normalize the version and build strings (eliminating additional
316 # zeros)
317 version = _norm_version(version)
318 return system, release, version
319
320
321def _wmi_query(table, *keys):

Callers 2

_win32_verFunction · 0.85
unameFunction · 0.85

Calls 6

_norm_versionFunction · 0.85
check_outputMethod · 0.45
compileMethod · 0.45
stripMethod · 0.45
matchMethod · 0.45
groupsMethod · 0.45

Tested by

no test coverage detected