当前位置: 首页>>代码示例>>Python>>正文


Python package_relationship.PackageRelationship类代码示例

本文整理汇总了Python中package_relationship.PackageRelationship的典型用法代码示例。如果您正苦于以下问题:Python PackageRelationship类的具体用法?Python PackageRelationship怎么用?Python PackageRelationship使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PackageRelationship类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_relationships

 def get_relationships(self, with_package=None, type=None, active=True,
                       direction='both'):
     '''Returns relationships this package has.
     Keeps stored type/ordering (not from pov of self).'''
     assert direction in ('both', 'forward', 'reverse')
     if with_package:
         assert isinstance(with_package, Package)
     from package_relationship import PackageRelationship
     forward_filters = [PackageRelationship.subject==self]
     reverse_filters = [PackageRelationship.object==self]
     if with_package:
         forward_filters.append(PackageRelationship.object==with_package)
         reverse_filters.append(PackageRelationship.subject==with_package)
     if active:
         forward_filters.append(PackageRelationship.state==core.State.ACTIVE)
         reverse_filters.append(PackageRelationship.state==core.State.ACTIVE)
     if type:
         forward_filters.append(PackageRelationship.type==type)
         reverse_type = PackageRelationship.reverse_type(type)
         reverse_filters.append(PackageRelationship.type==reverse_type)
     q = meta.Session.query(PackageRelationship)
     if direction == 'both':
         q = q.filter(or_(
         and_(*forward_filters),
         and_(*reverse_filters),
         ))
     elif direction == 'forward':
         q = q.filter(and_(*forward_filters))
     elif direction == 'reverse':
         q = q.filter(and_(*reverse_filters))
     return q.all()
开发者ID:HatemAlSum,项目名称:ckan,代码行数:31,代码来源:package.py

示例2: get_relationships

    def get_relationships(self, with_package=None, type=None, active=True, direction="both"):
        """Returns relationships this package has.
        Keeps stored type/ordering (not from pov of self)."""
        assert direction in ("both", "forward", "reverse")
        if with_package:
            assert isinstance(with_package, Package)
        from package_relationship import PackageRelationship

        forward_filters = [PackageRelationship.subject == self]
        reverse_filters = [PackageRelationship.object == self]
        if with_package:
            forward_filters.append(PackageRelationship.object == with_package)
            reverse_filters.append(PackageRelationship.subject == with_package)
        if active:
            forward_filters.append(PackageRelationship.state == State.ACTIVE)
            reverse_filters.append(PackageRelationship.state == State.ACTIVE)
        if type:
            forward_filters.append(PackageRelationship.type == type)
            reverse_type = PackageRelationship.reverse_type(type)
            reverse_filters.append(PackageRelationship.type == reverse_type)
        q = Session.query(PackageRelationship)
        if direction == "both":
            q = q.filter(or_(and_(*forward_filters), and_(*reverse_filters)))
        elif direction == "forward":
            q = q.filter(and_(*forward_filters))
        elif direction == "reverse":
            q = q.filter(and_(*reverse_filters))
        return q.all()
开发者ID:jakebarnwell,项目名称:PythonGenerator,代码行数:28,代码来源:package.py

示例3: get_relationships_printable

    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)))
开发者ID:kata-csc,项目名称:ckan,代码行数:39,代码来源:package.py


注:本文中的package_relationship.PackageRelationship类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。