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
9 # http://www.apache.org/licenses/LICENSE-2.0
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 implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
20 def cpulist_to_set(cl):
22 for e in cl.split(','):
27 r.update(map(str, range(int(p[0]), int(p[1]) + 1)))
30 def set_to_cpulist(cs):
32 for k, g in itertools.groupby(enumerate(sorted(cs, key=int)), lambda (i, v): int(v) - i):
35 r.append(str(t[0][1]))
37 r.append('-'.join([str(t[0][1]), str(t[-1][1])]))
40 def cpulist_combine(conf, name, lst):
44 r.update(conf[s]['set'])
46 conf[name] = { 'set': sorted(r), 'list': set_to_cpulist(r) }
49 def cmdline_to_list(cmdl):
50 return re.findall('(?:[^" ]|"[^"]*")+', cmdl)
52 def list_to_cmdline(lst):
55 class FilterModule(object):
58 'cpulist_to_set': cpulist_to_set,
59 'set_to_cpulist': set_to_cpulist,
60 'cpulist_combine': cpulist_combine,
61 'cmdline_to_list': cmdline_to_list,
62 'list_to_cmdline': list_to_cmdline