From 58b0a65ada340fda3bc04fa9fcb648eb43246402 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Fri, 27 Jun 2025 10:12:06 +0100 Subject: bitbake: utils: Refactor filemode variable conversion to a function We have other places in the code where we need to take filemode/mask information from a bitbake variable and turn it into a real python number. Turn this internal code into public API in bb.utils and add some tests for it. (Bitbake rev: d89e30fb2fb15b09f2cb95c4e5aa9f749ca257ea) Signed-off-by: Richard Purdie --- bitbake/lib/bb/utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'bitbake/lib/bb/utils.py') diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index a2806fd360..1cc74ed546 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py @@ -1211,6 +1211,23 @@ def which(path, item, direction = 0, history = False, executable=False): return "", hist return "" +def to_filemode(input): + """ + Take a bitbake variable contents defining a file mode and return + the proper python representation of the number + + Arguments: + + - ``input``: a string or number to convert, e.g. a bitbake variable + string, assumed to be an octal representation + + Returns the python file mode as a number + """ + # umask might come in as a number or text string.. + if type(input) is int: + return input + return int(input, 8) + @contextmanager def umask(new_mask): """ -- cgit v1.2.3-54-g00ecf