1 def read_file(filename
):
3 f
= file( filename
, "r" )
4 except IOError, reason
:
5 return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M:
7 return f
.read().strip()
10 def ifelse(condition
, iftrue
= True, iffalse
= False):
16 def conditional(variable
, checkvalue
, truevalue
, falsevalue
, d
):
17 if bb
.data
.getVar(variable
,d
,1) == checkvalue
:
22 def less_or_equal(variable
, checkvalue
, truevalue
, falsevalue
, d
):
23 if float(bb
.data
.getVar(variable
,d
,1)) <= float(checkvalue
):
28 def version_less_or_equal(variable
, checkvalue
, truevalue
, falsevalue
, d
):
29 result
= bb
.vercmp(bb
.data
.getVar(variable
,d
,True), checkvalue
)
35 def contains(variable
, checkvalues
, truevalue
, falsevalue
, d
):
36 val
= bb
.data
.getVar(variable
,d
,1)
40 if type(checkvalues
).__name
__ == "str":
41 checkvalues
= [checkvalues
]
42 for value
in checkvalues
:
43 if val
.find(value
) != -1:
45 if matches
== len(checkvalues
):
49 def both_contain(variable1
, variable2
, checkvalue
, d
):
50 if bb
.data
.getVar(variable1
,d
,1).find(checkvalue
) != -1 and bb
.data
.getVar(variable2
,d
,1).find(checkvalue
) != -1:
55 def prune_suffix(var
, suffixes
, d
):
56 # See if var ends with any of the suffixes listed and
58 for suffix
in suffixes
:
59 if var
.endswith(suffix
):
60 return var
.replace(suffix
, "")
63 def str_filter(f
, str, d
):
65 return " ".join(filter(lambda x
: match(f
, x
, 0), str.split()))
67 def str_filter_out(f
, str, d
):
69 return " ".join(filter(lambda x
: not match(f
, x
, 0), str.split()))
71 def param_bool(cfg
, field
, dflt
= None):
72 """Lookup <field> in <cfg> map and convert it to a boolean; take
73 <dflt> when this <field> does not exist"""
74 value
= cfg
.get(field
, dflt
)
75 strvalue
= str(value
).lower()
76 if strvalue
in ('yes', 'y', 'true', 't', '1'):
78 elif strvalue
in ('no', 'n', 'false', 'f', '0'):
80 raise ValueError("invalid value for boolean parameter '%s': '%s'" % (field
, value
))