def migrate_configuration(source_version, target_version, config, migration_class):
 upgraded_config = config
 current_version = source_version
 migrations_sequence = []
 for upgrade_version in range((source_version + 1), (target_version + 1)):
  with _LOG_UPGRADE(configuration=upgraded_config, source_version=current_version, target_version=upgrade_version):
   migration_method = (u'upgrade_from_v%d' % current_version)
   migration = getattr(migration_class, migration_method, None)
   if (migration is None):
    raise MissingMigrationError(current_version, upgrade_version)
   migrations_sequence.append(migration)
   current_version += 1
 for migration in migrations_sequence:
  upgraded_config = migration(upgraded_config)
 return upgraded_config

def migrate_configuration ( source_version , target_version , config , migration_class ) : upgraded_config = config current_version = source_version migrations_sequence = [ ] for upgrade_version in range ( ( source_version + 1 ) , ( target_version + 1 ) ) : with _LOG_UPGRADE ( configuration = upgraded_config , source_version = current_version , target_version = upgrade_version ) : migration_method = ( u'upgrade_from_v%d' % current_version ) migration = getattr ( migration_class , migration_method , None ) if ( migration is None ) : raise MissingMigrationError ( current_version , upgrade_version ) migrations_sequence . append ( migration ) current_version += 1 for migration in migrations_sequence : upgraded_config = migration ( upgraded_config ) return upgraded_config
migrate a persisted configuration from one version to another in sequential upgrades .