def onecmd(self, line):
"""Override onecmd.
1 - So we don't have to have a do_EOF method.
2 - So we can strip comments
3 - So we can track line numbers
"""
if DEBUG:
print('Executing "%s"' % line)
self.line_num += 1
if line == "EOF":
if cmd.Cmd.use_rawinput:
# This means that we printed a prompt, and we'll want to
# print a newline to pretty things up for the caller.
self.print('')
return True
# Strip comments
comment_idx = line.find("#")
if comment_idx >= 0:
line = line[0:comment_idx]
line = line.strip()
# search multiple commands on the same line
lexer = shlex.shlex(line)
lexer.whitespace = ''
for issemicolon, group in itertools.groupby(lexer, lambda x: x == ";"):
if not issemicolon:
self.onecmd_exec("".join(group))
评论列表
文章目录