本文整理汇总了Python中Cobalt.Proxy.ComponentProxy.add_resources方法的典型用法代码示例。如果您正苦于以下问题:Python ComponentProxy.add_resources方法的具体用法?Python ComponentProxy.add_resources怎么用?Python ComponentProxy.add_resources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cobalt.Proxy.ComponentProxy
的用法示例。
在下文中一共展示了ComponentProxy.add_resources方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: namesort
# 需要导入模块: from Cobalt.Proxy import ComponentProxy [as 别名]
# 或者: from Cobalt.Proxy.ComponentProxy import add_resources [as 别名]
if opt.sched and opt.nonsched:
print >> sys.stderr, "--sched and --nonsched can't be used together"
sys.exit(1)
def namesort(resource):
"""Helper function to sort by resource name"""
return resource["name"]
# Adding/Removing are single operations (can't set attributes at same time)
if opt.add:
if len(args) == 0:
print >> sys.stderr, "Must specify at least one resource name"
sys.exit(1)
specs = [{"name":name} for name in args]
added = system.add_resources(specs)
added.sort(key=namesort)
if added == "KeyError":
print >> sys.stderr, "One or more of the given names already exist"
sys.exit(1)
for r in added:
print "Added resource with name '%s'" % r["name"]
sys.exit(0)
elif opt.remove:
specs = [{"name":name} for name in args]
removed = system.remove_resources(specs)
removed.sort(key=namesort)
for r in removed:
print "Removed resource with name '%s'" % r["name"]
sys.exit(0)