From b1da0fe958aaeab51378eaa9e26f980667f40523 Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Thu, 11 May 2017 13:48:02 +0100 Subject: [PATCH] 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. --- wlauto/utils/misc.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wlauto/utils/misc.py b/wlauto/utils/misc.py index 98e79e05..a66e985b 100644 --- a/wlauto/utils/misc.py +++ b/wlauto/utils/misc.py @@ -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)