1# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import os
6import platform
7import sys
8
9import py_utils
10
11def GetOSAndArchForCurrentDesktopPlatform():
12  os_name = GetOSNameForCurrentDesktopPlatform()
13  return os_name, GetArchForCurrentDesktopPlatform(os_name)
14
15
16def GetOSNameForCurrentDesktopPlatform():
17  if py_utils.IsRunningOnCrosDevice():
18    return 'chromeos'
19  if sys.platform.startswith('linux'):
20    return 'linux'
21  if sys.platform == 'darwin':
22    return 'mac'
23  if sys.platform == 'win32':
24    return 'win'
25  return sys.platform
26
27
28def GetArchForCurrentDesktopPlatform(os_name):
29  if os_name == 'chromeos':
30    # Current tests outside of telemetry don't run on chromeos, and
31    # platform.machine is not the way telemetry gets the arch name on chromeos.
32    raise NotImplementedError()
33  return platform.machine()
34
35
36def GetChromeApkOsVersion(version_name):
37  version = version_name[0]
38  assert version.isupper(), (
39      'First character of versions name %s was not an uppercase letter.')
40  if version < 'L':
41    return 'k'
42  elif version > 'M':
43    return 'n'
44  return 'l'
45
46
47def ChromeBinariesConfigPath():
48  return os.path.realpath(os.path.join(
49      os.path.dirname(os.path.abspath(__file__)), 'chrome_binaries.json'))
50