Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
|
borenet
2014/06/23 19:45:31
This is directly copied from https://chromium.goog
| |
| 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 | |
| 6 Will throw an ImportError exception if depot_tools can't be found since it | |
| 7 imports breakpad. | |
|
rmistry
2014/06/24 17:55:44
Please add a comment here:
This is directly copie
borenet
2014/06/24 18:00:26
Done.
| |
| 8 """ | |
| 9 | |
| 10 import os | |
| 11 import sys | |
| 12 | |
| 13 | |
| 14 def directory_really_is_depot_tools(directory): | |
| 15 return os.path.isfile(os.path.join(directory, 'breakpad.py')) | |
| 16 | |
| 17 | |
| 18 def add_depot_tools_to_path(): | |
| 19 """Search for depot_tools and add it to sys.path.""" | |
| 20 # First look if depot_tools is already in PYTHONPATH. | |
| 21 for i in sys.path: | |
| 22 if i.rstrip(os.sep).endswith('depot_tools'): | |
| 23 if directory_really_is_depot_tools(i): | |
| 24 return i | |
| 25 | |
| 26 # Then look if depot_tools is in PATH, common case. | |
| 27 for i in os.environ['PATH'].split(os.pathsep): | |
| 28 if i.rstrip(os.sep).endswith('depot_tools'): | |
| 29 if directory_really_is_depot_tools(i): | |
| 30 sys.path.insert(0, i.rstrip(os.sep)) | |
| 31 return i | |
| 32 # Rare case, it's not even in PATH, look upward up to root. | |
| 33 root_dir = os.path.dirname(os.path.abspath(__file__)) | |
| 34 previous_dir = os.path.abspath(__file__) | |
| 35 while root_dir and root_dir != previous_dir: | |
| 36 if directory_really_is_depot_tools(os.path.join(root_dir, 'depot_tools')): | |
| 37 i = os.path.join(root_dir, 'depot_tools') | |
| 38 sys.path.insert(0, i) | |
| 39 return i | |
| 40 previous_dir = root_dir | |
| 41 root_dir = os.path.dirname(root_dir) | |
| 42 print >> sys.stderr, 'Failed to find depot_tools' | |
| 43 return None | |
| 44 | |
| 45 add_depot_tools_to_path() | |
| 46 | |
| 47 # pylint: disable=W0611 | |
| 48 import breakpad | |
| OLD | NEW |