1 # Copyright 2013 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 5 """A library for cross-platform browser tests.""" 6 import os 7 import sys 8 9 10 # Ensure Python >= 2.7. 11 if sys.version_info < (2, 7): 12 print >> sys.stderr, 'Need Python 2.7 or greater.' 13 sys.exit(-1) 14 15 16 def _JoinPath(*path_parts): 17 return os.path.abspath(os.path.join(*path_parts)) 18 19 20 def _AddDirToPythonPath(*path_parts): 21 path = _JoinPath(*path_parts) 22 if os.path.isdir(path) and path not in sys.path: 23 # Some call sites that use Telemetry assume that sys.path[0] is the 24 # directory containing the script, so we add these extra paths to right 25 # after sys.path[0]. 26 sys.path.insert(1, path) 27 28 29 # Add Catapult dependencies to our path. 30 # util depends on py_utils, so we can't use it to get the catapult dir. 31 _CATAPULT_DIR = os.path.join( 32 os.path.dirname(os.path.abspath(__file__)), '..', '..') 33 _AddDirToPythonPath(_CATAPULT_DIR, 'common', 'py_utils') 34 _AddDirToPythonPath(_CATAPULT_DIR, 'dependency_manager') 35 _AddDirToPythonPath(_CATAPULT_DIR, 'devil') 36 _AddDirToPythonPath(_CATAPULT_DIR, 'systrace') 37 _AddDirToPythonPath(_CATAPULT_DIR, 'tracing') 38 _AddDirToPythonPath(_CATAPULT_DIR, 'common', 'py_trace_event') 39 _AddDirToPythonPath(_CATAPULT_DIR, 'common', 'battor') 40 _AddDirToPythonPath(_CATAPULT_DIR, 'tracing', 'tracing_build') 41 _AddDirToPythonPath(_CATAPULT_DIR, 'third_party', 'py_vulcanize') 42 43 44 from telemetry.core import util 45 from telemetry.internal.util import global_hooks 46 47 # Add Catapult third party dependencies into our path. 48 _AddDirToPythonPath(util.GetCatapultThirdPartyDir(), 'typ') 49 50 # Add Telemetry third party dependencies into our path. 51 _AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'altgraph') 52 _AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'mock') 53 _AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'modulegraph') 54 _AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'mox3') 55 _AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'pexpect') 56 _AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'png') 57 _AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'pyfakefs') 58 _AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'pyserial') 59 _AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'web-page-replay') 60 _AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'websocket-client') 61 62 # Install Telemtry global hooks. 63 global_hooks.InstallHooks() 64