aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Slater <joe.slater@windriver.com>2024-01-30 14:02:13 -0800
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2024-05-09 14:41:37 +0200
commit571f8ebaf051e0014df93f5966bad0276a31d668 (patch)
treef986b503808687a36895506eb1f36433bbe631b4
parente53503546990adeab67b6d044fcce59dc5a3f455 (diff)
downloadbitbake-contrib-571f8ebaf051e0014df93f5966bad0276a31d668.tar.gz
utils.py: add var_in_numeric_range()
Add a function returning a value based on whether a bitbake variable is in a numeric range. Signed-off-by: Joe Slater <joe.slater@windriver.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
-rw-r--r--lib/bb/utils.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index ebee65d3d..9c09fe66e 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -1812,6 +1812,17 @@ def is_local_uid(uid=''):
return True
return False
+def var_in_numeric_range(d, var, first=1, last=0, truevalue="", falsevalue=""):
+ """
+ Return a value depending on whether a bitbake variable is in a numeric
+ range. Conventionally, 0 as the end of the range matches all values.
+ """
+ try:
+ v = int(d.getVar(var))
+ except:
+ return falsevalue
+ return truevalue if v >= first and (v <= last or last == 0) else falsevalue
+
def mkstemp(suffix=None, prefix=None, dir=None, text=False):
"""
Generates a unique filename, independent of time.