本文整理汇总了Python中pipeline.Pipeline.get_by_sobject方法的典型用法代码示例。如果您正苦于以下问题:Python Pipeline.get_by_sobject方法的具体用法?Python Pipeline.get_by_sobject怎么用?Python Pipeline.get_by_sobject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pipeline.Pipeline
的用法示例。
在下文中一共展示了Pipeline.get_by_sobject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sort_shot_tasks
# 需要导入模块: from pipeline import Pipeline [as 别名]
# 或者: from pipeline.Pipeline import get_by_sobject [as 别名]
def sort_shot_tasks( tasks):
''' sort task by pipeline. It can be for assets or shots'''
# first sort by pipeline
# get the pipeline of the first task
sobject = tasks[0].get_parent()
if not sobject:
return tasks
pipeline = Pipeline.get_by_sobject(sobject)
if not pipeline:
return tasks
# assign a number value to each process in the pipeline
processes = pipeline.get_process_names()
process_dict = {}
count = 0
for process in processes:
process_dict[process] = count
count += 1
def process_compare(x,y):
x_process = x.get_value("process")
y_process = y.get_value("process")
x_value = process_dict.get(x_process)
y_value = process_dict.get(y_process)
return cmp(x_value, y_value)
tasks.sort(process_compare)
return tasks
示例2: get_by_sobjects
# 需要导入模块: from pipeline import Pipeline [as 别名]
# 或者: from pipeline.Pipeline import get_by_sobject [as 别名]
def get_by_sobjects(sobjects, process=None, order=True):
if not sobjects:
return []
# quickly go through the sobjects to determine if their search types
# are the same
multi_stypes = False
for sobject in sobjects:
if sobject.get_search_type() != sobjects[0].get_search_type():
multi_stypes = True
break
search = Search( Task.SEARCH_TYPE )
if multi_stypes:
# sort this into a dictionary and make multiple calls to
# search.add_relationship_filters
# use the first sobject as a sample
sobjects_dict = {}
for sobject in sobjects:
st = sobject.get_search_type()
sobj_list = sobjects_dict.get(st)
if sobj_list == None:
sobjects_dict[st] = [sobject]
else:
sobj_list.append(sobject)
search.add_op('begin')
for key, sobj_list in sobjects_dict.items():
search.add_op('begin')
search.add_relationship_filters(sobj_list)
search.add_op('and')
search.add_op('or')
else:
from pyasm.biz import Schema
schema = Schema.get()
# FIXME: why doesn't the ops work here?
filters = []
search.add_relationship_filters(sobjects)
"""
for sobject in sobjects:
search_type = sobject.get_search_type()
attrs = schema.get_relationship_attrs("sthpw/task", search_type)
attrs = schema.resolve_relationship_attrs(attrs, "sthpw/task", search_type)
search_code = sobject.get_value(attrs.get("to_col"))
#search_code = sobject.get_value("code")
#search.add_filter('search_type', search_type)
#search.add_filter('search_id', search_id, quoted=False)
#search.add_op("and")
if attrs.get("from_col") == "search_code":
filters.append("search_type = '%s' and search_code = '%s'" % (search_type, search_code))
else:
filters.append("search_type = '%s' and search_id = %s" % (search_type, search_code))
search.add_where(" or ".join(filters))
"""
search.add_order_by("search_type")
search.add_order_by("search_code")
search.add_order_by("search_id")
# get the pipeline of the sobject
pipeline = Pipeline.get_by_sobject(sobject)
if order:
if pipeline:
process_names = pipeline.get_process_names(True)
search.add_enum_order_by("process", process_names)
else:
search.add_order_by("process")
search.add_order_by("id")
if process:
if isinstance(process, basestring):
search.add_filter("process", process)
else:
search.add_filters("process", process)
tasks = search.get_sobjects()
return tasks