Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: tools/find_depot_tools.py

Issue 137203009: Check that directory named depot_tools appears to be full checkout (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: stupid reitveld Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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
14 def IsRealDepotTools(path):
15 return os.path.isfile(os.path.join(path, 'breakpad.py'))
16
17
13 def add_depot_tools_to_path(): 18 def add_depot_tools_to_path():
14 """Search for depot_tools and add it to sys.path.""" 19 """Search for depot_tools and add it to sys.path."""
15 # First look if depot_tools is already in PYTHONPATH. 20 # First look if depot_tools is already in PYTHONPATH.
16 for i in sys.path: 21 for i in sys.path:
17 if i.rstrip(os.sep).endswith('depot_tools'): 22 if i.rstrip(os.sep).endswith('depot_tools') and IsRealDepotTools(i):
18 return i 23 return i
19 # Then look if depot_tools is in PATH, common case. 24 # Then look if depot_tools is in PATH, common case.
20 for i in os.environ['PATH'].split(os.pathsep): 25 for i in os.environ['PATH'].split(os.pathsep):
21 if i.rstrip(os.sep).endswith('depot_tools'): 26 if i.rstrip(os.sep).endswith('depot_tools') and IsRealDepotTools(i):
22 sys.path.append(i.rstrip(os.sep)) 27 sys.path.append(i.rstrip(os.sep))
23 return i 28 return i
24 # Rare case, it's not even in PATH, look upward up to root. 29 # Rare case, it's not even in PATH, look upward up to root.
25 root_dir = os.path.dirname(os.path.abspath(__file__)) 30 root_dir = os.path.dirname(os.path.abspath(__file__))
26 previous_dir = os.path.abspath(__file__) 31 previous_dir = os.path.abspath(__file__)
27 while root_dir and root_dir != previous_dir: 32 while root_dir and root_dir != previous_dir:
28 if os.path.isfile(os.path.join(root_dir, 'depot_tools', 'breakpad.py')): 33 if IsRealDepotTools(os.path.join(root_dir, 'depot_tools')):
29 i = os.path.join(root_dir, 'depot_tools') 34 i = os.path.join(root_dir, 'depot_tools')
Paweł Hajdan Jr. 2014/01/22 03:27:30 While you're here, let's deduplicate "os.path.join
scottmg 2014/01/22 05:05:36 Done.
30 sys.path.append(i) 35 sys.path.append(i)
31 return i 36 return i
32 previous_dir = root_dir 37 previous_dir = root_dir
33 root_dir = os.path.dirname(root_dir) 38 root_dir = os.path.dirname(root_dir)
34 print >> sys.stderr, 'Failed to find depot_tools' 39 print >> sys.stderr, 'Failed to find depot_tools'
35 return None 40 return None
36 41
37 add_depot_tools_to_path() 42 add_depot_tools_to_path()
38 43
39 # pylint: disable=W0611 44 # pylint: disable=W0611
40 import breakpad 45 import breakpad
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698