avocado.utils.misc: Remove get_relative_path

That function is not used in the avocado code base, and
it is superseded by standard library function
os.path.relpath().
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 90b23032
......@@ -13,7 +13,6 @@
# Authors: Martin J Bligh <mbligh@google.com>, Andy Whitcroft <apw@shadowen.org>
import logging
import os
log = logging.getLogger('avocado.test')
......@@ -78,40 +77,3 @@ def write_file(filename, data):
"""
with open(filename, 'w') as file_obj:
file_obj.write(data)
def get_relative_path(path, reference):
"""
Given 2 absolute paths "path" and "reference", compute the path of
"path" as relative to the directory "reference".
:param path: The absolute path to convert to a relative path.
:param reference: An absolute directory path to which the relative
path will be computed.
"""
# normalize the paths (remove double slashes, etc)
assert(os.path.isabs(path))
assert(os.path.isabs(reference))
path = os.path.normpath(path)
reference = os.path.normpath(reference)
# we could use os.path.split() but it splits from the end
path_list = path.split(os.path.sep)[1:]
ref_list = reference.split(os.path.sep)[1:]
# find the longest leading common path
for i in xrange(min(len(path_list), len(ref_list))):
if path_list[i] != ref_list[i]:
# decrement i so when exiting this loop either by no match or by
# end of range we are one step behind
i -= 1
break
i += 1
# drop the common part of the paths, not interested in that anymore
del path_list[:i]
# for each uncommon component in the reference prepend a ".."
path_list[:0] = ['..'] * (len(ref_list) - i)
return os.path.join(*path_list)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册