本文整理汇总了Python中pulp.server.db.connection.get_database函数的典型用法代码示例。如果您正苦于以下问题:Python get_database函数的具体用法?Python get_database怎么用?Python get_database使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_database函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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']}})
示例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())
示例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")
示例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())
示例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")
示例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']}})
示例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)
示例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)
示例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)
示例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()
示例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)
示例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)
示例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)
示例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'])