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


Python factory.content_query_manager函数代码示例

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


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

示例1: get

    def get(self, request, type_id):
        """
        Return a response containing a dict with info about a content type.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param type_id: type of content unit
        :type  type_id: str

        :return: response containing a dict that contains info about a content type or
                 404 response if the specified content type is not found.
        :rtype : django.http.HttpResponse or HttpResponseNotFound
        """
        cqm = factory.content_query_manager()
        content_type = cqm.get_content_type(type_id)
        if content_type is None:
            msg = _('No content type resource: %(r)s') % {'r': type_id}
            return generate_json_response(msg, response_class=HttpResponseNotFound)
        resource = serialization.content.content_type_obj(content_type)
        # These urls are not valid endpoints but are left here for for semantic versioning.
        # BZ - 1187287
        links = {
            'actions': {'_href': '/'.join([request.get_full_path().rstrip('/'), 'actions/'])},
            'content_units': {'_href': '/'.join([request.get_full_path().rstrip('/'), 'units/'])}
        }
        resource.update(links)
        return generate_json_response_with_pulp_encoder(resource)
开发者ID:beav,项目名称:pulp,代码行数:27,代码来源:content.py

示例2: search_all_units

    def search_all_units(self, type_id, criteria):
        """
        Searches for units of a given type in the server, regardless of their
        associations to any repositories.

        @param type_id: indicates the type of units being retrieved
        @type  type_id: str
        @param criteria: used to query which units are returned
        @type  criteria: pulp.server.db.model.criteria.Criteria

        @return: list of unit instances
        @rtype:  list of L{Unit}
        """

        try:
            query_manager = manager_factory.content_query_manager()
            units = query_manager.find_by_criteria(type_id, criteria)
            type_def = types_db.type_definition(type_id)

            transfer_units = []
            for pulp_unit in units:
                u = common_utils.to_plugin_unit(pulp_unit, type_def)
                transfer_units.append(u)

            return transfer_units

        except Exception, e:
            _LOG.exception('Exception from server requesting all units of type [%s]' % type_id)
            raise self.exception_class(e), None, sys.exc_info()[2]
开发者ID:signull,项目名称:pulp,代码行数:29,代码来源:mixins.py

示例3: delete_orphans_by_id

    def delete_orphans_by_id(self, orphans):
        """
        Delete a list of orphaned content units by their content type and unit ids.
        @param orphans: list of documents with 'content_type' and 'content_id' keys
        @type  orphans: list
        """
        # XXX this does no validation of the orphans

        # munge the orphans into something more programmatic-ly convenient
        orphans_by_id = {}
        for o in orphans:
            if 'content_type_id' not in o or 'unit_id' not in o:
                raise pulp_exceptions.InvalidValue(['content_type_id', 'unit_id'])
            id_list = orphans_by_id.setdefault(o['content_type_id'], [])
            id_list.append(o['unit_id'])

        # iterate through the types and ids
        content_query_manager = manager_factory.content_query_manager()
        for content_type, content_id_list in orphans_by_id.items():

            # build a list of the on-disk contents
            orphaned_paths = []
            for unit_id in content_id_list:
                content_unit = content_query_manager.get_content_unit_by_id(content_type, unit_id, model_fields=['_storage_path'])
                if content_unit['_storage_path'] is not None:
                    orphaned_paths.append(content_unit['_storage_path'])

            # remove the orphans from the db
            collection = content_types_db.type_units_collection(content_type)
            spec = {'_id': {'$in': content_id_list}}
            collection.remove(spec, safe=True)

            # delete the on-disk contents
            for path in orphaned_paths:
                self.delete_orphaned_file(path)
开发者ID:ehelms,项目名称:pulp,代码行数:35,代码来源:orphan.py

示例4: GET

 def GET(self, type_id):
     """
     List all the available content units.
     """
     cqm = factory.content_query_manager()
     units = cqm.find_by_criteria(type_id, Criteria())
     return self.ok([self.process_unit(unit) for unit in units])
开发者ID:jlsherrill,项目名称:pulp,代码行数:7,代码来源:contents.py

