示例#1
0
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
示例#2
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))  # TODO: Why am I sending the same data twice?
    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
示例#3
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'])
        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()
示例#4
0
 def load_sources(self):  # !cover
     sources = []
     settings_sources = settings.get_sources()
     if self.sources is None:
         for s in settings_sources:
             print('Loaded Source: ', s.get_alias())
             sources.append(s)
     else:
         for so in self.sources:
             regexp = re.compile(str(so), re.IGNORECASE)
             for s in settings_sources:
                 if regexp.search(str(s.get_alias())):
                     print('Matched Source: ', s.get_alias())
                     sources.append(s)
                     break
     if len(sources) == 0:
         if len(settings_sources) == 0:
             su.error('No sources were found from the settings file.')
         else:
             su.error(
                 'No sources were found from the settings file matching the supplied patterns.'
             )
         sys.exit(20)
     return sources