def migrate_repository(apt_file, old_repo, new_repo): try: sed(old_repo, new_repo, apt_file, use_regexp=False) except IOError as exc: logger.warn("Changing repository URL failed ({})".format(exc)) return # TODO: track progress of this apt_handle.clear_cache() apt_handle.update(DummyProgress())
def do_install(progress, status): status.state = UpdaterStatus.INSTALLING_UPDATES status.save() progress.split( Phase('init', _('Starting Update'), 10, is_main=True), Phase('updating-itself', _('Updating Itself'), 10, is_main=True), Phase('preupdate', _('Running The Preupdate Scripts'), 10, is_main=True), Phase('updating-pip-packages', _('Updating Pip Packages'), 15, is_main=True), Phase('updating-deb-packages', _('Updating Deb Packages'), 15, is_main=True), Phase('postupdate', _('Running The Postupdate Scripts'), 10, is_main=True), Phase('aux-tasks', 'Performing auxiliary tasks', 10, is_main=True)) progress.start('init') apt_handle.clear_cache() apt_handle.fix_broken(progress) # determine the versions (from and to) system_version = OSVersion.from_version_file(SYSTEM_VERSION_FILE) msg = "Upgrading from {} to {}".format(system_version, TARGET_VERSION) logger.info(msg) # set up the scenarios and check whether they cover updating # from this version preup = PreUpdate(system_version) postup = PostUpdate(system_version) if not (preup.covers_update() and postup.covers_update()): title = _('Unfortunately, your version of Kano OS is too old ' 'to be updated through the updater.') description = _('You will need to download the image of the ' 'OS and reflash your SD card.') msg = "{}: {}".format(title, description) logger.error("Updating from a version that is no longer supported" + \ "()".format(system_version)) progress.error(msg) raise InstallError(msg) old_updater = apt_handle.get_package('kano-updater').installed.version progress.start('updating-itself') apt_handle.upgrade('kano-updater', progress) # relaunch if the updater has changed new_updater = apt_handle.get_package('kano-updater') if old_updater != new_updater.installed.version: # Remove the installation in progress status so it doesn't # block the start of the new instance. status.state = UpdaterStatus.UPDATES_DOWNLOADED status.save() logger.info(_('The updater has been updated, relaunching.')) progress.relaunch() return False progress.start('preupdate') try: preup.run() except Exception as e: logger.error('The pre-update scenarios failed.') logger.error(str(e)) progress.abort(_('The pre-update tasks failed.')) raise logger.debug('Updating pip packages') progress.start('updating-pip-packages') install_pip_packages(progress) logger.debug('Updating deb packages') progress.start('updating-deb-packages') install_deb_packages(progress) progress.start('postupdate') try: postup.run() except Exception as e: logger.error('The post-update scenarios failed.') logger.error(str(e)) progress.abort(_('The post-update tasks failed.')) raise bump_system_version() # We don't care too much when these fail progress.start('aux-tasks') run_aux_tasks(progress) status.state = UpdaterStatus.UPDATES_INSTALLED status.last_update = int(time.time()) status.save() progress.finish('Update completed') return True
def install_standard(progress, status): progress.split( Phase( 'init', _("Starting Update"), 10, is_main=True ), Phase( 'updating-itself', _("Updating Itself"), 10, is_main=True ), Phase( 'preupdate', _("Running The Preupdate Scripts"), 10, is_main=True ), Phase( 'updating-pip-packages', _("Updating Pip Packages"), 15, is_main=True ), Phase( 'updating-deb-packages', _("Updating Deb Packages"), 15, is_main=True ), Phase( 'postupdate', _("Running The Postupdate Scripts"), 10, is_main=True ), Phase( 'aux-tasks', _("Performing auxiliary tasks"), 10, is_main=True ) ) progress.start('init') apt_handle.clear_cache() apt_handle.fix_broken(progress) # determine the versions (from and to) system_version = OSVersion.from_version_file(SYSTEM_VERSION_FILE) msg = "Upgrading from {} to {}".format(system_version, TARGET_VERSION) logger.info(msg) # set up the scenarios and check whether they cover updating # from this version preup = PreUpdate(system_version) postup = PostUpdate(system_version) if not (preup.covers_update() and postup.covers_update()): title = _("Unfortunately, your version of Kano OS is too old " \ "to be updated through the updater.") description = _("You will need to download the image of the " \ "OS and reflash your SD card.") msg = "{}: {}".format(title, description) logger.error("Updating from a version that is no longer supported ({})" .format(system_version)) progress.fail(msg) raise InstallError(msg) old_updater = apt_handle.get_package('kano-updater').installed.version progress.start('updating-itself') apt_handle.upgrade('kano-updater', progress) # relaunch if the updater has changed new_updater = apt_handle.get_package('kano-updater') if old_updater != new_updater.installed.version: # Remove the installation in progress status so it doesn't # block the start of the new instance. status.state = UpdaterStatus.UPDATES_DOWNLOADED status.save() logger.info("The updater has been updated, relaunching.") progress.relaunch() return False progress.start('preupdate') try: preup.run() except Exception as err: logger.error("The pre-update scenarios failed.") logger.error(err.encode('utf-8')) progress.abort("The pre-update tasks failed.") raise logger.debug("Updating pip packages") progress.start('updating-pip-packages') install_pip_packages(progress) logger.debug("Updating deb packages") progress.start('updating-deb-packages') install_deb_packages(progress) progress.start('postupdate') try: postup.run() except Exception as err: logger.error("The post-update scenarios failed.") logger.error(err.encode('utf-8')) progress.abort("The post-update tasks failed.") raise bump_system_version() # We don't care too much when these fail progress.start('aux-tasks') run_aux_tasks(progress)