OLD | NEW |
1 # Copyright 2009 Google Inc. All Rights Reserved. | 1 # Copyright 2009 Google Inc. All Rights Reserved. |
2 # | 2 # |
3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
6 # | 6 # |
7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
8 # | 8 # |
9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 """Returns the difference subpath minus root.""" | 316 """Returns the difference subpath minus root.""" |
317 root = os.path.realpath(root) | 317 root = os.path.realpath(root) |
318 subpath = os.path.realpath(subpath) | 318 subpath = os.path.realpath(subpath) |
319 if not subpath.startswith(root): | 319 if not subpath.startswith(root): |
320 return None | 320 return None |
321 # If the root does not have a trailing \ or /, we add it so the returned | 321 # If the root does not have a trailing \ or /, we add it so the returned |
322 # path starts immediately after the seperator regardless of whether it is | 322 # path starts immediately after the seperator regardless of whether it is |
323 # provided. | 323 # provided. |
324 root = os.path.join(root, '') | 324 root = os.path.join(root, '') |
325 return subpath[len(root):] | 325 return subpath[len(root):] |
| 326 |
| 327 |
| 328 def FindFileUpwards(filename, path=None): |
| 329 """Search upwards from the a directory (default: current) to find a file.""" |
| 330 if not path: |
| 331 path = os.getcwd() |
| 332 path = os.path.realpath(path) |
| 333 while True: |
| 334 file_path = os.path.join(path, filename) |
| 335 if os.path.isfile(file_path): |
| 336 return file_path |
| 337 (new_path, _) = os.path.split(path) |
| 338 if new_path == path: |
| 339 return None |
| 340 path = new_path |
| 341 |
| 342 |
| 343 def GetGClientRootAndEntries(path=None): |
| 344 """Returns the gclient root and the dict of entries.""" |
| 345 config_file = '.gclient_entries' |
| 346 config_path = FindFileUpwards(config_file, path) |
| 347 |
| 348 if not config_path: |
| 349 print "Can't find", config_file |
| 350 return None |
| 351 |
| 352 env = {} |
| 353 execfile(config_path, env) |
| 354 config_dir = os.path.dirname(config_path) |
| 355 return config_dir, env['entries'] |
OLD | NEW |