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