def api_get_sources(): ret = {'available': [], 'active': [], 'filters': {}} for s in source.get_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 filter.get_filters()] ret['filters']['operators'] = [f.value for f in filter.Operators] return ret
def run_test(re): sl = sources.get_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.get_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]: return 'Converted Source does not match original!', 3 return '', 0
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']) all_sources = source.get_sources() for s in all_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 filter.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 _add_source(settings): """ Prompts the user for a new Source to add. """ from classes.sources import source all_sources = source.get_sources() choice = console.prompt_list("What would you like to download?", [(s.description, s.type) for s in all_sources], allow_none=True) print('\n') for s in all_sources: if s.type == choice: if s.setup_wizard(): print('\nAdding new source...') name = wizard_functions.get_unique_alias(settings) if not name: print('Aborted building Source at User request.') return s.set_alias(name) settings.add_source(s) _source_editor(settings, s) else: print("Setup failed. Not adding Source.") return print('Invalid selection.')
def get_sources(self): """ Builds and then returns a list of the Sources in this Settings config. """ from classes.sources import source return source.get_sources(self.get('sources', []))