From b0fd252853ad241ea5fc14a55210b73f2493d5bf Mon Sep 17 00:00:00 2001 From: william Date: Tue, 20 Nov 2018 11:27:20 +0000 Subject: [PATCH 1/3] Read all shell arguments as lowercase Arguments are passed to the click callback (from click code) in lowercase. It's necessary we treat all arguments as lowercase also to prevent errors interfacing with this. --- src/models/config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/models/config.py b/src/models/config.py index 6b85a02..c55ed96 100644 --- a/src/models/config.py +++ b/src/models/config.py @@ -51,7 +51,8 @@ def help(self): return self.data['help'] def args(self): - return self.arguments or [] + if self.arguments: return [a.lower() for a in self.arguments] + else: return [] # TODO: Deprecated, avoid usage def interactive_only(self): From 89650ba8152b26041d9dd4b9f37ad93fe7d059f0 Mon Sep 17 00:00:00 2001 From: DavidMarchant Date: Tue, 20 Nov 2018 15:35:03 +0000 Subject: [PATCH 2/3] Cast arguments to strings Prevent issues rising from args being treated as ints They are later `strip`ed which would cause a breaking bug --- src/models/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/config.py b/src/models/config.py index c55ed96..c3cd82f 100644 --- a/src/models/config.py +++ b/src/models/config.py @@ -51,7 +51,7 @@ def help(self): return self.data['help'] def args(self): - if self.arguments: return [a.lower() for a in self.arguments] + if self.arguments: return [str(a).lower() for a in self.arguments] else: return [] # TODO: Deprecated, avoid usage From 40c85c3e2d475c1f378133ff7a194f806d9d9d98 Mon Sep 17 00:00:00 2001 From: DavidMarchant Date: Tue, 20 Nov 2018 16:53:15 +0000 Subject: [PATCH 3/3] Downcase argument names in cmds when cmds are ran The change so that argument names are downcased in order to match their values returned as from click (the commit before last) moved the problem such that there would be miss-match between the argument names stored by the system and those specified in the tool's cmd. This resulted in arguments not being used. This commit searches through a tools cmd on execution to fix this miss-match by replacing all instances with downcased versions. --- src/models/batch.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/models/batch.py b/src/models/batch.py index 093ef45..4f95e91 100644 --- a/src/models/batch.py +++ b/src/models/batch.py @@ -1,4 +1,5 @@ +import re from sqlalchemy import Column, String from database import Base @@ -26,6 +27,11 @@ def command(self): var_map = map(lambda v: '='.join([v.key, v.value]), var_models) var_str = ' && '.join(var_map) cmd = self.config_model.command() + # replace any instances of the variable in cmd with the lowercase + for variable in [var_model.key for var_model in var_models]: + matches = re.findall(variable, cmd, re.IGNORECASE) + for match in matches: + cmd = re.sub(match, variable, cmd) if var_str: cmd = ' && '.join([var_str, cmd]) return cmd