MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / _make_path_relative

Function _make_path_relative

tools/utils.py:51–91  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

49 return parts
50
51def _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
93def xml_indent(elem, level=0):
94 i = "\n" + level*" "

Callers 15

CLAddHeaderFilesFunction · 0.90
CLAddCFilesFunction · 0.90
TargetCodeliteFunction · 0.90
SDKAddGroupFunction · 0.90
_CDKProjectFunction · 0.90
GenerateCFilesFunction · 0.90
GenerateCFilesFunction · 0.90
VS_AddGroupFunction · 0.90
VS_AddHeadFilesGroupFunction · 0.90
VSProjectFunction · 0.90
CB_AddHeadFilesFunction · 0.90
CB_AddCFilesFunction · 0.90

Calls 2

splitallFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected