pep8, include the misp-galaxy tag in the output

pull/309/head
Christophe Vandeplas 2018-12-02 11:35:49 +01:00
parent 3e5abbf998
commit bd1f22ad7d
1 changed files with 14 additions and 12 deletions

View File

@ -76,39 +76,40 @@ def header():
doc += "= MISP galaxy\n" doc += "= MISP galaxy\n"
return doc return doc
def asciidoc(content=False, t='title',title='', typename=''):
def asciidoc(content=False, t='title', title='', typename=''):
adoc = [] adoc = []
adoc += "\n" adoc += "\n"
output = "" output = ""
if t == 'title': if t == 'title':
output = '== ' + content output = '== ' + content
elif t == 'info': elif t == 'info':
output = "\n{}.\n\n{} {} {}$${}$$.json[*this location*] {}.\n".format(content, 'NOTE: ', title, 'is a cluster galaxy available in JSON format at https://github.com/MISP/misp-galaxy/blob/master/clusters/',typename.lower(),' The JSON format can be freely reused in your application or automatically enabled in https://www.github.com/MISP/MISP[MISP]') output = "\n{}.\n\n{} {} {}$${}$$.json[*this location*] {}.\n".format(content, 'NOTE: ', title, 'is a cluster galaxy available in JSON format at https://github.com/MISP/misp-galaxy/blob/master/clusters/', typename.lower(), ' The JSON format can be freely reused in your application or automatically enabled in https://www.github.com/MISP/MISP[MISP]')
elif t == 'author': elif t == 'author':
output = '\nauthors:: {}\n'.format(' - '.join(content)) output = '\nauthors:: {}\n'.format(' - '.join(content))
elif t == 'value': elif t == 'value':
output = '=== ' + content output = '=== {}'.format(content)
elif t == 'description': elif t == 'description':
output = '\n{}\n'.format(content) output = '\n{}\n'.format(content)
elif t == 'meta-synonyms': elif t == 'meta-synonyms':
if 'synonyms' in content: if 'synonyms' in content:
for s in content['synonyms']: for s in content['synonyms']:
output = "{}\n* {}\n".format(output,s) output = "{}\n* {}\n".format(output, s)
output = '{} is also known as:\n{}\n'.format(title,output) output = '{} is also known as:\n{}\n'.format(title, output)
elif t == 'meta-refs': elif t == 'meta-refs':
if 'refs' in content: if 'refs' in content:
output = '{}{}'.format(output,'\n.Table References\n|===\n|Links\n') output = '{}{}'.format(output, '\n.Table References\n|===\n|Links\n')
for r in content['refs']: for r in content['refs']:
output = '{}|{}[{}]\n'.format(output, r, r) output = '{}|{}[{}]\n'.format(output, r, r)
output = '{}{}'.format(output,'|===\n') output = '{}{}'.format(output, '|===\n')
elif t == 'related': elif t == 'related':
for r in content: for r in content:
try: try:
output = "{}\n* {}: {} with {}\n".format(output, r['type'], cluster_uuids[r['dest-uuid']], ', '.join(r['tags'])) output = "{}\n* {}: {} with {}\n".format(output, r['type'], cluster_uuids[r['dest-uuid']], ', '.join(r['tags']))
except Exception: except Exception:
pass # ignore lookup errors pass # ignore lookup errors
if output: if output:
output = '{} has relationships with:\n{}\n'.format(title,output) output = '{} has relationships with:\n{}\n'.format(title, output)
adoc += output adoc += output
return adoc return adoc
@ -123,17 +124,18 @@ for cluster in clusters:
title = c['name'] title = c['name']
typename = c['type'] typename = c['type']
adoc += asciidoc(content=title, t='title') adoc += asciidoc(content=title, t='title')
adoc += asciidoc(content=c['description'], t='info', title=title, typename = typename) adoc += asciidoc(content=c['description'], t='info', title=title, typename=typename)
if 'authors' in c: if 'authors' in c:
adoc += asciidoc(content=c['authors'], t='author', title=title) adoc += asciidoc(content=c['authors'], t='author', title=title)
for v in c['values']: for v in c['values']:
adoc += asciidoc(content=v['value'], t='value', title=title) adoc += asciidoc(content=v['value'], t='value')
if 'description' in v: if 'description' in v:
adoc += asciidoc(content=v['description'], t='description') adoc += asciidoc(content=v['description'], t='description')
adoc += asciidoc(content='The tag is: _misp-galaxy:{}="{}"_'.format(c['type'], v['value']), t='description')
if 'meta' in v: if 'meta' in v:
adoc += asciidoc(content=v['meta'], t='meta-synonyms', title=v['value']) adoc += asciidoc(content=v['meta'], t='meta-synonyms', title=v['value'])
if 'related' in v: if 'related' in v:
adoc += asciidoc(content=v['related'], t='related', title=v['value']) adoc += asciidoc(content=v['related'], t='related', title=v['value'])
if 'meta' in v: if 'meta' in v:
adoc += asciidoc(content=v['meta'], t='meta-refs', title=v['value']) adoc += asciidoc(content=v['meta'], t='meta-refs', title=v['value'])
print (''.join(adoc)) print(''.join(adoc))