diff --git a/src/bin/bindctl/bindcmd.py b/src/bin/bindctl/bindcmd.py index d35b50aea7..f1a622e020 100644 --- a/src/bin/bindctl/bindcmd.py +++ b/src/bin/bindctl/bindcmd.py @@ -739,13 +739,8 @@ class BindCmdInterpreter(Cmd): of the sets as defined in command_sets.py''' if command.command == 'file': try: - command_file = open(command.params['filename']) - # copy them into a list for consistency with the built-in - # sets of commands - commands = [] - for line in command_file: - commands.append(line) - command_file.close() + with open(command.params['filename']) as command_file: + commands = command_file.readlines() except IOError as ioe: print("Error: " + str(ioe)) return @@ -787,14 +782,14 @@ class BindCmdInterpreter(Cmd): line = line.strip() if verbose: print(line) - if line.startswith('#'): + if line.startswith('#') or len(line) == 0: continue elif line.startswith('!'): - if line.startswith('!echo ') and len(line) > 6: + if re.match('^!echo ', line, re.I) and len(line) > 6: print(line[6:]) - elif line.startswith('!verbose on'): + elif re.match('^!verbose\s+on\s*$', line, re.I): verbose = True - elif line.startswith('!verbose off'): + elif re.match('^!verbose\s+off$', line, re.I): verbose = False else: print("Warning: ignoring unknown directive: " + line) diff --git a/tests/lettuce/data/commands/directives b/tests/lettuce/data/commands/directives index d8147fbf95..4fe10f514a 100644 --- a/tests/lettuce/data/commands/directives +++ b/tests/lettuce/data/commands/directives @@ -1,6 +1,19 @@ # this is a comment: commentexample1 -!echo this is an echo: echoexample +!echo this is an echo: echoexample2 !verbose on -# this is a comment with verbose on: verbosecommentexample +# this is a comment with verbose on: verbosecommentexample3 !verbose off -# this is a comment with verbose off again: commentexample2 +# this is a comment with verbose off again: commentexample4 +# empty lines and lines with only whitespace should be ignored + + + + + +# directives are case insensitive, and should handle whitespace +!ECHO echoexample5 +!eChO echoexample6 +!Verbose ON +# verbosecommentexample7 +!verBOSE off +# commentexample8 diff --git a/tests/lettuce/features/bindctl_commands.feature b/tests/lettuce/features/bindctl_commands.feature index f10467660f..0e7d9a82aa 100644 --- a/tests/lettuce/features/bindctl_commands.feature +++ b/tests/lettuce/features/bindctl_commands.feature @@ -88,9 +88,13 @@ Feature: control with bindctl When I send bind10 the command execute file data/commands/directives last bindctl output should not contain Error last bindctl output should not contain commentexample1 - last bindctl output should contain echoexample - last bindctl output should contain verbosecommentexample - last bindctl output should not contain commentexample2 + last bindctl output should contain echoexample2 + last bindctl output should contain verbosecommentexample3 + last bindctl output should not contain commentexample4 + last bindctl output should contain echoexample5 + last bindctl output should contain echoexample6 + last bindctl output should contain verbosecommentexample7 + last bindctl output should not contain commentexample8 # bad_command contains a bad command, at which point execution should stop When I send bind10 the command execute file data/commands/bad_command