• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2011 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"""Small utility function to find depot_tools and add it to the python path.
5
6Will throw an ImportError exception if depot_tools can't be found since it
7imports breakpad.
8"""
9
10import os
11import sys
12
13def add_depot_tools_to_path():
14  """Search for depot_tools and add it to sys.path."""
15  # First look if depot_tools is already in PYTHONPATH.
16  for i in sys.path:
17    if i.rstrip(os.sep).endswith('depot_tools'):
18      return i
19  # Then look if depot_tools is in PATH, common case.
20  for i in os.environ['PATH'].split(os.pathsep):
21    if i.rstrip(os.sep).endswith('depot_tools'):
22      sys.path.append(i.rstrip(os.sep))
23      return i
24  # Rare case, it's not even in PATH, look upward up to root.
25  root_dir = os.path.dirname(os.path.abspath(__file__))
26  previous_dir = os.path.abspath(__file__)
27  while root_dir and root_dir != previous_dir:
28    if os.path.isfile(os.path.join(root_dir, 'depot_tools', 'breakpad.py')):
29      i = os.path.join(root_dir, 'depot_tools')
30      sys.path.append(i)
31      return i
32    previous_dir = root_dir
33    root_dir = os.path.dirname(root_dir)
34  print >> sys.stderr, 'Failed to find depot_tools'
35  return None
36
37add_depot_tools_to_path()
38
39# pylint: disable=W0611
40import breakpad
41