Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit 5118d12

Browse files
author
clittle
committed
Cleaned up cmdline utility
1 parent 5c2ae7a commit 5118d12

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

layers/cmdline.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
from core import Layer
55

66
if __name__ == '__main__':
7-
parser = argparse.ArgumentParser(description='Export an Att&ck layer as a svg image')
7+
parser = argparse.ArgumentParser(description='Export an Att&ck layer as a svg image or excel file')
88
parser.add_argument('-m', '--mode', choices=['svg', 'excel'], required=True, help='The form to export the layers in')
99
parser.add_argument('input', nargs='+', help='Path(s) to the file to export')
1010
parser.add_argument('-s','--source', choices=['taxii', 'local'], default='taxii', help='What source to utilize when building the matrix')
1111
parser.add_argument('--local', help='Path to the local resource if --source=local', default=None)
1212
parser.add_argument('-o','--output', nargs='+', help='Path(s) to the exported svg file', required=True)
1313
args = parser.parse_args()
14-
print(args)
1514
if len(args.output) != len(args.input):
1615
print('Mismatched number of output filepaths to input file paths. Exiting...')
1716

18-
for entry in args.input:
19-
print('{}/{} - Beginning processing {}'.format(args.input.index(entry) + 1, len(args.input), entry))
17+
for i in range(0, len(args.input)):
18+
entry = args.input[i]
19+
print('{}/{} - Beginning processing {}'.format(i + 1, len(args.input), entry))
2020
lay = Layer()
2121
try:
2222
lay.from_file(entry)
@@ -25,11 +25,11 @@
2525
continue
2626
if args.mode=='excel':
2727
exy = ToExcel(domain=lay.layer.domain, source=args.source, local=args.local)
28-
exy.to_xlsx(lay, filepath=args.output[args.input.index(entry)])
28+
exy.to_xlsx(lay, filepath=args.output[i])
2929
else:
3030
svy = ToSvg(domain=lay.layer.domain, source=args.source, local=args.local)
31-
svy.to_svg(lay, filepath=args.output[args.input.index(entry)])
32-
print('{}/{} - Finished processing {}'.format(args.input.index(entry) + 1, len(args.input), entry))
31+
svy.to_svg(lay, filepath=args.output[i])
32+
print('{}/{} - Finished processing {}'.format(i + 1, len(args.input), entry))
3333

3434

3535
else:

layers/exporters/to_svg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def __init__(self, domain='enterprise', source='taxii', local=None):
1919
"""
2020
self.raw_handle = SvgTemplates(domain=domain, source=source, local=local)
2121

22-
def to_svg(self, layer, output='example.svg'):
22+
def to_svg(self, layer, filepath='example.svg'):
2323
"""
2424
Generate a svg file based on the input layer
2525
2626
:param layer: Input attack layer object to transform
27-
:param output: Desired output svg location
27+
:param filepath: Desired output svg location
2828
:return: (meta) svg file at the targeted output location
2929
"""
3030
if layer is not None:
@@ -76,4 +76,4 @@ def to_svg(self, layer, output='example.svg'):
7676
d = self.raw_handle.export(showName=sName, showID=sID, sort=sort, scores=scores,
7777
subtechs=included_subs, colors=colors,
7878
exclude=excluded, lhandle=layer.layer)
79-
d.saveSvg(output)
79+
d.saveSvg(filepath)

0 commit comments

Comments
 (0)