Return the relative path between origin and dest. If it's not possible return dest. If they are identical return ``os.curdir`` Adapted from `path.py `_ by Jason Orendorff.
(origin, dest)
| 49 | return parts |
| 50 | |
| 51 | def _make_path_relative(origin, dest): |
| 52 | """ |
| 53 | Return the relative path between origin and dest. |
| 54 | |
| 55 | If it's not possible return dest. |
| 56 | |
| 57 | |
| 58 | If they are identical return ``os.curdir`` |
| 59 | |
| 60 | Adapted from `path.py <http://www.jorendorff.com/articles/python/path/>`_ by Jason Orendorff. |
| 61 | """ |
| 62 | origin = os.path.abspath(origin).replace('\\', '/') |
| 63 | dest = os.path.abspath(dest).replace('\\', '/') |
| 64 | # |
| 65 | orig_list = splitall(os.path.normcase(origin)) |
| 66 | # Don't normcase dest! We want to preserve the case. |
| 67 | dest_list = splitall(dest) |
| 68 | # |
| 69 | if orig_list[0] != os.path.normcase(dest_list[0]): |
| 70 | # Can't get here from there. |
| 71 | return dest |
| 72 | # |
| 73 | # Find the location where the two paths start to differ. |
| 74 | i = 0 |
| 75 | for start_seg, dest_seg in zip(orig_list, dest_list): |
| 76 | if start_seg != os.path.normcase(dest_seg): |
| 77 | break |
| 78 | i += 1 |
| 79 | # |
| 80 | # Now i is the point where the two paths diverge. |
| 81 | # Need a certain number of "os.pardir"s to work up |
| 82 | # from the origin to the point of divergence. |
| 83 | segments = [os.pardir] * (len(orig_list) - i) |
| 84 | # Need to add the diverging part of dest_list. |
| 85 | segments += dest_list[i:] |
| 86 | if len(segments) == 0: |
| 87 | # If they happen to be identical, use os.curdir. |
| 88 | return os.curdir |
| 89 | else: |
| 90 | # return os.path.join(*segments).replace('\\', '/') |
| 91 | return os.path.join(*segments) |
| 92 | |
| 93 | def xml_indent(elem, level=0): |
| 94 | i = "\n" + level*" " |
no test coverage detected