path.py revision 5f1c94371a64b3196d4be9466099bb892df9b88e
1# Copyright 2014 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 6 7from telemetry.core import util 8 9 10# TODO(dtu): Move these functions from core.util to here. 11GetBaseDir = util.GetBaseDir 12GetTelemetryDir = util.GetTelemetryDir 13GetUnittestDataDir = util.GetUnittestDataDir 14GetChromiumSrcDir = util.GetChromiumSrcDir 15AddDirToPythonPath = util.AddDirToPythonPath 16GetBuildDirectories = util.GetBuildDirectories 17 18 19def IsExecutable(path): 20 return os.path.isfile(path) and os.access(path, os.X_OK) 21 22 23def FindInstalledWindowsApplication(application_path): 24 """Search common Windows installation directories for an application. 25 26 Args: 27 application_path: Path to application relative from installation location. 28 Returns: 29 A string representing the full path, or None if not found. 30 """ 31 search_paths = [os.getenv('PROGRAMFILES(X86)'), 32 os.getenv('PROGRAMFILES'), 33 os.getenv('LOCALAPPDATA')] 34 search_paths += os.getenv('PATH', '').split(os.pathsep) 35 36 for search_path in search_paths: 37 if not search_path: 38 continue 39 path = os.path.join(search_path, application_path) 40 if IsExecutable(path): 41 return path 42 43 return None 44