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

Python connection.get_database函数代码示例

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

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



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

示例1: migrate

def migrate(*args, **kwargs):
    """
    Adds a "checksums" DictField and populates it with the known checksum type and value.

    Templatizes the XML in "repodata".

    :param args:   unused
    :type  args:   list
    :param kwargs: unused
    :type  kwargs: dict
    """
    try:
        ET.register_namespace('rpm', RPM_NAMESPACE)
    except AttributeError:
        # python 2.6 doesn't have the register_namespace function
        ET._namespace_map[RPM_NAMESPACE] = 'rpm'

    db = connection.get_database()
    rpm_collection = db['units_rpm']
    srpm_collection = db['units_srpm']
    drpm_collection = db['units_drpm']

    for rpm in rpm_collection.find({}, ['checksum', 'checksumtype', 'repodata']):
        migrate_rpm_base(rpm_collection, rpm)
    for srpm in srpm_collection.find({}, ['checksum', 'checksumtype', 'repodata']):
        migrate_rpm_base(srpm_collection, srpm)

    migrate_drpms(drpm_collection)
开发者ID:ATIX-AG,项目名称:pulp_rpm,代码行数:28,代码来源:0033_checksums_and_templates.py


示例2: migrate

def migrate(*args, **kwargs):
    """
    Perform the migration as described in this module's docblock.

    :param args:   unused
    :type  args:   list
    :param kwargs: unused
    :type  kwargs: dict
    """
    db = connection.get_database()
    repos = db['repos']
    repo_distributors = db['repo_distributors']
    repo_objects = repos.find({'notes': {'_repo-type': 'rpm-repo'}})
    for repo_object in repo_objects:
        distributors = list(repo_distributors.find({'repo_id': repo_object['repo_id']}))
        _clean_distributors_relative_url(repo_distributors, distributors)
        yum_distributor = _find_yum_distributor(distributors)
        for distributor in distributors:

            if distributor['distributor_type_id'] == 'export_distributor' and \
                    'relative_url' not in distributor['config']:

                if yum_distributor is None:
                    relative_url = repo_object['repo_id']
                else:
                    relative_url = yum_distributor['config']['relative_url']

                distributor['config']['relative_url'] = relative_url

                repo_distributors.update_one({'_id': distributor['_id']},
                                             {'$set': {'config': distributor['config']}})
开发者ID:ATIX-AG,项目名称:pulp_rpm,代码行数:31,代码来源:0025_export_relative_url.py


示例3: 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:maxamillion,项目名称:pulp,代码行数:33,代码来源:test_database.py


示例4: migrate

def migrate(*args, **kwargs):
    """
    Perform the migration as described in this module's docblock.

    :param args:   unused
    :type  args:   list
    :param kwargs: unused
    :type  kwargs: dict
    """
    db = connection.get_database()

    # If 'repo_content_units' is not defined we don't need to do anything
    if 'repo_content_units' not in db.collection_names():
        return

    collection = db['repo_content_units']
    # Don't check whether we should run based on the index as that may have been cleared out
    # by a different migration
    if collection.find_one({'owner_type': {'$exists': True}}):
        remove_duplicates(collection)

        _logger.info("Removing unused fields (owner_type, owner_id) from repo_content_units")
        collection.update({}, {'$unset': {'owner_type': "", 'owner_id': ''}}, multi=True)

    index_info = collection.index_information()
    if "repo_id_-1_unit_type_id_-1_unit_id_-1_owner_type_-1_owner_id_-1" in index_info:
        _logger.info("Dropping the uniqueness index that included the owner_type & owner_id")
        collection.drop_index("repo_id_-1_unit_type_id_-1_unit_id_-1_owner_type_-1_owner_id_-1")
开发者ID:BrnoPCmaniak,项目名称:pulp,代码行数:28,代码来源:0016_remove_repo_content_unit_owner_type_and_id.py


示例5: 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


示例6: migrate

def migrate(*args, **kwargs):
    """
    Perform the migration as described in this module's docblock.

    :param args:   unused
    :type  args:   list
    :param kwargs: unused
    :type  kwargs: dict
    """
    db = connection.get_database()

    collection = db["units_distribution"]
    collection.update({}, {"$rename": {"id": "distribution_id"}})
    _drop_and_silence_exception(collection, "id_1")
    _drop_and_silence_exception(collection, "id_1_family_1_variant_1_version_1_arch_1")

    collection = db["units_erratum"]
    collection.update({}, {"$rename": {"id": "errata_id"}})
    collection.update({}, {"$rename": {"from": "errata_from"}})
    _drop_and_silence_exception(collection, "id_1")

    collection = db["units_package_group"]
    collection.update({}, {"$rename": {"id": "package_group_id"}})
    _drop_and_silence_exception(collection, "id_1")
    _drop_and_silence_exception(collection, "id_1_repo_id_1")

    collection = db["units_package_category"]
    collection.update({}, {"$rename": {"id": "package_category_id"}})
    _drop_and_silence_exception(collection, "id_1")
    _drop_and_silence_exception(collection, "id_1_repo_id_1")

    collection = db["units_package_environment"]
    collection.update({}, {"$rename": {"id": "package_environment_id"}})
    _drop_and_silence_exception(collection, "id_1")
    _drop_and_silence_exception(collection, "id_1_repo_id_1")
