def check_for_updates(progress=None, priority=Priority.NONE, is_gui=False): status = UpdaterStatus.get_instance() if not progress: progress = DummyProgress() countdown = status.first_boot_countdown - int(time.time()) # block update checks when: # 1) three days have NOT passed since the first boot # 2) and not checking for URGENT updates # 3) and the check is triggered from background hooks (not by user) if (countdown > 0) and (priority is not Priority.URGENT) and (not is_gui): return False if status.state not in [UpdaterStatus.NO_UPDATES, UpdaterStatus.UPDATES_DOWNLOADED]: msg = "No need to check for updates" logger.info(msg) # This was a successful check, so we need to update the timestamp. status.last_check = int(time.time()) status.save() # Return True in all cases except when the state is UPDATES_INSTALLED # In that case, we've just updated and don't want to check for updates # again. return status.state != UpdaterStatus.UPDATES_INSTALLED if not is_internet(): err_msg = N_("Must have internet to check for updates") logger.error(err_msg) progress.fail(_(err_msg)) RCState.get_instance().rc = RC.NO_NETWORK # Not updating the timestamp. The check failed. return False if not is_server_available(): err_msg = N_("Could not connect to the download server") logger.error(err_msg) progress.fail(_(err_msg)) RCState.get_instance().rc = RC.CANNOT_REACH_KANO # Not updating the timestamp. The check failed. return False update_type = _do_check(progress, priority=priority) if update_type == Priority.NONE: # If the Updater is running in recovery mode, do not update the state # out of the installing ones, otherwise the recovery flow will quit. if not status.is_recovery_needed(): status.state = UpdaterStatus.NO_UPDATES logger.info("No updates available") RCState.get_instance().rc = RC.NO_UPDATES_AVAILABLE rv = False else: if update_type == Priority.URGENT: status.notifications_muted = True status.is_urgent = True if not status.is_recovery_needed(): status.state = UpdaterStatus.UPDATES_AVAILABLE logger.info("Updates available") logger.info("Found update of priority: {}".format(priority.priority)) rv = True if priority <= Priority.STANDARD: status.last_check = 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.last_check_urgent = int(time.time()) status.save() return rv
def check_for_updates(progress=None, priority=Priority.NONE, is_gui=False): status = UpdaterStatus.get_instance() # FIXME: FOR DEBUGGING ONLY #status.state = UpdaterStatus.UPDATES_AVAILABLE #status.last_check = int(time.time()) #status.save() #return True if not progress: progress = DummyProgress() countdown = status.first_boot_countdown - int(time.time()) # block update checks when: # 1) three days have NOT passed since the first boot # 2) and not checking for URGENT updates # 3) and the check is triggered from background hooks (not by user) if (countdown > 0) and (priority is not Priority.URGENT) and (not is_gui): return False if status.state != UpdaterStatus.NO_UPDATES: msg = _('No need to check for updates') logger.info(msg) # This was a successful check, so we need to update the timestamp. status.last_check = int(time.time()) status.save() # Return True in all cases except when the state is UPDATES_INSTALLED # In that case, we've just updated and don't want to check for updates # again. return status.state != UpdaterStatus.UPDATES_INSTALLED if not is_internet(): err_msg = _('Must have internet to check for updates') logger.error(err_msg) progress.fail(err_msg) # Not updating the timestamp. The check failed. return False if not is_server_available(): err_msg = _('Could not connect to the download server') logger.error(err_msg) progress.fail(err_msg) # Not updating the timestamp. The check failed. return False update_type = _do_check(progress, priority=priority) if update_type == Priority.NONE: status.state = UpdaterStatus.NO_UPDATES logger.debug('No updates available') rv = False else: if update_type == Priority.URGENT: status.notifications_muted = True status.is_urgent = True status.state = UpdaterStatus.UPDATES_AVAILABLE logger.debug('Updates available') logger.debug('Found update of priority: {}'.format(priority.priority)) rv = True if priority <= Priority.STANDARD: status.last_check = int(time.time()) status.last_check_urgent = int(time.time()) status.save() return rv
def download(progress=None, gui=True): status = UpdaterStatus.get_instance() dialog_proc = None if not progress: progress = DummyProgress() if status.state == UpdaterStatus.NO_UPDATES: progress.split( Phase( 'checking', _('Checking for updates'), 10, is_main=True ), Phase( 'downloading', _('Downloading updates'), 90, is_main=True ) ) progress.start('checking') check_for_updates(progress=progress) if status.state == UpdaterStatus.NO_UPDATES: progress.finish(_('No updates to download')) return False progress.start('downloading') elif status.state == UpdaterStatus.UPDATES_DOWNLOADED: err_msg = _('Updates have been downloaded already') logger.error(err_msg) progress.abort(err_msg) return True elif status.state == UpdaterStatus.DOWNLOADING_UPDATES: err_msg = _('The download is already running') logger.error(err_msg) progress.abort(err_msg) return False elif status.state == UpdaterStatus.INSTALLING_UPDATES: err_msg = _('Updates are already being installed') logger.error(err_msg) progress.abort(err_msg) return False if not is_internet(): err_msg = _('Must have internet to download the updates') logger.error(err_msg) progress.fail(err_msg) return False if not is_server_available(): err_msg = _('Could not connect to the download server') logger.error(err_msg) progress.fail(err_msg) return False # show a dialog informing the user of an automatic urgent download if status.is_urgent and not gui: # TODO: mute notifications? title = "Updater" description = "Kano HQ has just released a critical update that will repair" \ " some important things on your system! We'll download these automatically," \ " and ask you to schedule the install when they finish." buttons = "OK:green:1" dialog_proc = show_kano_dialog(title, description, buttons, blocking=False) status.state = UpdaterStatus.DOWNLOADING_UPDATES status.save() priority = Priority.NONE if status.is_urgent: priority = Priority.URGENT logger.info('Urgent update detected, bumping to normal priority') make_normal_prio() logger.debug('Downloading with priority {}'.format(priority.priority)) try: success = do_download(progress, status, priority=priority, dialog_proc=dialog_proc) except Exception as err: progress.fail(err.message) logger.error(err.message) status.state = UpdaterStatus.UPDATES_AVAILABLE status.save() return False status.state = UpdaterStatus.UPDATES_DOWNLOADED status.save() return success
def check_for_updates(progress=None, priority=Priority.NONE, is_gui=False): status = UpdaterStatus.get_instance() # FIXME: FOR DEBUGGING ONLY #status.state = UpdaterStatus.UPDATES_AVAILABLE #status.last_check = int(time.time()) #status.save() #return True if not progress: progress = DummyProgress() countdown = status.first_boot_countdown - int(time.time()) # block update checks when: # 1) three days have NOT passed since the first boot # 2) and not checking for URGENT updates # 3) and the check is triggered from background hooks (not by user) if (countdown > 0) and (priority is not Priority.URGENT) and (not is_gui): return False if status.state != UpdaterStatus.NO_UPDATES: msg = "No need to check for updates" logger.info(msg) # This was a successful check, so we need to update the timestamp. status.last_check = int(time.time()) status.save() # Return True in all cases except when the state is UPDATES_INSTALLED # In that case, we've just updated and don't want to check for updates # again. return status.state != UpdaterStatus.UPDATES_INSTALLED if not is_internet(): err_msg = N_("Must have internet to check for updates") logger.error(err_msg) progress.fail(_(err_msg)) # Not updating the timestamp. The check failed. return False if not is_server_available(): err_msg = N_("Could not connect to the download server") logger.error(err_msg) progress.fail(_(err_msg)) # Not updating the timestamp. The check failed. return False update_type = _do_check(progress, priority=priority) if update_type == Priority.NONE: status.state = UpdaterStatus.NO_UPDATES logger.debug("No updates available") rv = False else: if update_type == Priority.URGENT: status.notifications_muted = True status.is_urgent = True status.state = UpdaterStatus.UPDATES_AVAILABLE logger.debug("Updates available") logger.debug("Found update of priority: {}".format(priority.priority)) rv = True if priority <= Priority.STANDARD: status.last_check = 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.last_check_urgent = int(time.time()) status.save() return rv
def download(progress=None, gui=True): status = UpdaterStatus.get_instance() dialog_proc = None if not progress: progress = DummyProgress() if status.state in [UpdaterStatus.NO_UPDATES, UpdaterStatus.UPDATES_DOWNLOADED]: progress.split( Phase( 'checking', _("Checking for updates"), 10, is_main=True ), Phase( 'downloading', _("Downloading updates"), 90, is_main=True ) ) pre_check_state = status.state progress.start('checking') check_for_updates(progress=progress) if status.state == UpdaterStatus.NO_UPDATES: if pre_check_state == UpdaterStatus.NO_UPDATES: msg = N_("No updates to download") logger.info(msg) progress.finish(_(msg)) return False elif pre_check_state == UpdaterStatus.UPDATES_DOWNLOADED: err_msg = N_("Latest updates have been downloaded already") logger.info(err_msg) progress.abort(_(err_msg)) return True progress.start('downloading') elif status.state == UpdaterStatus.DOWNLOADING_UPDATES: err_msg = N_("The download is already running") logger.error(err_msg) progress.abort(_(err_msg)) return False if not is_internet(): err_msg = N_("Must have internet to download the updates") logger.error(err_msg) progress.fail(_(err_msg)) RCState.get_instance().rc = RC.NO_NETWORK return False priority = Priority.NONE if status.is_urgent: priority = Priority.URGENT if not is_server_available(): err_msg = N_("Could not connect to the download server") logger.error(err_msg) progress.fail(_(err_msg)) RCState.get_instance().rc = RC.CANNOT_REACH_KANO return False run_cmd('sudo kano-empty-trash') enough_space, space_msg = check_disk_space(priority) if not enough_space: logger.error(space_msg) progress.abort(_(space_msg)) RCState.get_instance().rc = RC.NOT_ENOUGH_SPACE return False # show a dialog informing the user of an automatic urgent download if status.is_urgent and not gui: # TODO: mute notifications? title = _("Updater") description = _( "Kano HQ has just released a critical update that will repair some" " important things on your system! We'll download these automatically," " and ask you to schedule the install when they finish." ) buttons = _("OK:green:1") dialog_proc = show_kano_dialog(title, description, buttons, blocking=False) # If the Updater is running in recovery mode, do not update the state # out of the installing ones, otherwise the recovery flow will quit. if not status.is_recovery_needed(): status.state = UpdaterStatus.DOWNLOADING_UPDATES status.save() priority = Priority.NONE if status.is_urgent: priority = Priority.URGENT logger.info("Urgent update detected, bumping to normal priority") make_normal_prio() logger.debug("Downloading with priority {}".format(priority.priority)) try: success = do_download( progress, status, priority=priority, dialog_proc=dialog_proc ) except Exception as err: progress.fail(err.message) logger.error(err.message) RCState.get_instance().rc = RC.UNEXPECTED_ERROR status.state = UpdaterStatus.UPDATES_AVAILABLE status.save() return False if not status.is_recovery_needed(): status.state = UpdaterStatus.UPDATES_DOWNLOADED status.save() return success
def download(progress=None, gui=True): status = UpdaterStatus.get_instance() dialog_proc = None if not progress: progress = DummyProgress() if status.state in [ UpdaterStatus.NO_UPDATES, UpdaterStatus.UPDATES_DOWNLOADED ]: progress.split( Phase('checking', _("Checking for updates"), 10, is_main=True), Phase('downloading', _("Downloading updates"), 90, is_main=True)) pre_check_state = status.state progress.start('checking') check_for_updates(progress=progress) if status.state == UpdaterStatus.NO_UPDATES: if pre_check_state == UpdaterStatus.NO_UPDATES: msg = N_("No updates to download") logger.info(msg) progress.finish(_(msg)) return False elif pre_check_state == UpdaterStatus.UPDATES_DOWNLOADED: err_msg = N_("Latest updates have been downloaded already") logger.info(err_msg) progress.abort(_(err_msg)) return True progress.start('downloading') elif status.state == UpdaterStatus.DOWNLOADING_UPDATES: err_msg = N_("The download is already running") logger.error(err_msg) progress.abort(_(err_msg)) return False if not is_internet(): err_msg = N_("Must have internet to download the updates") logger.error(err_msg) progress.fail(_(err_msg)) RCState.get_instance().rc = RC.NO_NETWORK return False if not is_server_available(): err_msg = N_("Could not connect to the download server") logger.error(err_msg) progress.fail(_(err_msg)) RCState.get_instance().rc = RC.CANNOT_REACH_KANO return False # show a dialog informing the user of an automatic urgent download if status.is_urgent and not gui: # TODO: mute notifications? title = _("Updater") description = _( "Kano HQ has just released a critical update that will repair" " some important things on your system! We'll download these" " automatically, and ask you to schedule the install when they finish." ) buttons = _("OK:green:1") dialog_proc = show_kano_dialog(title, description, buttons, blocking=False) # If the Updater is running in recovery mode, do not update the state # out of the installing ones, otherwise the recovery flow will quit. if not status.is_recovery_needed(): status.state = UpdaterStatus.DOWNLOADING_UPDATES status.save() priority = Priority.NONE if status.is_urgent: priority = Priority.URGENT logger.info("Urgent update detected, bumping to normal priority") make_normal_prio() logger.debug("Downloading with priority {}".format(priority.priority)) try: success = do_download(progress, status, priority=priority, dialog_proc=dialog_proc) except Exception as err: progress.fail(err.message) logger.error(err.message) RCState.get_instance().rc = RC.UNEXPECTED_ERROR status.state = UpdaterStatus.UPDATES_AVAILABLE status.save() return False if not status.is_recovery_needed(): status.state = UpdaterStatus.UPDATES_DOWNLOADED status.save() return success
def download(progress=None, gui=True): status = UpdaterStatus.get_instance() dialog_proc = None if not progress: progress = DummyProgress() if status.state == UpdaterStatus.NO_UPDATES: progress.split( Phase( 'checking', _("Checking for updates"), 10, is_main=True ), Phase( 'downloading', _("Downloading updates"), 90, is_main=True ) ) progress.start('checking') check_for_updates(progress=progress) if status.state == UpdaterStatus.NO_UPDATES: logger.info("No updates to download") progress.finish(_("No updates to download")) return False progress.start('downloading') elif status.state == UpdaterStatus.UPDATES_DOWNLOADED: err_msg = N_("Updates have been downloaded already") logger.error(err_msg) progress.abort(_(err_msg)) return True elif status.state == UpdaterStatus.DOWNLOADING_UPDATES: err_msg = N_("The download is already running") logger.error(err_msg) progress.abort(_(err_msg)) return False elif status.state == UpdaterStatus.INSTALLING_UPDATES: err_msg = N_("Updates are already being installed") logger.error(err_msg) progress.abort(_(err_msg)) return False if not is_internet(): err_msg = N_("Must have internet to download the updates") logger.error(err_msg) progress.fail(_(err_msg)) return False if not is_server_available(): err_msg = N_("Could not connect to the download server") logger.error(err_msg) progress.fail(_(err_msg)) return False # show a dialog informing the user of an automatic urgent download if status.is_urgent and not gui: # TODO: mute notifications? title = _("Updater") description = _("Kano HQ has just released a critical update that will repair" \ " some important things on your system! We'll download these automatically," \ " and ask you to schedule the install when they finish.") buttons = _("OK:green:1") dialog_proc = show_kano_dialog(title, description, buttons, blocking=False) status.state = UpdaterStatus.DOWNLOADING_UPDATES status.save() priority = Priority.NONE if status.is_urgent: priority = Priority.URGENT logger.info("Urgent update detected, bumping to normal priority") make_normal_prio() logger.debug("Downloading with priority {}".format(priority.priority)) try: success = do_download(progress, status, priority=priority, dialog_proc=dialog_proc) except Exception as err: progress.fail(err.message) logger.error(err.message) status.state = UpdaterStatus.UPDATES_AVAILABLE status.save() return False status.state = UpdaterStatus.UPDATES_DOWNLOADED status.save() return success
def download(progress=None): status = UpdaterStatus.get_instance() if not progress: progress = DummyProgress() if status.state == UpdaterStatus.NO_UPDATES: progress.split( Phase('checking', _('Checking for updates'), 10, is_main=True), Phase('downloading', _('Downloading updates'), 90, is_main=True)) progress.start('checking') check_for_updates(progress=progress) if status.state == UpdaterStatus.NO_UPDATES: progress.finish(_('No updates to download')) return False progress.start('downloading') elif status.state == UpdaterStatus.UPDATES_DOWNLOADED: err_msg = _('Updates have been downloaded already') logger.error(err_msg) progress.abort(err_msg) return True elif status.state == UpdaterStatus.DOWNLOADING_UPDATES: err_msg = _('The download is already running') logger.error(err_msg) progress.abort(err_msg) return False elif status.state == UpdaterStatus.INSTALLING_UPDATES: err_msg = _('Updates are already being installed') logger.error(err_msg) progress.abort(err_msg) return False if not is_internet(): err_msg = _('Must have internet to download the updates') logger.error(err_msg) progress.fail(err_msg) return False if not is_server_available(): err_msg = _('Could not connect to the download server') logger.error(err_msg) progress.fail(err_msg) return False status.state = UpdaterStatus.DOWNLOADING_UPDATES status.save() try: success = do_download(progress, status) except Exception as err: progress.fail(err.message) logger.error(err.message) status.state = UpdaterStatus.UPDATES_AVAILABLE status.save() return False status.state = UpdaterStatus.UPDATES_DOWNLOADED status.save() return success
def check_for_updates(min_time_between_checks=0, progress=None): status = UpdaterStatus.get_instance() # FIXME: FOR DEBUGGING ONLY #status.state = UpdaterStatus.UPDATES_AVAILABLE #status.last_check = int(time.time()) #status.save() #return True if not progress: progress = DummyProgress() if status.state != UpdaterStatus.NO_UPDATES: msg = _('No need to check for updates') logger.info(msg) progress.abort(msg) # Return True in all cases except when the state is UPDATES_INSTALLED # In that case, we've just updated and don't want to check for updates # again. return status.state != UpdaterStatus.UPDATES_INSTALLED if min_time_between_checks: target_delta = float(min_time_between_checks) * 60 * 60 time_now = time.time() delta = time_now - status.last_check if delta > target_delta: logger.info(_('Time check passed, doing update check!')) else: msg = _('Not enough time passed for a new update check!') logger.info(msg) progress.abort(msg) return False if not is_internet(): err_msg = _('Must have internet to check for updates') logger.error(err_msg) progress.fail(err_msg) return False if not is_server_available(): err_msg = _('Could not connect to the download server') logger.error(err_msg) progress.fail(err_msg) return False if _do_check(progress): status.state = UpdaterStatus.UPDATES_AVAILABLE logger.debug('Updates available') rv = True else: status.state = UpdaterStatus.NO_UPDATES logger.debug('No updates available') rv = False status.last_check = int(time.time()) status.save() return rv