From 3a8880bf035873e26fbbaba9bd5fff91e3c20680 Mon Sep 17 00:00:00 2001 From: ProDigySML Date: Thu, 31 Jan 2019 23:09:26 -0800 Subject: [PATCH] Added in check for if output is defined. Also attempting fixing code smells with variable replacement --- Interlace/lib/core/input.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Interlace/lib/core/input.py b/Interlace/lib/core/input.py index 1157140..4d68893 100644 --- a/Interlace/lib/core/input.py +++ b/Interlace/lib/core/input.py @@ -59,6 +59,17 @@ class InputHelper(object): return ips + @staticmethod + def _replace_variable_for_commands(commands, variable, replacements): + tmp_commands = set() + + for replacement in replacements: + for command in commands: + tmp_commands.add(str(command).replace(variable, command)) + + return tmp_commands + + @staticmethod def process_commands(arguments): commands = set() @@ -70,8 +81,9 @@ class InputHelper(object): output = OutputHelper(arguments) # checking for whether output is writable and whether it exists - if not access(arguments.output, W_OK): - raise Exception("Directory provided isn't writable") + if arguments.output: + if not access(arguments.output, W_OK): + raise Exception("Directory provided isn't writable") if arguments.port: if "," in arguments.port: @@ -155,6 +167,9 @@ class InputHelper(object): for command in arguments.command_list: commands.add(command.strip()) + if arguments.port: + print(InputHelper._replace_variable_for_commands(commands, "__port__", ports)) + # expand commands to all known targets for target in targets: # replace flags