本文整理汇总了Python中pulp.server.db.model.migration_tracker.MigrationTracker.save方法的典型用法代码示例。如果您正苦于以下问题:Python MigrationTracker.save方法的具体用法?Python MigrationTracker.save怎么用?Python MigrationTracker.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp.server.db.model.migration_tracker.MigrationTracker
的用法示例。
在下文中一共展示了MigrationTracker.save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import save [as 别名]
def create(self, name, version):
"""
Create and return a MigrationTracker with specified name and version.
:param name: The name of the package that the MigrationTracker is tracking.
:type name: str
:param version: The version we want to store on the new MigrationTracker.
:type version: int
:rtype: pulp.server.db.model.migration_tracker.MigrationTracker
"""
new_mt = MigrationTracker(name=name, version=version)
new_mt.save()
return new_mt
示例2: test_save
# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import save [as 别名]
def test_save(self):
# Make sure we are starting off clean
self.assertEquals(MigrationTracker.get_collection().find({}).count(), 0)
# Instantiate a MigrationTracker
mt = MigrationTracker('meaning_of_life', 41)
# At this point there should not be a MigrationTracker in the database
self.assertEquals(mt.get_collection().find({}).count(), 0)
# saving the mt should add it to the DB
mt.save()
self.assertEquals(mt.get_collection().find({}).count(), 1)
mt_bson = mt.get_collection().find_one({'name': 'meaning_of_life'})
self.assertEquals(mt_bson['name'], 'meaning_of_life')
self.assertEquals(mt_bson['version'], 41)
# now let's update the version to 42, the correct meaning of life
mt.version = 42
mt.save()
# see if the updated meaning of life made it to the DB
self.assertEquals(mt.get_collection().find({}).count(), 1)
mt_bson = mt.get_collection().find_one({'name': 'meaning_of_life'})
self.assertEquals(mt_bson['name'], 'meaning_of_life')
self.assertEquals(mt_bson['version'], 42)
示例3: MigrationPackage
# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import save [as 别名]
class MigrationPackage(object):
"""
A wrapper around the migration packages found in pulp.server.db.migrations. Has methods to
retrieve information about the migrations that are found there, and to apply the migrations.
"""
class DuplicateVersions(Exception):
"""
This is raised when a single migration package has two MigrationModules in it that have the
same version.
"""
pass
class MissingVersion(Exception):
"""
This is raised when a migration package has a gap in the MigrationModule versions.
"""
pass
def __init__(self, python_package):
"""
Initialize the MigrationPackage to represent the Python migration package passed in.
:param python_package: The Python package this object should represent
:type python_package: package
"""
self._package = python_package
# This is an object representation of the DB object that keeps track of the migration
# version that has been applied
try:
self._migration_tracker = MigrationTracker.objects().get(name=self.name)
except DoesNotExist:
self._migration_tracker = MigrationTracker(name=self.name)
self._migration_tracker.save()
# Calculate the latest available version
available_versions = self.available_versions
if available_versions:
self.latest_available_version = available_versions[-1]
else:
self.latest_available_version = 0
def apply_migration(self, migration, update_current_version=True):
"""
Apply the migration that is passed in, and update the DB to note the new version that this
migration represents.
:param migration: The migration to apply
:type migration: pulp.server.db.migrate.utils.MigrationModule
:param update_current_version: If True, update the package's current version after
successful application and enforce migration version order.
If False, don't enforce and don't update.
:type update_current_version: bool
"""
if update_current_version and migration.version != self.current_version + 1:
msg = _('Cannot apply migration %(name)s, because the next migration version is '
'%(version)s.')
msg = msg % {'name': migration.name, 'version': self.current_version + 1}
raise Exception(msg)
migration.migrate()
if update_current_version:
self._migration_tracker.version = migration.version
self._migration_tracker.save()
@property
def available_versions(self):
"""
Return a list of the migration versions that are available in this migration package.
:rtype: list
"""
migrations = self.migrations
versions = [migration.version for migration in migrations]
return versions
@property
def current_version(self):
"""
An integer that represents the migration version that the database is currently at.
None means that the migration package has never been run before.
:rtype: int
"""
return self._migration_tracker.version
@property
def migrations(self):
"""
Finds all available migration modules for the MigrationPackage,
and then sorts by the version. Return a list of MigrationModules.
:rtype: list
"""
# Generate a list of the names of the modules found inside this package
module_names = [name for module_loader, name, ispkg in
iter_modules([os.path.dirname(self._package.__file__)])]
migration_modules = []
for module_name in module_names:
try:
module_name = '%s.%s' % (self.name, module_name)
#.........这里部分代码省略.........