1# Copyright 2023 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import functools 6import platform 7import subprocess 8 9from pkg_resources import packaging 10 11 12def check_chrome_version(downloaded_chrome: str) -> packaging.version.Version: 13 host = get_hosted_platform() 14 if host == 'win': 15 cmd = ('powershell -command "&{(Get-Item' 16 '\''+ downloaded_chrome + '\').VersionInfo.ProductVersion}"') 17 version = subprocess.run(cmd, check=True, 18 capture_output=True).stdout.decode('utf-8') 19 else: 20 cmd = [downloaded_chrome, '--version'] 21 version = subprocess.run(cmd, check=True, 22 capture_output=True).stdout.decode('utf-8') 23 # Only return the version number portion 24 version = version.strip().split(' ')[-1] 25 return packaging.version.parse(version) 26 27@functools.lru_cache 28def get_hosted_platform() -> str: 29 """Returns the host platform. 30 31 Returns: One of 'linux', 'win' and 'mac'. 32 """ 33 host = platform.uname().system.lower() 34 if host in ('win32', 'cygwin', 'windows'): 35 return 'win' 36 if host.startswith('linux'): 37 return 'linux' 38 if host == 'darwin': 39 return 'mac' 40 41 raise RuntimeError('Unknown or unsupported host platform (%s).' % 42 platform.uname()) 43