xref: /openbmc/pyphosphor/obmc/utils/misc.py (revision aea38c65)
1# 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
17
18def org_dot_openbmc_match_strings(sep='.', prefix=''):
19    matches = [
20        ['org', 'openbmc'],
21        ['xyz', 'openbmc_project'],
22    ]
23
24    return [prefix + sep.join(y) for y in matches]
25
26
27def org_dot_openbmc_match(name, sep='.', prefix=''):
28    names = org_dot_openbmc_match_strings(sep=sep, prefix=prefix)
29    return any(
30        [x in name or name in x for x in names])
31
32
33class ListMatch(object):
34    def __init__(self, lst):
35        self.lst = lst
36
37    def __call__(self, match):
38        return match in self.l
39
40
41def find_case_insensitive(value, lst):
42    return next((x for x in lst if x.lower() == value.lower()), None)
43
44
45def makelist(data):
46    if isinstance(data, list):
47            return data
48    elif data:
49            return [data]
50    else:
51            return []
52