def start_plugins_update_scheduler(event, doing_backup): _setup_signal_termination() if not api.sysparam.get_bool('ONLINE_SERVICES'): logger.info("ONLINE_SERVICES not enabled. Not scheduling plugin updates...") return manager = get_plugin_manager() while True: last_check_str = UserSettings().get('last-plugins-update', None) last_check = (dateutil.parser.parse(last_check_str) if last_check_str else datetime.datetime.min) # Check for updates once per day if last_check.date() == datetime.date.today(): time.sleep(24 * 60 * 60) continue logger.info("Checking for plugins updates...") updated = False default_store = get_default_store() for egg in default_store.find(PluginEgg): md5sum = egg.egg_md5sum manager.download_plugin(egg.plugin_name) # If download_plugin updated the plugin, autoreload will # make egg. be reloaded from the database if md5sum != egg.egg_md5sum: updated = True settings = UserSettings() settings.set('last-plugins-update', datetime.datetime.now().isoformat()) settings.flush() if updated: # Wait until any running backup is finished and restart while doing_backup.value: time.sleep(60) logger.info("Some plugins were updated. Restarting now " "to reflect the changes...") event.set() else: logger.info("No update was found...")
def start_plugins_update_scheduler(event): _setup_signal_termination() if not api.sysparam.get_bool('ONLINE_SERVICES'): logger.info( "ONLINE_SERVICES not enabled. Not scheduling plugin updates...") return manager = get_plugin_manager() while True: last_check_str = UserSettings().get('last-plugins-update', None) last_check = (dateutil.parser.parse(last_check_str) if last_check_str else datetime.datetime.min) # Check for updates once per day if last_check.date() == datetime.date.today(): time.sleep(24 * 60 * 60) continue logger.info("Checking for plugins updates...") updated = False default_store = get_default_store() # TODO: atm we are only updating the conector plugin to avoid # problems with migrations. Let this update everything once we # find a solution for this problem for egg in default_store.find(PluginEgg, plugin_name=u'conector'): md5sum = egg.egg_md5sum manager.download_plugin(egg.plugin_name) # If download_plugin updated the plugin, autoreload will # make egg. be reloaded from the database if md5sum != egg.egg_md5sum: updated = True settings = UserSettings() settings.set('last-plugins-update', datetime.datetime.now().isoformat()) settings.flush() if updated: # Wait until any running backup is finished and restart while _doing_backup.value: time.sleep(60) logger.info("Some plugins were updated. Restarting now " "to reflect the changes...") event.set() else: logger.info("No update was found...")
def test_settings_process(self): with tempfile.NamedTemporaryFile() as tmp: settings = UserSettings(filename=tmp.name) # Set a value and recover it. settings.set('value', 123) self.assertEquals(settings.get('value'), 123) # Get a non existing value with a default fallback self.assertEquals(settings.get('other_value', 456), 456) # Getting it again should have saved the value self.assertEquals(settings.get('other_value'), 456) # Now, lets remove that value. settings.remove('other_value') self.assertEquals(settings.items(), [('value', 123)]) # Getting it again should return None self.assertEquals(settings.get('other_value'), None) # Flush settings.flush()