示例5: test_syntactic_sugar_methods

    def test_syntactic_sugar_methods(self):
        """
        Tests the syntactic sugar methods for retrieving specific managers.
        """
        # Setup
        factory.initialize()

        # Test
        self.assertTrue(isinstance(factory.authentication_manager(), AuthenticationManager))
        self.assertTrue(isinstance(factory.cert_generation_manager(), CertGenerationManager))
        self.assertTrue(isinstance(factory.certificate_manager(), CertificateManager))
        self.assertTrue(isinstance(factory.password_manager(), PasswordManager))
        self.assertTrue(isinstance(factory.permission_manager(), PermissionManager))
        self.assertTrue(isinstance(factory.permission_query_manager(), PermissionQueryManager))
        self.assertTrue(isinstance(factory.role_manager(), RoleManager))
        self.assertTrue(isinstance(factory.role_query_manager(), RoleQueryManager))
        self.assertTrue(isinstance(factory.user_manager(), UserManager))
        self.assertTrue(isinstance(factory.user_query_manager(), UserQueryManager))
        self.assertTrue(isinstance(factory.repo_manager(), RepoManager))
        self.assertTrue(isinstance(factory.repo_unit_association_manager(),
                                   RepoUnitAssociationManager))
        self.assertTrue(isinstance(factory.repo_publish_manager(), RepoPublishManager))
        self.assertTrue(isinstance(factory.repo_query_manager(), RepoQueryManager))
        self.assertTrue(isinstance(factory.repo_sync_manager(), RepoSyncManager))
        self.assertTrue(isinstance(factory.content_manager(), ContentManager))
        self.assertTrue(isinstance(factory.content_query_manager(), ContentQueryManager))
        self.assertTrue(isinstance(factory.content_upload_manager(), ContentUploadManager))
        self.assertTrue(isinstance(factory.consumer_manager(), ConsumerManager))
        self.assertTrue(isinstance(factory.topic_publish_manager(), TopicPublishManager))
开发者ID:credativ,项目名称:pulp,代码行数:29,代码来源:test_factory.py

示例6: __unit_ids_to_plugin_unit_keys

    def __unit_ids_to_plugin_unit_keys(self, unit_ids_by_type, repo_ids):
        """
        Parse a dictionary of unit ids keyed by content type id and return a dictionary of 
        corresponding plugin unit keys keyed by content type id.

        :param unit_ids_by_type: dictionary of <content type id> : <list of unit ids>
        :type unit_ids_by_type: dict

        :return: if units are specified, return the corresponding plugin unit_keys. If unit_ids_by_type dict
                 is empty, return plugin unit keys corresponging to all units in given repo ids.
                 If unit ids list for a particular unit type is empty, return all plugin unit_keys
                 in given repo ids with that unit type.
        :rtype: dict
        """
        repo_unit_association_query_manager = managers.repo_unit_association_query_manager()
        content_query_manager = managers.content_query_manager()

        result_unit_keys = {}

        if unit_ids_by_type is not None:
            for unit_type_id, unit_ids in unit_ids_by_type.items():
                # Get unit type specific collection
                collection = content_query_manager.get_content_unit_collection(type_id=unit_type_id)
                type_def = content_types_db.type_definition(unit_type_id)
                if not unit_ids:
                    # If unit_list is empty for a unit_type, consider all units of specific type
                    criteria = UnitAssociationCriteria(unit_fields = ['unit_id'])
                    for repo_id in repo_ids:
                        repo_units = repo_unit_association_query_manager.get_units_by_type(repo_id, unit_type_id, criteria)
                        # Get metadata for each unit from type specific collection
                        pulp_units = [collection.find_one({'_id': u['unit_id']}) for u in repo_units]
                        # Convert pulp units to plugin unit keys
                        plugin_unit_keys = [common_utils.to_plugin_unit(u, type_def).unit_key for u in pulp_units]
                        result_unit_keys.setdefault(unit_type_id, []).extend(plugin_unit_keys)
                else:
                    # Get metadata for each unit from type specific collection
                    pulp_units = [collection.find_one({'_id': unit_id}) for unit_id in unit_ids]
                    # Convert pulp units to plugin unit keys
                    plugin_unit_keys = [common_utils.to_plugin_unit(u, type_def).unit_key for u in pulp_units]
                    result_unit_keys.setdefault(unit_type_id, []).extend(plugin_unit_keys)
        else:
            # If units are not specified, consider all units in given repos.
            for repo_id in repo_ids:
                all_unit_type_ids = content_types_db.all_type_ids()
                for unit_type_id in all_unit_type_ids:
                    criteria = UnitAssociationCriteria(type_ids=[unit_type_id], unit_fields = ['unit_id', 'unit_type_id'])
                    repo_units = repo_unit_association_query_manager.get_units(repo_id, criteria)

                    # Get unit metadata for each unit from type specific collection
                    collection = content_query_manager.get_content_unit_collection(type_id=unit_type_id)
                    pulp_units = [collection.find_one({'_id': u['unit_id']}) for u in repo_units]
  
                    # Convert pulp units to plugin unit keys
                    type_def = content_types_db.type_definition(unit_type_id)
                    plugin_unit_keys = [common_utils.to_plugin_unit(u, type_def).unit_key for u in pulp_units]
                    result_unit_keys.setdefault(unit_type_id, []).extend(plugin_unit_keys)

        return result_unit_keys
