2018-09-13 14:58:50 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
|
|
|
|
module_types = ['expansion', 'export_mod', 'import_mod']
|
|
|
|
titles = ['Expansion Modules', 'Export Modules', 'Import Modules']
|
2019-01-21 13:31:52 +01:00
|
|
|
markdown = ["# MISP modules documentation\n"]
|
2018-09-29 08:09:27 +02:00
|
|
|
githublink = 'https://github.com/MISP/misp-modules/tree/master/misp_modules/modules'
|
2018-09-20 10:46:25 +02:00
|
|
|
|
2019-01-21 13:31:52 +01:00
|
|
|
|
2018-09-20 10:46:25 +02:00
|
|
|
def generate_doc(root_path):
|
|
|
|
for _path, title in zip(module_types, titles):
|
|
|
|
markdown.append('\n## {}\n'.format(title))
|
|
|
|
current_path = os.path.join(root_path, _path)
|
|
|
|
files = sorted(os.listdir(current_path))
|
2018-09-29 08:09:27 +02:00
|
|
|
githubpath = '{}/{}'.format(githublink, _path)
|
2018-09-20 10:46:25 +02:00
|
|
|
for _file in files:
|
2018-09-29 08:09:27 +02:00
|
|
|
modulename = _file.split('.json')[0]
|
|
|
|
githubref = '{}/{}.py'.format(githubpath, modulename)
|
|
|
|
markdown.append('\n#### [{}]({})\n'.format(modulename, githubref))
|
2018-09-20 10:46:25 +02:00
|
|
|
filename = os.path.join(current_path, _file)
|
2019-01-21 13:31:52 +01:00
|
|
|
with open(filename, 'rt') as f:
|
2018-09-20 10:46:25 +02:00
|
|
|
definition = json.loads(f.read())
|
|
|
|
if 'logo' in definition:
|
|
|
|
markdown.append('\n<img src={} height=60>\n'.format(definition.pop('logo')))
|
|
|
|
if 'description' in definition:
|
|
|
|
markdown.append('\n{}\n'.format(definition.pop('description')))
|
2018-11-13 16:50:49 +01:00
|
|
|
for field, value in sorted(definition.items()):
|
2018-09-20 10:46:25 +02:00
|
|
|
if value:
|
|
|
|
value = ', '.join(value) if isinstance(value, list) else '{}'.format(value.replace('\n', '\n>'))
|
|
|
|
markdown.append('- **{}**:\n>{}\n'.format(field, value))
|
|
|
|
markdown.append('\n-----\n')
|
2019-02-05 14:46:42 +01:00
|
|
|
with open('README.md', 'w') as w:
|
2018-09-20 10:46:25 +02:00
|
|
|
w.write(''.join(markdown))
|
|
|
|
|
2019-01-21 13:31:52 +01:00
|
|
|
|
2018-09-20 10:46:25 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
root_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
generate_doc(root_path)
|