From 2ef73925555a77008674322271fde949904d2f03 Mon Sep 17 00:00:00 2001 From: Hannah Ward Date: Fri, 20 Jan 2017 09:35:28 +0000 Subject: [PATCH] Update machinetag to allow running from any directory --- tools/machinetag.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/machinetag.py b/tools/machinetag.py index 7d883a5..bd685cb 100755 --- a/tools/machinetag.py +++ b/tools/machinetag.py @@ -32,8 +32,12 @@ import argparse import os taxonomies = [] -for folder in os.listdir('../'): - if os.path.isfile(os.path.join('../', folder, 'machinetag.json')): + +# Get our current directory from file location +thisDir = os.path.dirname(__file__) + +for folder in os.listdir(os.path.join(thisDir, '../')): + if os.path.isfile(os.path.join(thisDir, '../', folder, 'machinetag.json')): taxonomies.append(folder) argParser = argparse.ArgumentParser(description='Dump Machine Tags (Triple Tags) from MISP taxonomies', epilog='Available taxonomies are {0}'.format(taxonomies)) argParser.add_argument('-e', action='store_true', help='Include expanded tags') @@ -83,7 +87,7 @@ def machineTag(namespace=False, predicate=False, value=None): return (u'{0}:{1}=\"{2}\"'.format(namespace, predicate, value)) for taxonomy in taxonomies: - filename = os.path.join("../", taxonomy, "machinetag.json") + filename = os.path.join(thisDir, "../", taxonomy, "machinetag.json") with open(filename) as fp: t = json.load(fp) namespace = t['namespace']