| OLD | NEW |
| 1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 Google Inc. 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 | 4 |
| 5 from __future__ import with_statement | 5 from __future__ import with_statement |
| 6 | 6 |
| 7 import errno | 7 import errno |
| 8 import filecmp | 8 import filecmp |
| 9 import os.path | 9 import os.path |
| 10 import re | 10 import re |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 @memoize | 124 @memoize |
| 125 def RelativePath(path, relative_to): | 125 def RelativePath(path, relative_to): |
| 126 # Assuming both |path| and |relative_to| are relative to the current | 126 # Assuming both |path| and |relative_to| are relative to the current |
| 127 # directory, returns a relative path that identifies path relative to | 127 # directory, returns a relative path that identifies path relative to |
| 128 # relative_to. | 128 # relative_to. |
| 129 | 129 |
| 130 # Convert to normalized (and therefore absolute paths). | 130 # Convert to normalized (and therefore absolute paths). |
| 131 path = os.path.realpath(path) | 131 path = os.path.realpath(path) |
| 132 relative_to = os.path.realpath(relative_to) | 132 relative_to = os.path.realpath(relative_to) |
| 133 | 133 |
| 134 # On Windows, we can't create a relative path to a different drive, so just |
| 135 # use the absolute path. |
| 136 if sys.platform == 'win32': |
| 137 if (os.path.splitdrive(path)[0].lower() != |
| 138 os.path.splitdrive(relative_to)[0].lower()): |
| 139 return path |
| 140 |
| 134 # Split the paths into components. | 141 # Split the paths into components. |
| 135 path_split = path.split(os.path.sep) | 142 path_split = path.split(os.path.sep) |
| 136 relative_to_split = relative_to.split(os.path.sep) | 143 relative_to_split = relative_to.split(os.path.sep) |
| 137 | 144 |
| 138 # Determine how much of the prefix the two paths share. | 145 # Determine how much of the prefix the two paths share. |
| 139 prefix_len = len(os.path.commonprefix([path_split, relative_to_split])) | 146 prefix_len = len(os.path.commonprefix([path_split, relative_to_split])) |
| 140 | 147 |
| 141 # Put enough ".." components to back up out of relative_to to the common | 148 # Put enough ".." components to back up out of relative_to to the common |
| 142 # prefix, and then append the part of path_split after the common prefix. | 149 # prefix, and then append the part of path_split after the common prefix. |
| 143 relative_split = [os.path.pardir] * (len(relative_to_split) - prefix_len) + \ | 150 relative_split = [os.path.pardir] * (len(relative_to_split) - prefix_len) + \ |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 return | 489 return |
| 483 visited.add(node) | 490 visited.add(node) |
| 484 visiting.add(node) | 491 visiting.add(node) |
| 485 for neighbor in get_edges(node): | 492 for neighbor in get_edges(node): |
| 486 Visit(neighbor) | 493 Visit(neighbor) |
| 487 visiting.remove(node) | 494 visiting.remove(node) |
| 488 ordered_nodes.insert(0, node) | 495 ordered_nodes.insert(0, node) |
| 489 for node in sorted(graph): | 496 for node in sorted(graph): |
| 490 Visit(node) | 497 Visit(node) |
| 491 return ordered_nodes | 498 return ordered_nodes |
| OLD | NEW |