本文整理汇总了Python中commands.Commands.call方法的典型用法代码示例。如果您正苦于以下问题:Python Commands.call方法的具体用法?Python Commands.call怎么用?Python Commands.call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类commands.Commands
的用法示例。
在下文中一共展示了Commands.call方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ComodITConsole
# 需要导入模块: from commands import Commands [as 别名]
# 或者: from commands.Commands import call [as 别名]
class ComodITConsole(object):
def __init__(self, debug = False):
self._cmds = None
self._debug = debug
def interact(self):
if self._cmds == None:
raise Exception("Console must be connected")
readline.parse_and_bind('tab: complete')
readline.set_completer_delims(readline.get_completer_delims().replace('-', ''))
while True:
try:
readline.set_completer(self._cmds.get_completer())
line = raw_input(self._cmds.prompt() + "> ")
self.execute_line(line)
except EOFError:
print
break
except KeyboardInterrupt:
print # skip a line
continue
def execute_file(self, path):
with open(path, 'r') as f:
for line in f:
self.execute_line(line)
def connect(self, api_url, username, password, insecure = False):
self._cmds = Commands(Client(api_url, username, password, insecure))
self._cmds.set_debug(self._debug)
def execute_line(self, line):
# Strip comments out
index = line.find('#')
if index >= 0:
line = line[0:index]
line = line.strip()
# If line is empty, do nothing
if line != '':
args = merge_escaped(line.split())
self._execute(args)
def _execute(self, args):
if len(args) == 0:
# Nothing to do
return
try:
self._cmds.call(args)
except Exception as e:
sys.stderr.write(str(e) + "\n")
if self._debug:
sys.exit(1)