• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python content.ContentType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _create_or_update_type

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,代码行数:29,代码来源:database.py


示例2: test_create_or_update_existing_type_collection

    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,代码行数:33,代码来源:test_types_database.py


示例3: test_create_or_update_type_collection

    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,代码行数:27,代码来源:test_types_database.py


示例4: all_type_definitions

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,代码行数:9,代码来源:database.py


示例5: _create_or_update_type

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,代码行数:19,代码来源:database.py


示例6: type_definition

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,代码行数:11,代码来源:database.py


示例7: all_type_ids

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,代码行数:12,代码来源:database.py


示例8: all_type_collection_names

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,代码行数:14,代码来源:database.py


示例9: type_units_unit_key

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,代码行数:16,代码来源:database.py


示例10: clean

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,代码行数:20,代码来源:database.py


示例11: define_plugins

 def define_plugins(self):
     collection = ContentType.get_collection()
     collection.save(dict(id=self.TYPEDEF_ID, unit_key=self.UNIT_KEY.keys()))
开发者ID:maxamillion,项目名称:pulp,代码行数:3,代码来源:test_plugins.py


示例12: define_plugins

 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,代码行数:4,代码来源:test_conduit.py


示例13: _validate_content_type

def _validate_content_type():
    objectdb = ContentType.get_collection()
    reference = ContentType('', '', '', [], [], [])
    return _validate_model(ConsumerHistoryEvent.__name__, objectdb, reference)
开发者ID:ehelms,项目名称:pulp,代码行数:4,代码来源:validate.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python criteria.Criteria类代码示例发布时间:2022-05-25
下一篇:
Python content.ContentCatalog类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap