[OE-core] [PATCH 1/8] lib/oe/path: implement is_path_under()

Ola x Nilsson ola.x.nilsson at axis.com
Fri Feb 23 07:42:34 UTC 2018


> From: openembedded-core-bounces at lists.openembedded.org
> [mailto:openembedded-core-bounces at lists.openembedded.org] On Behalf
> Of Paul Eggleton
> Sent: den 23 februari 2018 04:02
> To: openembedded-core at lists.openembedded.org
> 
<snip>
> Signed-off-by: Paul Eggleton <paul.eggleton at linux.intel.com>
> ---
>  meta/lib/oe/path.py | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py index
> 1ea03d5d568..346b48f3641 100644
> --- a/meta/lib/oe/path.py
> +++ b/meta/lib/oe/path.py
> @@ -237,3 +237,27 @@ def realpath(file, root, use_physdir = True, loop_cnt
> = 100, assume_dir = False)
>          raise
> 
>      return file
> +
> +def is_path_under(path1, possible_parent):

Changing the signature to is_path_under(possible_parent, *paths) will make the list management more natural.

This function will return True if path1 is the empty list. Is that intentional?

/Ola Nilsson

> +    """
> +    Return True if a path is underneath another, False otherwise.
> +    Multiple paths to test can be specified (as a list or tuple) in
> +    which case all specified test paths must be under the parent to
> +    return True.
> +    """
> +    def abs_path_trailing(pth):
> +        pth_abs = os.path.abspath(pth)
> +        if not pth_abs.endswith(os.sep):
> +            pth_abs += os.sep
> +        return pth_abs
> +
> +    possible_parent_abs = abs_path_trailing(possible_parent)
> +    if isinstance(path1, str):
> +        testpaths = [path1]
> +    else:
> +        testpaths = path1
> +    for path in testpaths:
> +        path_abs = abs_path_trailing(path)
> +        if not path_abs.startswith(possible_parent_abs):
> +            return False
> +    return True
> --
> 2.14.3
> 
> --
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core at lists.openembedded.org
> http://lists.openembedded.org/mailman/listinfo/openembedded-core



More information about the Openembedded-core mailing list