def format_cpu_spec(cpuset, allow_ranges=True):
 if allow_ranges:
  ranges = []
  previndex = None
  for cpuindex in sorted(cpuset):
   if ((previndex is None) or (previndex != (cpuindex - 1))):
    ranges.append([])
   ranges[(-1)].append(cpuindex)
   previndex = cpuindex
  parts = []
  for entry in ranges:
   if (len(entry) == 1):
    parts.append(str(entry[0]))
   else:
    parts.append(('%d-%d' % (entry[0], entry[(len(entry) - 1)])))
  return ','.join(parts)
 else:
  return ','.join((str(id) for id in sorted(cpuset)))

def format_cpu_spec ( cpuset , allow_ranges = True ) : if allow_ranges : ranges = [ ] previndex = None for cpuindex in sorted ( cpuset ) : if ( ( previndex is None ) or ( previndex != ( cpuindex - 1 ) ) ) : ranges . append ( [ ] ) ranges [ ( - 1 ) ] . append ( cpuindex ) previndex = cpuindex parts = [ ] for entry in ranges : if ( len ( entry ) == 1 ) : parts . append ( str ( entry [ 0 ] ) ) else : parts . append ( ( '%d-%d' % ( entry [ 0 ] , entry [ ( len ( entry ) - 1 ) ] ) ) ) return ',' . join ( parts ) else : return ',' . join ( ( str ( id ) for id in sorted ( cpuset ) ) )
format a libvirt cpu range specification .