OLD | NEW |
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 """Small utility function to find depot_tools and add it to the python path. | 4 """Small utility function to find depot_tools and add it to the python path. |
5 | 5 |
6 Will throw an ImportError exception if depot_tools can't be found since it | 6 Will throw an ImportError exception if depot_tools can't be found since it |
7 imports breakpad. | 7 imports breakpad. |
8 """ | 8 """ |
9 | 9 |
10 import os | 10 import os |
11 import sys | 11 import sys |
12 | 12 |
13 def add_depot_tools_to_path(): | 13 def add_depot_tools_to_path(): |
14 """Search for depot_tools and add it to sys.path.""" | 14 """Search for depot_tools and add it to sys.path.""" |
15 # First look if depot_tools is already in PYTHONPATH. | 15 # First look if depot_tools is already in PYTHONPATH. |
16 for i in sys.path: | 16 for i in sys.path: |
17 if i.endswith('depot_tools'): | 17 if i.endswith('depot_tools'): |
18 return | 18 return |
19 # Then look if depot_tools is in PATH, common case. | 19 # Then look if depot_tools is in PATH, common case. |
20 for i in os.environ['PATH'].split(os.pathsep): | 20 for i in os.environ['PATH'].split(os.pathsep): |
21 if i.rstrip(os.sep).endswith('depot_tools'): | 21 if i.rstrip(os.sep).endswith('depot_tools'): |
22 sys.path.append(i.rstrip(os.sep)) | 22 sys.path.append(i.rstrip(os.sep)) |
23 return | 23 return |
24 # Rare case, it's not even in PATH, look upward up to root. | 24 # Rare case, it's not even in PATH, look upward up to root. |
25 root_dir = os.path.dirname(os.path.abspath(__file__)) | 25 root_dir = os.path.dirname(os.path.abspath(__file__)) |
26 while root_dir: | 26 while root_dir: |
27 if os.path.isfile(os.path.join(root_dir, 'depot_tools', 'breakpad.py')): | 27 if os.path.isfile(os.path.join(root_dir, 'depot_tools', 'breakpad.py')): |
28 sys.path.append(os.path.join(root_dir, 'depot_tools')) | 28 sys.path.append(os.path.join(root_dir, 'depot_tools')) |
29 return | 29 return |
30 | 30 root_dir = os.path.dirname(root_dir) |
| 31 print >> sys.stderr, 'Failed to find depot_tools' |
31 | 32 |
32 add_depot_tools_to_path() | 33 add_depot_tools_to_path() |
33 | 34 |
34 # pylint: disable=W0611 | 35 # pylint: disable=W0611 |
35 import breakpad | 36 import breakpad |
OLD | NEW |