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


Python ContentType.get_collection方法代码示例

本文整理汇总了Python中pulp.server.db.model.content.ContentType.get_collection方法的典型用法代码示例。如果您正苦于以下问题:Python ContentType.get_collection方法的具体用法?Python ContentType.get_collection怎么用?Python ContentType.get_collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pulp.server.db.model.content.ContentType的用法示例。


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

示例1: test_create_or_update_existing_type_collection

# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import get_collection [as 别名]
    def test_create_or_update_existing_type_collection(self):
        """
        Tests calling create_or_update with a change to an existing type
        collection is successful.
        """

        # Setup
        type_def = TypeDefinition('rpm', 'RPM', 'RPM Packages', ['name'], ['name'], [])
        types_db._create_or_update_type(type_def)

        # Test
        type_def.display_name = 'new-name'
        type_def.description = 'new-description'
        type_def.unit_key = 'new-key'
        type_def.search_indexes = None
        types_db._create_or_update_type(type_def)

        # Verify

        #   Present in types collection
        all_types = list(ContentType.get_collection().find())
        self.assertEqual(1, len(all_types))

        found = all_types[0]
        self.assertEqual(type_def.id, found['id'])
        self.assertEqual(type_def.display_name, found['display_name'])
        self.assertEqual(type_def.description, found['description'])
        self.assertEqual(type_def.unit_key, found['unit_key'])
        self.assertEqual(type_def.search_indexes, found['search_indexes'])

        #   Type collection exists
        collection_name = types_db.unit_collection_name(type_def.id)
        self.assertTrue(collection_name in pulp_db.get_database().collection_names())
开发者ID:ashcrow,项目名称:pulp,代码行数:35,代码来源:test_types_database.py

示例2: _create_or_update_type

# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import get_collection [as 别名]
def _create_or_update_type(type_def):
    """
    This method creates or updates a type definition in MongoDB.

    :param type_def: the type definition to update or create. If a type definition with the same
                     as an existing type, the type is updated, otherwise it is created.
    :type  type_def: ContentType

    :return: This method will always return None
    :rtype:  None
    """
    # Make sure a collection exists for the type
    database = pulp_db.get_database()
    collection_name = unit_collection_name(type_def.id)

    if collection_name not in database.collection_names():
        pulp_db.get_collection(collection_name, create=True)

    # Add or update an entry in the types list
    content_type_collection = ContentType.get_collection()
    content_type = ContentType(
        type_def.id, type_def.display_name, type_def.description, type_def.unit_key,
        type_def.search_indexes, type_def.referenced_types)
    # no longer rely on _id = id
    existing_type = content_type_collection.find_one({'id': type_def.id}, fields=[])
    if existing_type is not None:
        content_type._id = existing_type['_id']
    # XXX this still causes a potential race condition when 2 users are updating the same type
    content_type_collection.save(content_type, safe=True)
开发者ID:hgschmie,项目名称:pulp,代码行数:31,代码来源:database.py

示例3: test_create_or_update_type_collection

# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import get_collection [as 别名]
    def test_create_or_update_type_collection(self):
        """
        Tests the call to create a new type collection works.
        """

        # Setup
        type_def = TypeDefinition('rpm', 'RPM', 'RPM Packages', ['name'], ['name'], [])

        # Test
        types_db._create_or_update_type(type_def)

        # Verify

        #   Present in types collection
        all_types = list(ContentType.get_collection().find())
        self.assertEqual(1, len(all_types))

        found = all_types[0]
        self.assertEqual(type_def.id, found['id'])
        self.assertEqual(type_def.display_name, found['display_name'])
        self.assertEqual(type_def.description, found['description'])
        self.assertEqual(type_def.unit_key, found['unit_key'])
        self.assertEqual(type_def.search_indexes, found['search_indexes'])

        #   Type collection exists
        collection_name = types_db.unit_collection_name(type_def.id)
        self.assertTrue(collection_name in pulp_db.get_database().collection_names())
开发者ID:ashcrow,项目名称:pulp,代码行数:29,代码来源:test_types_database.py

示例4: all_type_definitions

# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import get_collection [as 别名]
def all_type_definitions():
    """
    @return: list of all type definitions in the database (mongo SON objects)
    @rtype:  list of dict
    """

    coll = ContentType.get_collection()
    types = list(coll.find())
    return types
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:11,代码来源:database.py

示例5: type_definition

# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import get_collection [as 别名]
def type_definition(type_id):
    """
    Return a type definition
    @param type_id: unique type id
    @type type_id: str
    @return: corresponding type definition, None if not found
    @rtype: SON or None
    """
    collection = ContentType.get_collection()
    type_ = collection.find_one({'id': type_id})
    return type_
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:13,代码来源:database.py

示例6: all_type_ids

# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import get_collection [as 别名]
def all_type_ids():
    """
    @return: list of IDs for all types currently in the database; empty list
             if there are no IDs in the database
    @rtype:  list of str
    """

    collection = ContentType.get_collection()
    type_id_son = list(collection.find(fields={'id' : 1}))
    type_ids = [t['id'] for t in type_id_son]

    return type_ids
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:14,代码来源:database.py

示例7: all_type_collection_names

# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import get_collection [as 别名]
def all_type_collection_names():
    """
    @return: list of collection names for all types currently in the database
    @rtype:  list of str
    """

    collection = ContentType.get_collection()
    type_ids = list(collection.find(fields={'id' : 1}))

    type_collection_names = []
    for id in type_ids:
        type_collection_names.append(unit_collection_name(id['id']))

    return type_collection_names
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:16,代码来源:database.py

示例8: type_units_unit_key

# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import get_collection [as 别名]
def type_units_unit_key(type_id):
    """
    Get the unit key for a given content type collection. If no type
    definition is found for the given ID, None is returned

    @param type_id: unique content type identifier
    @type type_id: str
    @return: list of indices that can uniquely identify a document in the
             content type collection
    @rtype: list of str or None
    """
    collection = ContentType.get_collection()
    type_def = collection.find_one({'id': type_id})
    if type_def is None:
        return None
    return type_def['unit_key']
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:18,代码来源:database.py

示例9: _create_or_update_type

# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import get_collection [as 别名]
def _create_or_update_type(type_def):

    # Make sure a collection exists for the type
    database = pulp_db.get_database()
    collection_name = unit_collection_name(type_def.id)

    if collection_name not in database.collection_names():
        pulp_db.get_collection(collection_name, create=True)

    # Add or update an entry in the types list
    content_type_collection = ContentType.get_collection()
    content_type = ContentType(type_def.id, type_def.display_name, type_def.description,
                               type_def.unit_key, type_def.search_indexes, type_def.referenced_types)
    # no longer rely on _id = id
    existing_type = content_type_collection.find_one({'id': type_def.id}, fields=[])
    if existing_type is not None:
        content_type._id = existing_type['_id']
    # XXX this still causes a potential race condition when 2 users are updating the same type
    content_type_collection.save(content_type, safe=True)
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:21,代码来源:database.py

示例10: clean

# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import get_collection [as 别名]
def clean():
    """
    Purges the database of all types and their associated collections. This
    isn't really meant to be run from Pulp server code but rather as a utility
    for test cases.
    """

    LOG.info('Purging the database of all content type definitions and collections')

    # Search the database instead of just going on what's in the type listing
    # just in case they got out of sync
    database = pulp_db.get_database()
    all_collection_names = database.collection_names()
    type_collection_names = [n for n in all_collection_names if n.startswith(TYPE_COLLECTION_PREFIX)]
    for drop_me in type_collection_names:
        database[drop_me].drop()

    # Purge the types collection of all entries
    type_collection = ContentType.get_collection()
    type_collection.remove(safe=True)
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:22,代码来源:database.py

示例11: define_plugins

# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import get_collection [as 别名]
 def define_plugins(self):
     collection = ContentType.get_collection()
     collection.save(dict(id=self.TYPEDEF_ID, unit_key=self.UNIT_KEY.keys()))
开发者ID:maxamillion,项目名称:pulp,代码行数:5,代码来源:test_plugins.py

示例12: define_plugins

# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import get_collection [as 别名]
 def define_plugins(self):
     collection = ContentType.get_collection()
     for type_id in ALL_TYPES:
         collection.save(dict(id=type_id, unit_key=UNIT_METADATA.keys()), safe=True)
开发者ID:pombreda,项目名称:pulp,代码行数:6,代码来源:test_conduit.py

示例13: _validate_content_type

# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import get_collection [as 别名]
def _validate_content_type():
    objectdb = ContentType.get_collection()
    reference = ContentType('', '', '', [], [], [])
    return _validate_model(ConsumerHistoryEvent.__name__, objectdb, reference)
开发者ID:ehelms,项目名称:pulp,代码行数:6,代码来源:validate.py


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