diff options
author | Joe Slater <joe.slater@windriver.com> | 2024-01-30 14:02:13 -0800 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2024-05-09 14:41:37 +0200 |
commit | 571f8ebaf051e0014df93f5966bad0276a31d668 (patch) | |
tree | f986b503808687a36895506eb1f36433bbe631b4 | |
parent | e53503546990adeab67b6d044fcce59dc5a3f455 (diff) | |
download | bitbake-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.py | 11 |
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. |