代码拉取完成,页面将自动刷新
#!/usr/bin/env python3
#
import argparse
def numbers_set(nlist):
# e.g. 1,2,4-6,20 => 1,2,4,5,6,20
if nlist is None or len(nlist.strip()) == 0:
return set()
nums = []
for n in nlist.strip().split(','):
if '-' in n:
b, e = n.split('-')
nums.extend(list(range(int(b), int(e) + 1)))
else:
nums.append(int(n))
return set(nums)
def args_parser():
comment = ("A simple of parse number list.")
parser = argparse.ArgumentParser(description = comment,
formatter_class =
argparse.RawTextHelpFormatter)
parser.add_argument("-m", dest = "m", action = "store",
help = "memory bind nodes")
parser.add_argument("-c", dest = "c", action = "store",
help = "CPU bind nodes")
parser.add_argument("-N", dest = "N", type = int, action = "store",
default = 8, help = "NUMA nodes")
parser.add_argument("extra", nargs = "*",
help = "extra arguments")
return parser
def usage():
args_parser().parse_args(["-h"])
def parse_args(args_list = None):
args = args_parser().parse_args(args_list)
memnodes = numbers_set(args.m)
if len(memnodes) == 0 and not args.N is None:
memnodes = set(range(0, args.N))
setattr(args, "memnodes", memnodes)
cpunodes = numbers_set(args.c)
if len(cpunodes) == 0 and not args.N is None:
cpunodes = set(range(0, args.N))
setattr(args, "cpunodes", cpunodes)
return args
args = parse_args()
print(args)
result = {}
for c in args.cpunodes:
row = {}
for m in args.memnodes:
# TODO
row[m] = str(c) + str(m)
result[c] = row
# 表头
print("CPU\MEM", end = "")
for m in args.memnodes:
print("\t%d" % m, end = "")
print("")
for k1, v1 in result.items():
# 列头
print("%d" % k1, end = "")
for k2, v2 in v1.items():
print("\t%s" % v2, end = "")
print("")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。