开发者ID:goosemania,项目名称:pulp_rpm,代码行数:35,代码来源:0022_rename_unit_id_fields.py


示例7: migrate

def migrate(*args, **kwargs):
    """
    Perform the migration as described in this module's docblock.

    :param args:   unused
    :type  args:   list
    :param kwargs: unused
    :type  kwargs: dict
    """
    db = connection.get_database()
    errata_collection = db['units_erratum']

    for erratum in errata_collection.find({'pushcount': {'$type': 10}}, {'pushcount': 1}):
        errata_collection.update({'_id': erratum['_id']}, {'$unset': {'pushcount': ""}})

    for erratum in errata_collection.find({'pushcount': {'$exists': True}}, {'pushcount': 1}):
        changed = False
        if not isinstance(erratum['pushcount'], basestring):
            if isinstance(erratum['pushcount'], float):
                erratum['pushcount'] = int(erratum['pushcount'])
            if isinstance(erratum['pushcount'], int):
                changed = True
                erratum['pushcount'] = str(erratum['pushcount'])
        if changed:
            errata_collection.update({'_id': erratum['_id']},
                                     {'$set': {'pushcount': erratum['pushcount']}})
开发者ID:ATIX-AG,项目名称:pulp_rpm,代码行数:26,代码来源:0024_errata_pushcount_string.py


示例8: _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


示例9: migrate

