Skip to contentSkip to conversation

utils.py: add var_in_numeric_range()

PATCH Slater, Joseph 1 participant 1 message Jan 30, 2024 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Oops, needs a little editing.

Quoted 49 lines

-----Original Message-----
From: [email protected] <bitbake- [email protected]> On Behalf Of Joe Slater via lists.openembedded.org
Sent: Tuesday, January 30, 2024 1:57 PM
To: [email protected]
Cc: Slater, Joseph <[email protected]>; MacLeod, Randy <[email protected]>
Subject: [bitbake-devel] [bitbake][PATCH 1/1] utils.py: add var_in_numeric_range()

From: Joe Slater <[email protected]>

Add a function returning a value based on whether a bitbake variable is in a numeric range.

Issue: LINUXEXEC-29701

(LOCAL REV: NOT UPSTREAM) - sent to bitbake/master

---
 lib/bb/utils.py | 11 +++++++++++
 1 file changed, 11 insertions(+)
lib/bb/utils.py +12 -1
@@ -1780,6 +1780,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.
--

2.25.1