new: Allow to pass a list of WarningLists (in dict) as parameter

pull/5/head
Raphaël Vinot 2018-01-25 17:54:01 +01:00
parent d95ebeacfe
commit 133771d7c4
2 changed files with 11 additions and 7 deletions

View File

@ -108,16 +108,20 @@ class WarningList():
class WarningLists(collections.Mapping):
def __init__(self, slow_search=False):
def __init__(self, slow_search=False, lists=False):
"""Load all the warning lists from the package.
:slow_search: If true, uses the most appropriate search method. Can be slower. Default: exact match.
:lists: A list of warning lists (typically fetched from a MISP instance)
"""
self.root_dir_warninglists = os.path.join(os.path.abspath(os.path.dirname(sys.modules['pymispwarninglists'].__file__)),
'data', 'misp-warninglists', 'lists')
if not lists:
lists = []
self.root_dir_warninglists = os.path.join(os.path.abspath(os.path.dirname(sys.modules['pymispwarninglists'].__file__)),
'data', 'misp-warninglists', 'lists')
for warninglist_file in glob(os.path.join(self.root_dir_warninglists, '*', 'list.json')):
with open(warninglist_file, 'r') as f:
lists.append(json.load(f))
self.warninglists = {}
for warninglist_file in glob(os.path.join(self.root_dir_warninglists, '*', 'list.json')):
with open(warninglist_file, 'r') as f:
warninglist = json.load(f)
for warninglist in lists:
self.warninglists[warninglist['name']] = WarningList(warninglist, slow_search)
def validate_with_schema(self):

View File

@ -5,7 +5,7 @@ from setuptools import setup
setup(
name='pymispwarninglists',
version='0.1',
version='0.2',
author='Raphaël Vinot',
author_email='raphael.vinot@circl.lu',
maintainer='Raphaël Vinot',