xref: /openbmc/pyphosphor/obmc/utils/misc.py (revision ffe66a91)
18ffe1e44SBrad Bishop# Contributors Listed Below - COPYRIGHT 2016
28ffe1e44SBrad Bishop# [+] International Business Machines Corp.
38ffe1e44SBrad Bishop#
48ffe1e44SBrad Bishop#
58ffe1e44SBrad Bishop# Licensed under the Apache License, Version 2.0 (the "License");
68ffe1e44SBrad Bishop# you may not use this file except in compliance with the License.
78ffe1e44SBrad Bishop# You may obtain a copy of the License at
88ffe1e44SBrad Bishop#
98ffe1e44SBrad Bishop#     http://www.apache.org/licenses/LICENSE-2.0
108ffe1e44SBrad Bishop#
118ffe1e44SBrad Bishop# Unless required by applicable law or agreed to in writing, software
128ffe1e44SBrad Bishop# distributed under the License is distributed on an "AS IS" BASIS,
138ffe1e44SBrad Bishop# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148ffe1e44SBrad Bishop# implied. See the License for the specific language governing
158ffe1e44SBrad Bishop# permissions and limitations under the License.
168ffe1e44SBrad Bishop
17*aea38c65SBrad Bishop
18b00a989bSBrad Bishopdef org_dot_openbmc_match_strings(sep='.', prefix=''):
1991ae8f91SBrad Bishop    matches = [
2091ae8f91SBrad Bishop        ['org', 'openbmc'],
2125af4ba8SBrad Bishop        ['xyz', 'openbmc_project'],
2291ae8f91SBrad Bishop    ]
2325af4ba8SBrad Bishop
24b00a989bSBrad Bishop    return [prefix + sep.join(y) for y in matches]
2525af4ba8SBrad Bishop
2625af4ba8SBrad Bishop
27b00a989bSBrad Bishopdef org_dot_openbmc_match(name, sep='.', prefix=''):
28b00a989bSBrad Bishop    names = org_dot_openbmc_match_strings(sep=sep, prefix=prefix)
2991ae8f91SBrad Bishop    return any(
30bf72047dSBrad Bishop        [x in name or name in x for x in names])
318ffe1e44SBrad Bishop
328ffe1e44SBrad Bishop
338ffe1e44SBrad Bishopdef find_case_insensitive(value, lst):
348ffe1e44SBrad Bishop    return next((x for x in lst if x.lower() == value.lower()), None)
358ffe1e44SBrad Bishop
368ffe1e44SBrad Bishop
378ffe1e44SBrad Bishopdef makelist(data):
388ffe1e44SBrad Bishop    if isinstance(data, list):
398ffe1e44SBrad Bishop            return data
408ffe1e44SBrad Bishop    elif data:
418ffe1e44SBrad Bishop            return [data]
428ffe1e44SBrad Bishop    else:
438ffe1e44SBrad Bishop            return []
44