本文整理汇总了Python中package_relationship.PackageRelationship.make_type_printable方法的典型用法代码示例。如果您正苦于以下问题:Python PackageRelationship.make_type_printable方法的具体用法?Python PackageRelationship.make_type_printable怎么用?Python PackageRelationship.make_type_printable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类package_relationship.PackageRelationship
的用法示例。
在下文中一共展示了PackageRelationship.make_type_printable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_relationships_printable
# 需要导入模块: from package_relationship import PackageRelationship [as 别名]
# 或者: from package_relationship.PackageRelationship import make_type_printable [as 别名]
def get_relationships_printable(self):
"""Returns a list of tuples describing related packages, including
non-direct relationships (such as siblings).
@return: e.g. [(annakarenina, u"is a parent"), ...]
"""
from package_relationship import PackageRelationship
rel_list = []
for rel in self.get_relationships():
if rel.subject == self:
type_printable = PackageRelationship.make_type_printable(rel.type)
rel_list.append((rel.object, type_printable, rel.comment))
else:
type_printable = PackageRelationship.make_type_printable(
PackageRelationship.forward_to_reverse_type(rel.type)
)
rel_list.append((rel.subject, type_printable, rel.comment))
# sibling types
# e.g. 'gary' is a child of 'mum', looking for 'bert' is a child of 'mum'
# i.e. for each 'child_of' type relationship ...
for rel_as_subject in self.get_relationships(direction="forward"):
if rel_as_subject.state != core.State.ACTIVE:
continue
# ... parent is the object
parent_pkg = rel_as_subject.object
# Now look for the parent's other relationships as object ...
for parent_rel_as_object in parent_pkg.get_relationships(direction="reverse"):
if parent_rel_as_object.state != core.State.ACTIVE:
continue
# and check children
child_pkg = parent_rel_as_object.subject
if (
child_pkg != self
and parent_rel_as_object.type == rel_as_subject.type
and child_pkg.state == core.State.ACTIVE
):
type_printable = PackageRelationship.inferred_types_printable["sibling"]
rel_list.append((child_pkg, type_printable, None))
return sorted(list(set(rel_list)))