blob: cfde266fbd443cef5fc64f3621fe5ed05946505c [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
17
18class Path:
19 def __init__(self, path):
20 self.parts = filter(bool, path.split('/'))
21
22 def rel(self, first=None, last=None):
23 # relative
24 return self.get('', first, last)
25
26 def fq(self, first=None, last=None):
27 # fully qualified
28 return self.get('/', first, last)
29
30 def depth(self):
31 return len(self.parts)
32
33 def get(self, prefix='/', first=None, last=None):
34 if not first:
35 first = 0
36 if not last:
37 last = self.depth()
38 return prefix + '/'.join(self.parts[first:last])
39
40
41def org_dot_openbmc_match(name):
42 return 'org.openbmc' in name
43
44
45class ListMatch(object):
46 def __init__(self, l):
47 self.l = l
48
49 def __call__(self, match):
50 return match in self.l
51
52
53def find_case_insensitive(value, lst):
54 return next((x for x in lst if x.lower() == value.lower()), None)
55
56
57def makelist(data):
58 if isinstance(data, list):
59 return data
60 elif data:
61 return [data]
62 else:
63 return []