OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright 2016 PDFium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 """Small utility function to find depot_tools and add it to the python path. | |
6 | |
7 Will throw an ImportError exception if depot_tools can't be found since it | |
8 imports breakpad. | |
9 | |
10 This can also be used as a standalone script to print out the depot_tools | |
11 directory location. | |
12 """ | |
13 | |
14 import os | |
15 import sys | |
16 | |
17 | |
18 def IsRealDepotTools(path): | |
19 return os.path.isfile(os.path.join(path, 'gclient.py')) | |
20 | |
21 | |
22 def add_depot_tools_to_path(): | |
23 """Search for depot_tools and add it to sys.path.""" | |
24 # First look if depot_tools is already in PYTHONPATH. | |
25 for i in sys.path: | |
26 if i.rstrip(os.sep).endswith('depot_tools') and IsRealDepotTools(i): | |
27 return i | |
28 # Then look if depot_tools is in PATH, common case. | |
29 for i in os.environ['PATH'].split(os.pathsep): | |
30 if IsRealDepotTools(i): | |
31 sys.path.append(i.rstrip(os.sep)) | |
32 return i | |
33 # Rare case, it's not even in PATH, look upward up to root. | |
34 root_dir = os.path.dirname(os.path.abspath(__file__)) | |
35 previous_dir = os.path.abspath(__file__) | |
36 while root_dir and root_dir != previous_dir: | |
37 i = os.path.join(root_dir, 'depot_tools') | |
38 if IsRealDepotTools(i): | |
39 sys.path.append(i) | |
40 return i | |
41 previous_dir = root_dir | |
42 root_dir = os.path.dirname(root_dir) | |
43 print >> sys.stderr, 'Failed to find depot_tools' | |
44 return None | |
45 | |
46 DEPOT_TOOLS_PATH = add_depot_tools_to_path() | |
47 | |
48 # pylint: disable=W0611 | |
49 import breakpad | |
50 | |
51 | |
52 def main(): | |
53 if DEPOT_TOOLS_PATH is None: | |
54 return 1 | |
55 print DEPOT_TOOLS_PATH | |
56 return 0 | |
57 | |
58 | |
59 if __name__ == '__main__': | |
60 sys.exit(main()) | |
OLD | NEW |