def install_ind_package(progress, package): status = UpdaterStatus.get_instance() # install an independent package. previous_state = status.state # Allow installing only if the updater is in certain safe states. if status.state not in [UpdaterStatus.NO_UPDATES, UpdaterStatus.UPDATES_AVAILABLE, UpdaterStatus.UPDATES_INSTALLED]: msg = "The install is already running" logger.warn(msg) progress.abort(msg) return False if package not in status.updatable_independent_packages: msg = "tried to install non-independent package {} using update_ind_pkg".format(package) logger.warn(msg) progress.abort(msg) return False status.state = UpdaterStatus.INSTALLING_INDEPENDENT status.save() update_sources_phase = 'updating-sources' installing_idp_phase = 'installing-idp-package' progress.split( Phase( update_sources_phase, _("Updating apt sources"), 10 ), Phase( installing_idp_phase, _("Installing independent package"), 90 ) ) progress.start(update_sources_phase) apt_handle.update(progress) progress.start(installing_idp_phase) apt_handle.upgrade(package, progress) status.state = previous_state status.last_update = int(time.time()) # always check independent packages as NONE as urgent updates to # these packages are dealt with by the main updater status.updatable_independent_packages = get_ind_packages(Priority.NONE) status.is_scheduled = False status.save() progress.finish(_("Update completed")) return True
def install_ind_package(progress, package): status = UpdaterStatus.get_instance() # install an independent package. previous_state = status.state # Allow installing only if the updater is in certain safe states. if status.state not in [ UpdaterStatus.NO_UPDATES, UpdaterStatus.UPDATES_AVAILABLE, UpdaterStatus.UPDATES_INSTALLED ]: msg = "The install is already running" logger.warn(msg) progress.abort(msg) return False if package not in status.updatable_independent_packages: msg = "tried to install non-independent package {} using update_ind_pkg".format( package) logger.warn(msg) progress.abort(msg) return False status.state = UpdaterStatus.INSTALLING_INDEPENDENT status.save() update_sources_phase = 'updating-sources' installing_idp_phase = 'installing-idp-package' progress.split( Phase(update_sources_phase, _("Updating apt sources"), 10), Phase(installing_idp_phase, _("Installing independent package"), 90)) progress.start(update_sources_phase) apt_handle.update(progress) progress.start(installing_idp_phase) apt_handle.upgrade(package, progress) status.state = previous_state status.last_update = int(time.time()) # always check independent packages as NONE as urgent updates to # these packages are dealt with by the main updater status.updatable_independent_packages = get_ind_packages(Priority.NONE) status.is_scheduled = False status.save() progress.finish(_("Update completed")) return True
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)