开发者ID:bartwo,项目名称:pulp,代码行数:58,代码来源:applicability.py

示例7: __parse_units

    def __parse_units(self, user_units, repo_ids):
        """
        Parse units specified by user and return a dictionary of all plugin unit_keys 
        to be considered for applicability keyed by unit_type_id.

        :param user_units: dictionary of unit metadata filters keyed by unit-type-id specified by user
        :type user_units: dict

        :return: if specific units are specified, return the corresponding plugin unit_keys. If units dict is empty, 
                 return all plugin unit_keys corresponging to units in given repo ids keyed by unit_type_id. 
                 If units list for a particular unit type in units is empty, return all plugin unit_keys 
                 in given repo ids with that unit type keyed by unit_type_id.
        :rtype: dict
        """
        repo_unit_association_query_manager = managers.repo_unit_association_query_manager()
        content_query_manager = managers.content_query_manager()

        result_unit_keys = {}
        if user_units is not None:
            for unit_type_id, unit_list in user_units.items():
                # Get unit type specific collection
                collection = content_query_manager.get_content_unit_collection(type_id=unit_type_id)
                type_def = content_types_db.type_definition(unit_type_id)
                if not unit_list:
                    # If unit_list is empty for a unit_type, consider all units of specific type
                    criteria = UnitAssociationCriteria(unit_fields = ['unit_id'])
                    for repo_id in repo_ids:
                        repo_units = repo_unit_association_query_manager.get_units_by_type(repo_id, unit_type_id, criteria)
                        # Get unit metadata for each unit from type specific collection
                        pulp_units = [collection.find_one({'_id': u['unit_id']}) for u in repo_units]
                        plugin_units = [common_utils.to_plugin_unit(u, type_def) for u in pulp_units]
                        plugin_unit_keys = [u.unit_key for u in plugin_units]
                        result_unit_keys.setdefault(unit_type_id, []).extend(plugin_unit_keys)
                else:
                    for unit in unit_list:
                        criteria = UnitAssociationCriteria(unit_filters=unit, unit_fields = ['unit_id'])
                        for repo_id in repo_ids:
                            repo_units = repo_unit_association_query_manager.get_units_by_type(repo_id, unit_type_id, criteria)
                            # Get unit metadata for each unit from type specific collection
                            pulp_units = [collection.find_one({'_id': u['unit_id']}) for u in repo_units]
                            plugin_units = [common_utils.to_plugin_unit(u, type_def) for u in pulp_units]
                            plugin_unit_keys = [u.unit_key for u in plugin_units]
                            result_unit_keys.setdefault(unit_type_id, []).extend(plugin_unit_keys)
        else:
            # If units are not specified, consider all units in repo_ids list.
            for repo_id in repo_ids:
                criteria = UnitAssociationCriteria(unit_fields = ['unit_id','unit_type_id'])
                repo_units = repo_unit_association_query_manager.get_units(repo_id, criteria)
                # Get unit metadata for each unit from type specific collection
                for repo_unit in repo_units:
                    collection = content_query_manager.get_content_unit_collection(type_id=repo_unit['unit_type_id'])
                    type_def = content_types_db.type_definition(repo_unit['unit_type_id'])
                    pulp_unit = collection.find_one({'_id': repo_unit['unit_id']})
                    plugin_unit = common_utils.to_plugin_unit(pulp_unit, type_def)
                    result_unit_keys.setdefault(repo_unit['unit_type_id'], []).append(plugin_unit.unit_key)

        return result_unit_keys
