From 8930ad0a2e1b55acd17aee162f4a62d5d9aa6624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Sun, 2 Apr 2017 22:06:32 +0200 Subject: [PATCH] Make pep8 happy --- tools/generator/misp-galaxy.py | 2 +- tools/generator/veris.py | 13 +++++++++---- tools/machinetag.py | 33 ++++++++++++++++++++------------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/tools/generator/misp-galaxy.py b/tools/generator/misp-galaxy.py index 88652c1..3a5f652 100644 --- a/tools/generator/misp-galaxy.py +++ b/tools/generator/misp-galaxy.py @@ -50,7 +50,7 @@ for element in elements: file_out = '../../misp-galaxy/machinetag.json' with open(file_out, 'w') as f: f.write(json.dumps(taxonomy, sort_keys=True, indent=4, separators=(',', ': '))) -print("JSON saved to "+ file_out) +print("JSON saved to " + file_out) # t = Taxonomy(taxonomy) diff --git a/tools/generator/veris.py b/tools/generator/veris.py index 9c3033d..c63a9b8 100644 --- a/tools/generator/veris.py +++ b/tools/generator/veris.py @@ -15,6 +15,7 @@ output['values'] = [] with open(filename) as fp: t = json.load(fp) + def lookupPredicate(predicate=False): if not predicate: return False @@ -22,12 +23,14 @@ def lookupPredicate(predicate=False): if p['value'] == predicate: return True + def lookupValues(predicate=False): if not predicate: return False for p in output['values']: if p['predicate'] == predicate: - return True + return True + def machineTag(namespace=False, predicate=False, value=None, expanded=None): @@ -54,6 +57,7 @@ def machineTag(namespace=False, predicate=False, value=None, expanded=None): prefix = [] top = [] + def flatten(root, prefix_keys=True): dicts = [([], root)] ret = {} @@ -70,11 +74,12 @@ def flatten(root, prefix_keys=True): else: p = ':'.join(prefix.rsplit(':')[:-1]) if debug: - print (namespace+":"+p+"="+v) + print(namespace + ":" + p + "=" + v) machineTag(namespace=namespace, predicate=p, value=prefix.split(':')[-1], expanded=v) ret[prefix] = v return ret -flatten ( root = t) -print (json.dumps(output)) +flatten(root=t) + +print(json.dumps(output)) diff --git a/tools/machinetag.py b/tools/machinetag.py index bd685cb..3e1f56d 100755 --- a/tools/machinetag.py +++ b/tools/machinetag.py @@ -54,13 +54,16 @@ if args.a: doc = doc + "= MISP taxonomies and classification as machine tags\n\n" doc = doc + "Generated from https://github.com/MISP/misp-taxonomies.\n\n" doc = doc + "\nimage::{images-cdn}misp-logo.png[MISP logo]\n" - doc = doc + "Taxonomies that can be used in MISP (2.4) and other information sharing tool and expressed in Machine Tags (Triple Tags). A machine tag is composed of a namespace (MUST), a predicate (MUST) and an (OPTIONAL) value. Machine tags are often called triple tag due to their format.\n" + doc = "{} {} {} {}".format(doc, "Taxonomies that can be used in MISP (2.4) and other information sharing tool and expressed in Machine Tags (Triple Tags).", + "A machine tag is composed of a namespace (MUST), a predicate (MUST) and an (OPTIONAL) value.", + "Machine tags are often called triple tag due to their format.\n") doc = doc + "\n\n" if args.n: del taxonomies[:] taxonomies.append(args.n) + def asciidoc(content=False, adoc=doc, t='title'): if not args.a: return False @@ -71,12 +74,15 @@ def asciidoc(content=False, adoc=doc, t='title'): content = '=== ' + content elif t == 'namespace': content = '== ' + content + '\n' - content = content + 'NOTE: ' + namespace + ' namespace available in JSON format at https://github.com/MISP/misp-taxonomies/blob/master/' + namespace + '/machinetag.json[*this location*]. The JSON format can be freely reused in your application or automatically enabled in https://www.github.com/MISP/MISP[MISP] taxonomy.' + content = "{} {} {} {} {} {} {}".format(content, 'NOTE:', namespace, 'namespace available in JSON format at https://github.com/MISP/misp-taxonomies/blob/master/', + namespace, '/machinetag.json[*this location*]. The JSON format can be freely reused in your application', + 'or automatically enabled in https://www.github.com/MISP/MISP[MISP] taxonomy.') elif t == 'description': - content = '\n'+content+'\n' + content = '\n' + content + '\n' adoc = adoc + content return adoc + def machineTag(namespace=False, predicate=False, value=None): if namespace is False or predicate is False: @@ -86,6 +92,7 @@ def machineTag(namespace=False, predicate=False, value=None): else: return (u'{0}:{1}=\"{2}\"'.format(namespace, predicate, value)) + for taxonomy in taxonomies: filename = os.path.join(thisDir, "../", taxonomy, "machinetag.json") with open(filename) as fp: @@ -96,10 +103,10 @@ for taxonomy in taxonomies: else: expanded_namespace = namespace if args.a: - doc = asciidoc(content=t['namespace'], adoc=doc, t='namespace') - doc = asciidoc(content=t['description'], adoc=doc, t='description') + doc = asciidoc(content=t['namespace'], adoc=doc, t='namespace') + doc = asciidoc(content=t['description'], adoc=doc, t='description') if args.v: - print ('{0}'.format(t['description'])) + print('{0}'.format(t['description'])) for predicate in t['predicates']: if args.a: doc = asciidoc(content=predicate['value'], adoc=doc, t='predicate') @@ -110,11 +117,11 @@ for taxonomy in taxonomies: if predicate.get('description'): doc = asciidoc(content=machineTag(namespace=namespace, predicate=predicate['description']), adoc=doc, t='description') else: - print (machineTag(namespace=namespace, predicate=predicate['value'])) + print(machineTag(namespace=namespace, predicate=predicate['value'])) if args.e: - print ("--> " + machineTag(namespace=expanded_namespace, predicate=predicate['expanded'])) - if predicate.get('description'): - print ("--> " + predicate['description']) + print("--> " + machineTag(namespace=expanded_namespace, predicate=predicate['expanded'])) + if predicate.get('description'): + print("--> " + predicate['description']) else: for e in t['values']: if e['predicate'] == predicate['value']: @@ -125,10 +132,10 @@ for taxonomy in taxonomies: doc = asciidoc(content=machineTag(namespace=namespace, predicate=e['predicate'], value=v['value']), adoc=doc) doc = asciidoc(content=machineTag(namespace=namespace, predicate=v['expanded']), adoc=doc, t='description') else: - print (machineTag(namespace=namespace, predicate=e['predicate'], value=v['value'])) + print(machineTag(namespace=namespace, predicate=e['predicate'], value=v['value'])) if args.e: if'expanded' in v: - print ("--> " + machineTag(namespace=namespace, predicate=expanded, value=v['expanded'])) + print("--> " + machineTag(namespace=namespace, predicate=expanded, value=v['expanded'])) if args.a: - print (doc) + print(doc)