Пример #1
0
 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)))
Пример #2
0
    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)))