我可以在 d.getVar [Yocto] 上使用正则表达式或通配符吗

发布于 2025-01-15 17:00:01 字数 180 浏览 1 评论 0原文

我希望获取以某个名称开头的所有变量的值。对于我当前的解决方案,我解析 d 并查找所有变量并挑选出以预期名称开头的变量。

但是,我们可以使用正则表达式或通配符吗?

像这样的东西: d.getVar("ALLOWED_RECIPES_%")

期望输出:以 ALLOWED_RECIPE 开头的所有变量的值列表

I am looking to get values of all the variables starting with some name. For my current solution, I parse the d and look for all the variables and pick out the ones starting with expected name.

But instead, can we use regex or wild char.

Something like this: d.getVar("ALLOWED_RECIPES_%")

Expect output: List of values for all variables starting with ALLOWED_RECIPE

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁客 2025-01-22 17:00:01

这是我尝试管理的一个示例:

  • testvars.bb
LICENSE = "CLOSED"

xVARIABLE1 = "1"
yVARIABLE2 = "2"
zVARIABLE3 = "3"
yVARIABLE4 = "4"
VARIABLEp5 = "5"
VARIABLEp6 = "6"

python do_getvars(){
    import re
    variables = list(filter(re.compile(".VARIABLE.").match, [i for i in d]))
    varvalues = {}
    for var in variables:
        varvalues[var] = d.getVar(var)
    bb.warn("Variables: %s" %varvalues)
}

addtask do_getvars

该示例为 .VARIABLE. 创建一个正则表达式,并检查所有 d变量。

之后,它为每个变量及其值创建一个字典。

bitbake testvars -c getvars 的输出:

WARNING: testvars-1.0-r0 do_getvars: Variables: {'zVARIABLE3': '3', 'yVARIABLE2': '2', 'yVARIABLE4': '4', 'xVARIABLE1': '1'}

注意

Bitbake 不提供将多个变量组合在一起的方法,因此直接正则表达式应用程序不可能使用 d .getVar,所以这是我现在能想到的最好的解决方案。

Here is an example I tried to manage:

  • testvars.bb
LICENSE = "CLOSED"

xVARIABLE1 = "1"
yVARIABLE2 = "2"
zVARIABLE3 = "3"
yVARIABLE4 = "4"
VARIABLEp5 = "5"
VARIABLEp6 = "6"

python do_getvars(){
    import re
    variables = list(filter(re.compile(".VARIABLE.").match, [i for i in d]))
    varvalues = {}
    for var in variables:
        varvalues[var] = d.getVar(var)
    bb.warn("Variables: %s" %varvalues)
}

addtask do_getvars

The example creates a regex for .VARIABLE., and it checks for all matches on all d variables.

After that, it creates a dictionary for each variable and its value.

Output of bitbake testvars -c getvars :

WARNING: testvars-1.0-r0 do_getvars: Variables: {'zVARIABLE3': '3', 'yVARIABLE2': '2', 'yVARIABLE4': '4', 'xVARIABLE1': '1'}

NOTE:

Bitbake does not offer a way to get multiple variables together and for that the direct regex application is not possible with d.getVar, so a that is the best solution I can think of right now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文