agr /
rope
(http://rope.sf.net/)
A python refactoring library
Clone URL : http://bitbucket.org/agr/rope/ (size: 3.3 MB)
| commit 1522: | b8e5f9fc8acc |
| parent 1521: | 84cdb822d326 |
| branch: | trunk |
libutils: rely on project._realpath() in relative()
Stop trying to support hard links when you can't ;-)
2 months ago
Changed (Δ354 bytes):
raw changeset »
rope/base/libutils.py (6 lines added, 19 lines removed)
Up to file-list rope/base/libutils.py:
| … | … | @@ -30,25 +30,12 @@ def path_to_resource(project, path, type |
30 |
30 |
return None |
31 |
31 |
|
32 |
32 |
def relative(root, path): |
33 |
root = rope.base.project._realpath(root) |
|
34 |
path = rope.base.project._realpath(path) |
|
35 |
if os.name == 'nt': |
|
36 |
root = root.rstrip('\\') |
|
37 |
if path.startswith(root): |
|
38 |
return path[len(root):].replace('\\', '/').lstrip('/') |
|
39 |
return |
|
40 |
rel = [] |
|
41 |
while True: |
|
42 |
try: |
|
43 |
if os.path.samefile(root, path): |
|
44 |
return '/'.join(reversed(rel)) |
|
45 |
except OSError: |
|
46 |
pass |
|
47 |
parent = os.path.dirname(path) |
|
48 |
if not parent or parent == path: |
|
49 |
break |
|
50 |
rel.append(os.path.basename(path)) |
|
51 |
|
|
33 |
root = rope.base.project._realpath(root).replace(os.path.sep, '/') |
|
34 |
path = rope.base.project._realpath(path).replace(os.path.sep, '/') |
|
35 |
if path == root: |
|
36 |
return '' |
|
37 |
if path.startswith(root + '/'): |
|
38 |
return path[len(root) + 1:] |
|
52 |
39 |
|
53 |
40 |
def report_change(project, path, old_content): |
54 |
41 |
"""Report that the contents of file at `path` was changed |
