From 8d9f6053d3c4f8c15bf2d1fdff79efe3f6637255 Mon Sep 17 00:00:00 2001 From: Ricky Cook Date: Wed, 8 Oct 2014 22:19:26 +1100 Subject: [PATCH 1/4] Simplify command module option parsing --- commands/command.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/commands/command.py b/commands/command.py index c584d6feed8..90a94fd8369 100644 --- a/commands/command.py +++ b/commands/command.py @@ -18,6 +18,7 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +import copy import sys import datetime import traceback @@ -99,12 +100,21 @@ EXAMPLES = ''' creates: /path/to/database ''' +OPTIONS = {'chdir': None, + 'creates': None, + 'executable': None, + 'NO_LOG': None, + 'removes': None, + 'warn': True, + } + # This is a pretty complex regex, which functions as follows: # # 1. (^|\s) # ^ look for a space or the beginning of the line -# 2. (creates|removes|chdir|executable|NO_LOG)= -# ^ look for a valid param, followed by an '=' +# 2. ({options_list})= +# ^ expanded to (chdir|creates|executable...)= +# look for a valid param, followed by an '=' # 3. (?P[\'"])? # ^ look for an optional quote character, which can either be # a single or double quote character, and store it for later @@ -114,8 +124,12 @@ EXAMPLES = ''' # ^ a non-escaped space or a non-escaped quote of the same kind # that was matched in the first 'quote' is found, or the end of # the line is reached - -PARAM_REGEX = re.compile(r'(^|\s)(creates|removes|chdir|executable|NO_LOG|warn)=(?P[\'"])?(.*?)(?(quote)(?[\'"])?(.*?)(?(quote)(? Date: Wed, 8 Oct 2014 22:25:02 +1100 Subject: [PATCH 2/4] Add comment to command options dict --- commands/command.py | 1 + 1 file changed, 1 insertion(+) diff --git a/commands/command.py b/commands/command.py index 90a94fd8369..75927a5ba0b 100644 --- a/commands/command.py +++ b/commands/command.py @@ -100,6 +100,7 @@ EXAMPLES = ''' creates: /path/to/database ''' +# Dict of options and their defaults OPTIONS = {'chdir': None, 'creates': None, 'executable': None, From b195b5a6bb65acfbfddc61885df1fe9d721c34a3 Mon Sep 17 00:00:00 2001 From: Ricky Cook Date: Wed, 8 Oct 2014 22:30:20 +1100 Subject: [PATCH 3/4] Get warn option same as other args --- commands/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/command.py b/commands/command.py index 75927a5ba0b..44c95a3d5bd 100644 --- a/commands/command.py +++ b/commands/command.py @@ -163,7 +163,7 @@ def main(): args = module.params['args'] creates = module.params['creates'] removes = module.params['removes'] - warn = module.params.get('warn', True) + warn = module.params['warn'] if args.strip() == '': module.fail_json(rc=256, msg="no command given") From 6db328c79a8c1f406fdab4e901732ecc9682ced3 Mon Sep 17 00:00:00 2001 From: Ricky Cook Date: Wed, 8 Oct 2014 22:59:03 +1100 Subject: [PATCH 4/4] Fix regex string format --- commands/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/command.py b/commands/command.py index 44c95a3d5bd..2b79b327d71 100644 --- a/commands/command.py +++ b/commands/command.py @@ -127,7 +127,7 @@ OPTIONS = {'chdir': None, # the line is reached OPTIONS_REGEX = '|'.join(OPTIONS.keys()) PARAM_REGEX = re.compile( - r'(^|\s)({options_list})=(?P[\'"])?(.*?)(?(quote)(?[\'"])?(.*?)(?(quote)(?