本文整理汇总了Python中cmd2.Cmd类的典型用法代码示例。如果您正苦于以下问题:Python Cmd类的具体用法?Python Cmd怎么用?Python Cmd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cmd类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
Cmd.__init__(self)
mixins.bootstrap.BootstrapMixin.__init__(self)
self._load_config()
if 'url' in self.config and self.config['url']:
self._init_stacks()
self._validate_auth()
示例2: __init__
def __init__(self, verbose=False):
Cmd.__init__(self)
self.pp = pprint.PrettyPrinter(indent=4)
try:
self.conn = boto.connect_dynamodb()
except Exception as e:
self.conn = None
print e
print "Cannot connect to dynamodb - Check your credentials in ~/.boto or use the 'login' command"
# by default readline thinks - and other characters are word delimiters :(
if readline:
readline.set_completer_delims(re.sub('[-~]', '', readline.get_completer_delims()))
path = os.path.join(os.environ.get('HOME', ''), HISTORY_FILE)
self.history_file = os.path.abspath(path)
else:
self.history_file = None
self.tables = []
self.table = None
self.consistent = False
self.consumed = False
self.verbose = verbose
self.next_key = None
self.schema = {}
if verbose:
self._onchange_verbose(None, verbose)
示例3: __init__
def __init__(self):
Cmd.__init__(self)
try:
import readline
readline.set_completer_delims(' \t\n"') # initially it was ' \t\n`[email protected]#$^&*()=+[{]}\\|;:\'",<>?', but I dont want to break on too many
except:
pass
示例4: __init__
def __init__(self, namefile):
Cmd.__init__(self)
self.last = []
self.last.append([])
self.prompt = bcolors.PROMPT + "ForPCAP >>> " + bcolors.ENDC
self.loadPcap(namefile)
self.cmd = ""
示例5: __init__
def __init__(self, logical_device_id, get_stub):
Cmd.__init__(self)
self.get_stub = get_stub
self.logical_device_id = logical_device_id
self.prompt = '(' + self.colorize(
self.colorize('logical device {}'.format(logical_device_id), 'red'),
'bold') + ') '
示例6: do_help
def do_help(self, arg):
"""Command to display help info"""
self.stdout.write("\n%s Namespace Help\n" % self.namespace)
# If we're just in the cmd2 namespace, return its help
if (self.namespace == 'cmd2'):
Cmd.do_help(arg)
return
else: # Else, if we're in another namespace, try the following:
if arg: # If getting help for a specific command in the namespace, try:
# First see if the namespace command exists
try:
do_func = getattr(self, 'do_' + self.namespace + "_" + arg)
except AttributeError:
# Namespace function doesn't exist - see if there is a non-namespace / cmd2 command with arg name
try:
do_func = getattr(self, 'do_' + arg)
Cmd.do_help(arg)
return
except AttributeError:
self.stdout.write("[ERROR] Command does not exist in this or top-level namespace: %s\n" % arg)
return
try:
# Next see if there is a help_<namespace>_<command> method is available to call
help_func = getattr(self, 'help_' + self.namespace + '_' + arg)
help_func()
return
except AttributeError:
# If no help method for the command, get the __doc__ for the method if exists
try:
doc=getattr(self, 'do_' + self.namespace + '_' + arg).__doc__
if doc:
self.stdout.write("%s\n" % str(doc))
return
except AttributeError:
self.stdout.write("%s\n"%str(self.nohelp % (arg,)))
return
# Otherwise display generic help
else:
#names = self.get_names() + self.get_names_addendum
names = self.get_names()
cmds_doc = []
cmds_undoc = []
cmds_cmd2_namespace = []
for name in names:
if name.startswith('do_' + self.namespace):
cmd_prefix_length = len(self.namespace)+4
cmd=name[cmd_prefix_length:]
if getattr(self, name).__doc__:
cmds_doc.append(cmd)
else:
cmds_undoc.append(cmd)
elif name[:3] == 'do_':
cmd=name[3:]
cmds_cmd2_namespace.append(cmd)
self.stdout.write("%s\n" % str(self.doc_leader))
self.print_topics(self.doc_header, cmds_doc, 15,80)
self.print_topics(self.undoc_header, cmds_undoc, 15,80)
self.print_topics("'cmd2' Namespace Commands", cmds_cmd2_namespace, 15, 80)
示例7: __init__
def __init__(self, session_obj):
Cmd.__init__(self)
self.my_session = session_obj
self.supported_namespaces = ['poortego', 'cmd2']
self.namespace = 'poortego'
self.no_namespace_commands = ['help', 'welcome', 'namespace', 'exit']
self.get_names_addendum = [] # list of additional class methods not returned from python dir() at runtime
self.prompt = self.my_session.my_conf.conf_settings['poortego_prompt'] + ' '
示例8: __init__
def __init__(self, *args, **kwargs):
self.user = kwargs.pop("user")
self.username = kwargs.pop("username")
self.passwd = kwargs.pop("passwd")
self.api_auth = HTTPBasicAuth(self.username, self.passwd)
self.site = Site.objects.get_current()
self.prompt = "Schemanizer(%s)> " % (self.username)
Cmd.__init__(self, *args, **kwargs)
示例9: __init__
def __init__(self, device_id, get_stub):
Cmd.__init__(self)
self.get_stub = get_stub
self.device_id = device_id
self.prompt = '(' + self.colorize(
self.colorize('device {}'.format(device_id), 'red'), 'bold') + ') '
self.pm_config_last = None
self.pm_config_dirty = False
示例10: __init__
def __init__(self, parent):
Cmd.__init__(self)
self.parent = parent
self.prompt = self.parent.prompt[:-2] + "find:: "
self.machines = []
self.project = ""
self.locdata_dirs = []
self.project_dirs = []
self.record = self.parent.record
示例11: __init__
def __init__(self):
Cmd.__init__(self)
self.cli_parser = argparse.ArgumentParser()
subparsers = self.cli_parser.add_subparsers(help='internal commands')
publish_parser = subparsers.add_parser('publish', help='publish')
publish_parser.add_argument('--to', dest="to", metavar='PATH', type=str,
help='acoustic model directory', required=True)
示例12: __init__
def __init__(self, **kwargs):
Cmd.__init__(self, **kwargs)
self.prompt = 'BES> '
#self.do_conf(None)
self.BES_ROOT_SERVER = None
self.BES_USER_NAME = None
self.BES_PASSWORD = None
self.bes_conn = None
示例13: __init__
def __init__(self):
package = kolala.actions
for loader, name, is_pkg in pkgutil.walk_packages(package.__path__):
module = loader.find_module(name).load_module(name)
if getattr(module, 'main', None) is not None:
setattr(self, 'do_' + name, module.main)
if getattr(module, 'help', None) is not None:
setattr(self, 'help_' + name, module.help)
Cmd.__init__(self)
示例14: cmdloop
def cmdloop(self):
try:
Cmd.cmdloop(self)
except KeyboardInterrupt as e:
self.__key_interrupt = self.__key_interrupt + 1
if self.__key_interrupt > 1:
print('^C')
self.do_exit(self)
else:
print('Press Ctrl-C again to exit.')
self.cmdloop()
示例15: __init__
def __init__(self, port, debug):
Cmd.__init__(self)
if readline:
path = os.path.join(os.environ.get('HOME', ''), HISTORY_FILE)
self.history_file = os.path.abspath(path)
else:
self.history_file = None
self.debug = debug
self.port = port
self.init_search()