def update(old_version, new_version): """ Called whenever a version change in kolibri is detected """ logger.info("Running update routines for new version...") try: # Check if there are other kolibri instances running # If there are, then we need to stop users from starting kolibri again. get_status() logger.error( "There is a Kolibri server running. " "Running updates now could cause a database error. " "Please use `kolibri stop` and try again. " ) sys.exit(1) except NotRunning: pass _migrate_databases() run_upgrades(old_version, new_version) with open(version_file(), "w") as f: f.write(kolibri.__version__) from django.core.cache import caches cache = caches["built_files"] cache.clear()
def update(old_version, new_version): """ Called whenever a version change in kolibri is detected TODO: We should look at version numbers of external plugins, too! """ logger.info("Running update routines for new version...") try: # Check if there are other kolibri instances running # If there are, then we need to stop users from starting kolibri again. server.get_status() logger.error("There is a Kolibri server running." "Running updates now could cause a database error." "Please use `kolibri stop` and try again.") sys.exit(1) except server.NotRunning: pass call_command("collectstatic", interactive=False, verbosity=0) migrate_databases() run_upgrades(old_version, new_version) with open(version_file(), "w") as f: f.write(kolibri.__version__) from django.core.cache import caches cache = caches["built_files"] cache.clear()
def update(old_version, new_version): """ Called whenever a version change in kolibri is detected TODO: We should look at version numbers of external plugins, too! """ logger.info(u"Running update routines for new version...") # Need to do this here, before we run any Django management commands that # import settings. Otherwise the updated configuration will not be used # during this runtime. call_command("collectstatic", interactive=False, verbosity=0) from kolibri.core.settings import SKIP_AUTO_DATABASE_MIGRATION if not SKIP_AUTO_DATABASE_MIGRATION: _migrate_databases() run_upgrades(old_version, new_version) with open(version_file(), "w") as f: f.write(kolibri.__version__) from django.core.cache import caches cache = caches["built_files"] cache.clear()
def test_blank_old_version(): function = Mock() first = VersionUpgrade(old_version="<0.10.1", upgrade=function) with patch("kolibri.core.upgrade.get_upgrades", return_value=[first]): run_upgrades("", "1.1.2") function.assert_called_once()
def test_order_new_version(): function = Mock() first = VersionUpgrade(new_version=">0.10.1", upgrade=lambda: function(0)) second = VersionUpgrade(upgrade=lambda: function(1)) with patch("kolibri.core.upgrade.get_upgrades", return_value=[second, first]): run_upgrades("0.10.0", "1.1.2") function.assert_has_calls([call(0), call(1)])
def test_not_filter_dev_version(): unfiltered_mock = Mock() not_filtered = VersionUpgrade(old_version="<1.1.1", upgrade=unfiltered_mock) with patch("kolibri.core.upgrade.get_upgrades", return_value=[not_filtered]): run_upgrades("1.1.1.dev0", "1.1.2") unfiltered_mock.assert_called_once()
def test_filter_new_version(): filtered_mock = Mock() unfiltered_mock = Mock() filtered = VersionUpgrade(new_version=">1.1.1", upgrade=filtered_mock) not_filtered = VersionUpgrade(upgrade=unfiltered_mock) with patch("kolibri.core.upgrade.get_upgrades", return_value=[not_filtered, filtered]): run_upgrades("1.0.1", "1.1.0") filtered_mock.assert_not_called() unfiltered_mock.assert_called_once()
def _update_plugin(self, plugin_name): # Import here to prevent circular import from kolibri.plugins.registry import registered_plugins app_configs = [] plugin_instance = registered_plugins.get(plugin_name) if plugin_instance is None: logger.error( "Tried to run upgrades for plugin {} but it doesn't exist". format(plugin_name)) return for app in plugin_instance.INSTALLED_APPS: if not isinstance(app, AppConfig) and isinstance(app, str): app = apps.get_containing_app_config(app) app_configs.append(app) old_version = config["PLUGIN_VERSIONS"].get(plugin_name, "") new_version = _get_plugin_version(plugin_name) try: self._migrate_plugin(plugin_name, app_configs) except Exception as e: logger.error( "Unhandled exception while migrating {}, exception was:\n\n{}". format(plugin_name, e)) return if old_version: if VersionInfo.parse(normalize_version_to_semver( old_version)) < VersionInfo.parse( normalize_version_to_semver(new_version)): logger.info( "Running upgrade routines for {}, upgrading from {} to {}". format(plugin_name, old_version, new_version)) else: logger.info( "Running downgrade routines for {}, downgrading from {} to {}" .format(plugin_name, old_version, new_version)) else: logger.info( "Running installation routines for {}, installing {}".format( plugin_name, new_version)) try: run_upgrades(old_version, new_version, app_configs=app_configs) except Exception as e: logger.error( "An exception occured running upgrades for plugin {}: {}". format(plugin_name, e)) return return new_version
def update(old_version, new_version): """ Called whenever a version change in kolibri is detected TODO: We should look at version numbers of external plugins, too! """ logger.info("Running update routines for new version...") try: # Check if there are other kolibri instances running # If there are, then we need to stop users from starting kolibri again. server.get_status() logger.error("There is a Kolibri server running." "Running updates now could cause a database error." "Please use `kolibri stop` and try again.") sys.exit(1) except server.NotRunning: pass # Need to do this here, before we run any Django management commands that # import settings. Otherwise the updated configuration will not be used # during this runtime. call_command("collectstatic", interactive=False, verbosity=0) from kolibri.core.settings import SKIP_AUTO_DATABASE_MIGRATION if not SKIP_AUTO_DATABASE_MIGRATION: _migrate_databases() run_upgrades(old_version, new_version) with open(version_file(), "w") as f: f.write(kolibri.__version__) from django.core.cache import caches cache = caches["built_files"] cache.clear()