def migrate(*args, **kwargs):
    """
    Compress the content of repodata field for RPM and SRPM units.
    Migration can be safely re-run multiple times.

    :param args:   unused
    :type  args:   list
    :param kwargs: unused
    :type  kwargs: dict
    """
    db = connection.get_database()
    rpm_collection = db['units_rpm']
    srpm_collection = db['units_srpm']

    total_rpm_units = rpm_collection.count()
    total_srpm_units = srpm_collection.count()

    msg = '* NOTE: This migration may take some time depending on the size of your Pulp content. *'
    stars = '*' * len(msg)
    progress_msg = '* Migrated units: %s of %s'

    _logger.info(stars)
    _logger.info(msg)
    _logger.info(stars)

    if total_rpm_units:
        _logger.info('* Migrating RPM content...')

    migrated_units = 0
    for rpm in rpm_collection.find({}, ['repodata']).batch_size(100):
        migrate_rpm_base(rpm_collection, rpm)

        migrated_units += 1
        another_ten_percent_completed = total_rpm_units >= 10 and \
            not migrated_units % (total_rpm_units // 10)
        all_units_migrated = migrated_units == total_rpm_units
        if another_ten_percent_completed or all_units_migrated:
            _logger.info(progress_msg % (migrated_units, total_rpm_units))

    if total_srpm_units:
        _logger.info('* Migrating SRPM content...')

    migrated_units = 0
    for srpm in srpm_collection.find({}, ['repodata']).batch_size(100):
        migrate_rpm_base(srpm_collection, srpm)

        migrated_units += 1
        another_ten_percent_completed = total_srpm_units >= 10 and \
            not migrated_units % (total_srpm_units // 10)
        all_units_migrated = migrated_units == total_srpm_units
        if another_ten_percent_completed or all_units_migrated:
            _logger.info(progress_msg % (migrated_units, total_srpm_units))

    _logger.info(stars)
开发者ID:ATIX-AG,项目名称:pulp_rpm,代码行数:54,代码来源:0039_gzip_repodata.py


示例10: migrate

def migrate(*args, **kwargs):
    """
    Ensure all content units have the _last_updated attribute.
    """
    database = connection.get_database()
    for name in database.collection_names():
        if not name.startswith(TYPE_COLLECTION_PREFIX):
            continue
        collection = connection.get_collection(name)
        for unit in collection.find(QUERY):
            unit[LAST_UPDATED] = NEVER
            collection.save(unit)
开发者ID:jeremycline,项目名称:pulp,代码行数:12,代码来源:0005_unit_last_updated.py


示例11: migrate

def migrate(*args, **kwargs):
    """
    Perform the migration as described in this module's docblock.

    :param args:   unused
    :type  args:   list
    :param kwargs: unused
    :type  kwargs: dict
    """
    db = connection.get_database()
    collection = db['celery_taskmeta']
    collection.drop()
开发者ID:BrnoPCmaniak,项目名称:pulp,代码行数:12,代码来源:0020_drop_celery_taskmeta.py


示例12: migrate

def migrate(*args, **kwargs):
    """
    Perform the migration as described in this module's docblock.

    :param args:   unused
    :type  args:   list
    :param kwargs: unused
    :type  kwargs: dict
    """
    db = connection.get_database()
    collection = db['repos']
    collection.drop_index("id_-1")
    collection.update({}, {"$rename": {"id": "repo_id"}}, multi=True)
开发者ID:BrnoPCmaniak,项目名称:pulp,代码行数:13,代码来源:0019_repo_collection_id.py


示例13: migrate

def migrate(*args, **kwargs):
    """
    Perform the migration as described in this module's docblock.

    :param args:   unused
    :type  args:   list
    :param kwargs: unused
    :type  kwargs: dict
    """
    db = connection.get_database()
    collection = db['repo_importers']
    collection.update({}, {"$unset": {"id": True}}, multi=True)
    collection.drop_index("repo_id_-1_id_-1")
    collection.update({}, {"$unset": {"scheduled_syncs": ""}}, multi=True)
开发者ID:BrnoPCmaniak,项目名称:pulp,代码行数:14,代码来源:0021_remove_extra_importer_fields.py


示例14: migrate

def migrate(*args, **kwargs):
    """
    Perform the migration as described in this module's docblock.

    :param args:   unused
    :type  args:   list
    :param kwargs: unused
    :type  kwargs: dict
    """
    db = connection.get_database()
    repos_collection = db['repos']
    for repo in repos_collection.find():
        repo_id = repo['repo_id']
        rebuild_content_unit_counts(db, repo_id)
开发者ID:BrnoPCmaniak,项目名称:pulp_rpm,代码行数:14,代码来源:0031_regenerate_repo_unit_counts.py


示例15: migrate

def migrate(*args, **kwargs):
    """
    Perform the migration as described in this module's docblock.

    :param args:   unused
    :type  args:   list
    :param kwargs: unused
    :type  kwargs: dict
    """
    db = connection.get_database()

    fix_translated_fields_string_to_dict(db['units_package_category'])
    fix_translated_fields_string_to_dict(db['units_package_environment'])
    fix_translated_fields_string_to_dict(db['units_package_group'])
开发者ID:ATIX-AG,项目名称:pulp_rpm,代码行数:14,代码来源:0023_fix_translated_fields_type.py


示例16: migrate

def migrate(*args, **kwargs):
    """
    Clean up duplicated collections in erratum pkglist.

    :param args:   unused
    :type  args:   list
    :param kwargs: unused
    :type  kwargs: dict
    """
    db = connection.get_database()
    erratum_collection = db['units_erratum']

    for erratum in erratum_collection.find({}, ['pkglist']).batch_size(100):
        migrate_erratum(erratum_collection, erratum)
开发者ID:ATIX-AG,项目名称:pulp_rpm,代码行数:14,代码来源:0038_errata_pkglist_duplicates_cleanup.py


示例17: migrate

def migrate(*args, **kwargs):
    """
    Perform the migration as described in this module's docblock.

    :param args:   unused
    :type  args:   list
    :param kwargs: unused
    :type  kwargs: dict
    """
    db = connection.get_database()
    collection = db['units_rpm']
    collection.update(
        {"checksum_type": {"$exists": True}},
        {"$unset": {"checksum_type": True}},
        multi=True)
开发者ID:ATIX-AG,项目名称:pulp_rpm,代码行数:15,代码来源:0027_remove_checksum_type_field.py


示例18: get_mongo_conn_status

def get_mongo_conn_status():
    """
    Perform a simple mongo operation and return success or failure.

    This uses a "raw" pymongo Collection to avoid any auto-retry logic.

    :returns:          mongo connection status
    :rtype:            bool
    """
    try:
        db = connection.get_database()
        db.workers.count()
        return {'connected': True}
    except:
        return {'connected': False}
开发者ID:BrnoPCmaniak,项目名称:pulp,代码行数:15,代码来源:status.py


示例19: migrate

def migrate(*args, **kwargs):
    """
    Perform the migration as described in this module's docblock.

    :param args:   unused
    :type  args:   list
    :param kwargs: unused
    :type  kwargs: dict
    """
    db = connection.get_database()
    units_drpm_collection = db['units_drpm']
    units_drpm_collection.update(
        {'relativepath': {'$exists': True}},
        {'$unset': {'relativepath': True}},
        multi=True
    )
开发者ID:ATIX-AG,项目名称:pulp_rpm,代码行数:16,代码来源:0035_remove_drpm_relativepath_field.py


示例20: rebuild_content_unit_counts

def rebuild_content_unit_counts(repository):
    """
    Update the content_unit_counts field on a Repository.

    :param repository: The repository to update
    :type repository: pulp.server.db.model.Repository
    """
    db = connection.get_database()

    pipeline = [{"$match": {"repo_id": repository.repo_id}}, {"$group": {"_id": "$unit_type_id", "sum": {"$sum": 1}}}]
    q = db.command("aggregate", "repo_content_units", pipeline=pipeline)

    # Flip this into the form that we need
    counts = {}
    for result in q["result"]:
        counts[result["_id"]] = result["sum"]

    # Use the raw query since there is currently a conflict with the id and the repo_id fields
    model.Repository.objects(__raw__={"id": repository.repo_id}).update_one(set__content_unit_counts=counts)
开发者ID:credativ,项目名称:pulp,代码行数:19,代码来源:repository.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python connection.initialize函数代码示例发布时间:2022-05-25
下一篇:
Python connection.get_collection函数代码示例发布时间: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