开发者ID:domcleal,项目名称:pulp,代码行数:57,代码来源:applicability.py

示例8: delete_all_orphans

    def delete_all_orphans(self):
        """
        Delete all orphaned content units.
        """

        # iterate through the types and delete all orphans of each type
        content_query_manager = manager_factory.content_query_manager()
        content_types = content_query_manager.list_content_types()
        for content_type in content_types:
            self.delete_orphans_by_type(content_type)
开发者ID:ehelms,项目名称:pulp,代码行数:10,代码来源:orphan.py

示例9: unassociate_all_by_ids

    def unassociate_all_by_ids(self, repo_id, unit_type_id, unit_id_list, owner_type, owner_id):
        """
        Removes the association between a repo and a number of units. Only the
        association made by the given owner will be removed. It is possible the
        repo will still have a manually created association will for the unit.

        @param repo_id: identifies the repo
        @type  repo_id: str

        @param unit_type_id: identifies the type of units being removed
        @type  unit_type_id: str

        @param unit_id_list: list of unique identifiers for units within the given type
        @type  unit_id_list: list of str

        @param owner_type: category of the caller who created the association;
                           must be one of the OWNER_* variables in this module
        @type  owner_type: str

        @param owner_id: identifies the caller who created the association, either
                         the importer ID or user login
        @type  owner_id: str
        """
        spec = {'repo_id' : repo_id,
                'unit_type_id' : unit_type_id,
                'unit_id' : {'$in' : unit_id_list},
                'owner_type' : owner_type,
                'owner_id' : owner_id,
                }

        unit_coll = RepoContentUnit.get_collection()
        unit_coll.remove(spec, safe=True)

        unique_count = sum(1 for unit_id in unit_id_list
            if not self.association_exists(repo_id, unit_id, unit_type_id))

        # update the count of associated units on the repo object
        if unique_count:
            manager_factory.repo_manager().update_unit_count(
                repo_id, -unique_count)

        try:
            repo_query_manager = manager_factory.repo_query_manager()
            repo = repo_query_manager.get_repository(repo_id)

            content_query_manager = manager_factory.content_query_manager()
            content_units = content_query_manager.get_multiple_units_by_ids(unit_type_id, unit_id_list)

            importer_manager = manager_factory.repo_importer_manager()
            importer = importer_manager.get_importer(repo_id)

            importer.remove_units(repo, content_units)
        except:
            _LOG.exception('Exception informing importer for [%s] of unassociation' % repo_id)
开发者ID:stpierre,项目名称:pulp,代码行数:54,代码来源:unit_association.py

示例10: GET

 def GET(self, type_id, unit_id):
     """
     Return information about a content unit.
     """
     cqm = factory.content_query_manager()
     try:
         unit = cqm.get_content_unit_by_id(type_id, unit_id)
     except MissingResource:
         return self.not_found(_("No content unit resource: %(r)s") % {"r": unit_id})
     resource = serialization.content.content_unit_obj(unit)
     resource.update({"children": serialization.content.content_unit_child_link_objs(resource)})
     return self.ok(resource)
开发者ID:lzap,项目名称:pulp,代码行数:12,代码来源:contents.py

