blob: 12d04897f3770634c2ff0a6e19befc4b2cf630d2 [file] [log] [blame]
Brad Bishop8ffe1e42016-02-11 16:15:40 -05001# Contributors Listed Below - COPYRIGHT 2016
2# [+] International Business Machines Corp.
3#
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14# implied. See the License for the specific language governing
15# permissions and limitations under the License.
16
Brad Bishopb00a9892016-09-19 10:58:46 -040017def org_dot_openbmc_match_strings(sep='.', prefix=''):
Brad Bishop91ae8f92016-09-08 21:21:44 -040018 matches = [
19 ['org', 'openbmc'],
Brad Bishop25af4ba2016-09-15 15:37:02 -040020 ['xyz', 'openbmc_project'],
Brad Bishop91ae8f92016-09-08 21:21:44 -040021 ]
Brad Bishop25af4ba2016-09-15 15:37:02 -040022
Brad Bishopb00a9892016-09-19 10:58:46 -040023 return [prefix + sep.join(y) for y in matches]
Brad Bishop25af4ba2016-09-15 15:37:02 -040024
25
Brad Bishopb00a9892016-09-19 10:58:46 -040026def org_dot_openbmc_match(name, sep='.', prefix=''):
27 names = org_dot_openbmc_match_strings(sep=sep, prefix=prefix)
Brad Bishop91ae8f92016-09-08 21:21:44 -040028 return any(
Brad Bishopbf720472016-09-19 10:34:23 -040029 [x in name or name in x for x in names])
Brad Bishop8ffe1e42016-02-11 16:15:40 -050030
31
32class ListMatch(object):
33 def __init__(self, l):
34 self.l = l
35
36 def __call__(self, match):
37 return match in self.l
38
39
40def find_case_insensitive(value, lst):
41 return next((x for x in lst if x.lower() == value.lower()), None)
42
43
44def makelist(data):
45 if isinstance(data, list):
46 return data
47 elif data:
48 return [data]
49 else:
50 return []