def test_saving(self): """ Saving should work """ os.unlink(self.settings_file) self.assertTrue(settings.save(), msg="Save failed!") self.assertTrue(os.path.isfile(self.settings_file), msg='Failed to rebuild Settings file on save!') settings.disable_saving() self.assertFalse(settings.save(), msg="Settings saved after disabling!")
def api_save_settings(settings_obj): print('WebUI wants to change settings:', settings_obj) # noinspection PyBroadException try: for k, v in settings_obj.items(): settings.put(k, v, save_after=False) settings.save() except Exception: import traceback traceback.print_exc() return False return True
def api_save_sources(new_obj): print('Saving new source list:') output_settings = [] for so in new_obj: print('\tType:', so['type'], 'Alias:', so['alias'], so['filters']) for s in sources.load_sources(): if s.type == so['type']: s.set_alias(so['alias']) for k, v in so['data'].items(): s.insert_data(k, v) for f in so['filters']: for fi in filters.get_filters(): if f['field'] == fi.field: fi.set_operator(f['operator']) fi.set_limit(f['limit']) s.add_filter(fi) break output_settings.append(s) for s in settings.get_sources(): settings.remove_source(s, save_after=False) for s in output_settings: settings.add_source(s, prevent_duplicate=False, save_after=False) return settings.save()