示例11: init_unit

    def init_unit(self, type_id, unit_key, metadata, relative_path):
        """
        Initializes the Pulp representation of a content unit. The conduit will
        use the provided information to generate any unit metadata that it needs
        to. A populated transfer object representation of the unit will be
        returned from this call. The returned unit should be used in subsequent
        calls to this conduit.

        This call makes no changes to the Pulp server. At the end of this call,
        the unit's id field will *not* be populated.

        The unit_key and metadata will be merged as they are saved in Pulp to
        form the full representation of the unit. If values are specified in
        both dictionaries, the unit_key value takes precedence.

        If the importer wants to save the bits for the unit, the relative_path
        value should be used to indicate a unique -- with respect to the type
        of unit -- relative path where it will be saved. Pulp will convert this
        into an absolute path on disk where the unit should actually be saved.
        The absolute path is stored in the returned unit object.

        @param type_id: must correspond to a type definition in Pulp
        @type  type_id: str

        @param unit_key: dictionary of whatever fields are necessary to uniquely
                         identify this unit from others of the same type
        @type  unit_key: dict

        @param metadata: dictionary of key-value pairs to describe the unit
        @type  metadata: dict

        @param relative_path: see above; may be None
        @type  relative_path: str, None

        @return: object representation of the unit, populated by Pulp with both
                 provided and derived values
        @rtype:  pulp.plugins.model.Unit
        """

        try:
            # Generate the storage location
            if relative_path is not None:
                content_query_manager = manager_factory.content_query_manager()
                path = content_query_manager.request_content_unit_file_path(type_id, relative_path)
            else:
                path = None
            u = Unit(type_id, unit_key, metadata, path)
            return u
        except Exception, e:
            msg = _('Exception from server requesting unit filename for relative path [%s]')
            msg = msg % relative_path
            _logger.exception(msg)
            raise ImporterConduitException(e), None, sys.exc_info()[2]
开发者ID:BrnoPCmaniak,项目名称:pulp,代码行数:53,代码来源:mixins.py

示例12: __init__

    def __init__(self, repo_id, importer_id):
        RepoScratchPadMixin.__init__(self, repo_id, ImporterConduitException)
        ImporterScratchPadMixin.__init__(self, repo_id, importer_id)
        AddUnitMixin.__init__(self, repo_id, importer_id)
        SingleRepoUnitsMixin.__init__(self, repo_id, ImporterConduitException)
        StatusMixin.__init__(self, importer_id, ImporterConduitException)
        SearchUnitsMixin.__init__(self, ImporterConduitException)

        self._association_manager = manager_factory.repo_unit_association_manager()
        self._content_query_manager = manager_factory.content_query_manager()

        self._removed_count = 0
开发者ID:credativ,项目名称:pulp,代码行数:12,代码来源:repo_sync.py

示例13: test_syntactic_sugar_methods

    def test_syntactic_sugar_methods(self):
        """
        Tests the syntactic sugar methods for retrieving specific managers.
        """

        # Test
        self.assertTrue(isinstance(factory.repo_manager(), RepoManager))
        self.assertTrue(isinstance(factory.repo_unit_association_manager(), RepoUnitAssociationManager))
        self.assertTrue(isinstance(factory.repo_publish_manager(), RepoPublishManager))
        self.assertTrue(isinstance(factory.repo_query_manager(), RepoQueryManager))
        self.assertTrue(isinstance(factory.repo_sync_manager(), RepoSyncManager))
        self.assertTrue(isinstance(factory.content_manager(), ContentManager))
        self.assertTrue(isinstance(factory.content_query_manager(), ContentQueryManager))
        self.assertTrue(isinstance(factory.content_upload_manager(), ContentUploadManager))
        self.assertTrue(isinstance(factory.consumer_manager(), ConsumerManager))
开发者ID:stpierre,项目名称:pulp,代码行数:15,代码来源:test_manager_factory.py

示例14: list_all_orphans

    def list_all_orphans(self):
        """
        List all content units that are not associated with a repository.
        @return: list of content units
        @rtype:  list
        """

        # iterate through all types and get the orphaned units for each
        orphaned_units = []
        content_query_manager = manager_factory.content_query_manager()
        content_types = content_query_manager.list_content_types()
        for content_type in content_types:
            orphaned_units_of_type = self.list_orphans_by_type(content_type)
            orphaned_units.extend(orphaned_units_of_type)
        return orphaned_units
开发者ID:ehelms,项目名称:pulp,代码行数:15,代码来源:orphan.py

示例15: get

    def get(self, request, type_id):
        """
        Return a response with a serialized list of the content units of the specified type.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param type_id: the list of content units will be limited to this type
        :type  type_id: str

        :return: response with a serialized list of dicts, one for each unit of the type.
        :rtype: django.http.HttpResponse
        """
        cqm = factory.content_query_manager()
        all_units = cqm.find_by_criteria(type_id, Criteria())
        all_processed_units = [_process_content_unit(unit, type_id) for unit in all_units]
        return generate_json_response_with_pulp_encoder(all_processed_units)
开发者ID:credativ,项目名称:pulp,代码行数:16,代码来源:content.py


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