def run_test(re): sl = sources.load_sources() for s in sl: if not s.get_alias(): return 'Missing Source alias! (%s)' % s, 1 if 'test' in s.get_alias(): return 'Loaded test Source by mistake.', 2 sl = sources.load_sources(source_list) if len(sl) != len(source_list): return 'Error loading test source list!', 1 for s in sl: # print(s) if 'multi' not in s.type: return 'Loaded source is of invalid type!', 2 if s.to_obj() != source_list[0]: print(s.to_obj()) return 'Converted Source does not match original!', 3 return '', 0
def api_get_sources(): ret = {'available': [], 'active': [], 'filters': {}} for s in sources.load_sources(): ret['available'].append(s.to_obj(for_webui=True)) for s in settings.get_sources(): ret['active'].append(s.to_obj(for_webui=True)) ret['filters']['available'] = [ f.to_js_obj() for f in filters.get_filters() ] ret['filters']['operators'] = [f.value for f in filters.Operators] return ret
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']) 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()
def get_sources(): """ Builds and then returns a list of the Sources in this Settings config. """ from classes import sources return sources.load_sources(get('sources'))