def loop(first_start=False): global _ShedulerTask dhnio.Dprint(4, 'dhnupdate.loop mode=' + str(settings.getUpdatesMode())) if settings.getUpdatesMode() == settings.getUpdatesModeValues()[2]: dhnio.Dprint(4, 'dhnupdate.loop is finishing. updates is turned off') return shed = schedule.Schedule(from_dict=read_shedule_dict()) nexttime = shed.next_time() # nexttime = next(d) if first_start: nexttime = time.time() + 5 if nexttime is None: dhnio.Dprint(1, 'dhnupdate.loop ERROR calculating shedule interval') return if nexttime < 0: dhnio.Dprint(1, 'dhnupdate.loop nexttime=%s' % str(nexttime)) return # DEBUG # nexttime = time.time() + 60.0 delay = nexttime - time.time() if delay < 0: dhnio.Dprint(2, 'dhnupdate.loop WARNING delay=%s %s' % (str(delay), shed)) delay = 10 dhnio.Dprint(6, 'dhnupdate.loop run_sheduled_update will start after %s seconds (%s hours)' % (str(delay), str(delay/3600.0))) _ShedulerTask = reactor.callLater(delay, run_sheduled_update)
def init(): dhnio.Dprint(4, 'dhnupdate.init') update_shedule_file(settings.getUpdatesSheduleData()) if not dhnio.isFrozen() or not dhnio.Windows(): dhnio.Dprint(6, 'dhnupdate.init finishing') return if not os.path.isfile(settings.VersionFile()): dhnio.WriteFile(settings.VersionFile(), '') SetLocalDir(dhnio.getExecutableDir()) if settings.getUpdatesMode() != settings.getUpdatesModeValues()[2]: dhnio.Dprint(6, 'dhnupdate.init starting the loop') reactor.callLater(0, loop, True) else: dhnio.Dprint(6, 'dhnupdate.init skip, update mode is: %s' % settings.getUpdatesMode())
def step4(version_digest): dhnio.Dprint(4, 'dhnupdate.step4') global _UpdatingInProgress global _CurrentVersionDigest global _NewVersionNotifyFunc global _UpdatingByUser _CurrentVersionDigest = str(version_digest) local_version = dhnio.ReadBinaryFile(settings.VersionFile()) if local_version == _CurrentVersionDigest: dhnio.Dprint(6, 'dhnupdate.step4 no need to update') _UpdatingInProgress = False return dhnio.Dprint(6, 'dhnupdate.step4 local=%s current=%s ' % (local_version, _CurrentVersionDigest)) if settings.getUpdatesMode() == settings.getUpdatesModeValues()[2] and not _UpdatingByUser: dhnio.Dprint(6, 'dhnupdate.step4 run scheduled, but mode is %s, skip now' % settings.getUpdatesMode()) return if _UpdatingByUser or settings.getUpdatesMode() == settings.getUpdatesModeValues()[0]: # info_file_path = os.path.join(dhnio.getExecutableDir(), settings.FilesDigestsFilename()) info_file_path = settings.InfoFile() if os.path.isfile(info_file_path): try: os.remove(info_file_path) except: dhnio.Dprint(1, 'dhnupdate.step4 ERROR can no remove ' + info_file_path ) dhnio.DprintException() param = '' if _UpdatingByUser: param = 'show' import shutdowner if param == 'show': shutdowner.A('stop', 'restartnshow') else: shutdowner.A('stop', 'restart') else: if _NewVersionNotifyFunc is not None: _NewVersionNotifyFunc(_CurrentVersionDigest)
def run_sheduled_update(): global _UpdatingByUser global _UpdatingInProgress dhnio.Dprint(6, 'dhnupdate.run_sheduled_update') if _UpdatingInProgress: dhnio.Dprint(6, ' update is in progress, finish.') return if settings.getUpdatesMode() == settings.getUpdatesModeValues()[2]: dhnio.Dprint(6, ' update mode is %s, finish.' % settings.getUpdatesMode()) return if backup_control.HasRunningBackup(): dhnio.Dprint(6, ' some backups are running at the moment, finish.') return _UpdatingByUser = False reactor.callLater(0, step0) #check or start the update d = read_shedule_dict() d['lasttime'] = str(time.time()) write_shedule_dict(d) loop()