1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-31 10:11:17 +00:00

AndroidDevice: Add a common_base_path utility function

Adds a utility function to determine the lowest common base path of a passed list
of files.
This commit is contained in:
Marc Bonnici 2017-05-11 13:48:02 +01:00
parent b10b5970c3
commit b1da0fe958

View File

@ -848,3 +848,16 @@ def memoized(func):
return __memo_cache[id_string]
return memoize_wrapper
def commonprefix(file_list, sep=os.sep):
"""
Find the lowest common base folder of a passed list of files.
"""
common_path = os.path.commonprefix(file_list)
cp_split = common_path.split(sep)
other_split = file_list[0].split(sep)
last = len(cp_split) - 1
if cp_split[last] != other_split[last]:
cp_split = cp_split[:-1]
return sep.join(cp_split)