本文整理汇总了Python中cmd.ljust方法的典型用法代码示例。如果您正苦于以下问题:Python cmd.ljust方法的具体用法?Python cmd.ljust怎么用?Python cmd.ljust使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cmd
的用法示例。
在下文中一共展示了cmd.ljust方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _list_options
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def _list_options(self, options=None):
'''Lists options'''
if options is None:
options = self.options
if options:
pattern = f"{self.spacer}%s %s %s %s"
key_len = len(max(options, key=len))
if key_len < 4: key_len = 4
val_len = len(max([self.to_unicode_str(options[x]) for x in options], key=len))
if val_len < 13: val_len = 13
print('')
print(pattern % ('Name'.ljust(key_len), 'Current Value'.ljust(val_len), 'Required', 'Description'))
print(pattern % (self.ruler*key_len, (self.ruler*13).ljust(val_len), self.ruler*8, self.ruler*11))
for key in sorted(options):
value = options[key] if options[key] != None else ''
reqd = 'no' if options.required[key] is False else 'yes'
desc = options.description[key]
print(pattern % (key.ljust(key_len), self.to_unicode_str(value).ljust(val_len), self.to_unicode_str(reqd).ljust(8), desc))
print('')
else:
print('')
print(f"{self.spacer}No options available for this module.")
print('')
示例2: show_options
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def show_options(self, options=None):
'''Lists options'''
if options is None:
options = self.options
if options:
pattern = f'{self.spacer}%s %s %s %s'
key_len = len(max(options, key=len))
if key_len < 4: key_len = 4
val_len = len(max([self.to_unicode_str(options[x]) for x in options], key=len))
if val_len < 13: val_len = 13
print('')
print(pattern % ('Name'.ljust(key_len), 'Current Value'.ljust(val_len), 'Required', 'Description'))
print(pattern % (self.ruler*key_len, (self.ruler*13).ljust(val_len), self.ruler*8, self.ruler*11))
for key in sorted(options):
value = options[key] if options[key] != None else ''
reqd = 'no' if options.required[key] is False else 'yes'
desc = options.description[key]
print(pattern % (key.ljust(key_len), self.to_unicode_str(value).ljust(val_len), self.to_unicode_str(reqd).ljust(8), desc))
print('')
else:
print(f'{os.linesep}{self.spacer}No options available for this module.{os.linesep}')
示例3: show_options
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def show_options(self, options=None):
'''Lists options'''
if options is None:
options = self.options
if options:
pattern = '%s%%s %%s %%s %%s' % (self.spacer)
key_len = len(max(options, key=len))
if key_len < 4: key_len = 4
val_len = len(max([self.to_unicode_str(options[x]) for x in options], key=len))
if val_len < 13: val_len = 13
print('')
print(pattern % ('Name'.ljust(key_len), 'Current Value'.ljust(val_len), 'Required', 'Description'))
print(pattern % (self.ruler*key_len, (self.ruler*13).ljust(val_len), self.ruler*8, self.ruler*11))
for key in sorted(options):
value = options[key] if options[key] != None else ''
reqd = 'no' if options.required[key] is False else 'yes'
desc = options.description[key]
print(pattern % (key.upper().ljust(key_len), self.to_unicode_str(value).ljust(val_len), self.to_unicode_str(reqd).ljust(8), desc))
print('')
else:
print('')
print('%sNo options available for this module.' % (self.spacer))
print('')
示例4: print_topics
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def print_topics(self, header, cmds, cmdlen, maxcol):
self.logger.debug('')
if cmds:
self.stdout.write("%s\n" % str(header))
if self.ruler:
self.stdout.write("%s\n" % str(self.ruler * len(header)))
for cmd in cmds:
self.stdout.write(
"%s %s\n" % (
cmd.ljust(15),
getattr(self, 'do_' + cmd).__doc__
)
)
self.stdout.write("\n")
# ==================================================
# SUPPORT METHODS
# ==================================================
示例5: print_topics
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def print_topics(self, header, cmds, cmdlen, maxcol):
if cmds:
self.stdout.write(f"{header}{os.linesep}")
if self.ruler:
self.stdout.write(f"{self.ruler * len(header)}{os.linesep}")
for cmd in cmds:
self.stdout.write(f"{cmd.ljust(15)} {getattr(self, 'do_' + cmd).__doc__}{os.linesep}")
self.stdout.write(os.linesep)
#==================================================
# SUPPORT METHODS
#==================================================
示例6: print_topics
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def print_topics(self, header, cmds, cmdlen, maxcol):
if cmds:
self.stdout.write(f"{header}{os.linesep}")
if self.ruler:
self.stdout.write(f"{self.ruler * len(header)}{os.linesep}")
for cmd in cmds:
self.stdout.write(f"{cmd.ljust(15)} {getattr(self, 'do_' + cmd).__doc__}{os.linesep}")
self.stdout.write(os.linesep)
# ==================================================
# SUPPORT METHODS
# ==================================================
示例7: print_topics
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def print_topics(self,header,cmds,cmdlen,maxcol):
if cmds:
self.stdout.write("%s\n"%(str(header)))
if self.ruler:self.stdout.write("%s\n"%(str(self.ruler * len(header))))
for cmd in cmds:
self.stdout.write("%s %s\n"%(cmd.ljust(15),getattr(self,"do_"+cmd).__doc__))
self.stdout.write("\n")
示例8: show_options
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def show_options(self,options=None):
if options is None:
options = self.options
if options:
pattern = '%s%%s %%s %%s %%s'%(spacer)
key_len = len(max(options,key=len))
if key_len < 4: key_len = 4
try:
val_len = len(max([to_unicode(options[x]) for x in options],key=len))
except Exception:
val_len = 13
if val_len < 13: val_len = 13
print('')
print(pattern%('Name'.ljust(key_len),'Current Value'.ljust(val_len),'Required','Description'))
print(pattern%(self.ruler*key_len,(self.ruler*13).ljust(val_len),self.ruler*8,self.ruler*11))
for key in sorted(options):
value = options[key] if options[key] != None else ""
reqd = 'no' if options.required[key] is False else 'yes'
desc = options.description[key]
try:
print(pattern%(key.upper().ljust(key_len),to_unicode(value).ljust(val_len),to_unicode(reqd).ljust(8),desc))
except AttributeError:
self.clear()
print('')
else:
print('\n%sNo options available for this module\n'%(spacer))
示例9: print_topics
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def print_topics(self, header, cmds, cmdlen, maxcol):
if cmds:
self.stdout.write("%s\n"%str(header))
if self.ruler:
self.stdout.write("%s\n"%str(self.ruler * len(header)))
for cmd in cmds:
self.stdout.write("%s %s\n" % (cmd.ljust(15), getattr(self, 'do_' + cmd).__doc__))
self.stdout.write("\n")
#==================================================
# SUPPORT METHODS
#==================================================
示例10: table_record_data
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def table_record_data(self, header, rdata, lens):
"""table record data"""
self.logger.debug('')
return tuple([
self.to_unicode_str(rdata[i]).ljust(lens[i])
if rdata[i] is not None else ''.ljust(lens[i])
for i in range(0, len(header))
])
示例11: show_options
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def show_options(self, options=None):
'''Lists options'''
self.logger.debug('')
if options is None:
options = self.options
if options:
pattern = '%s%%s %%s %%s %%s' % (self.spacer)
key_len = len(max(options, key=len))
if key_len < 4:
key_len = 4
val_len = len(
max([self.to_unicode_str(options[x])
for x in options], key=len))
if val_len < 13:
val_len = 13
print('')
print(pattern % (
'Name'.ljust(key_len),
'Current Value'.ljust(val_len),
'Required',
'Description'))
print(pattern % (
self.ruler*key_len,
(self.ruler*13).ljust(val_len),
self.ruler*8,
self.ruler*11))
for key in sorted(options):
value = options[key] if options[key] is not None else ''
reqd = 'no' if options.required[key] is False else 'yes'
desc = options.description[key]
print(pattern % (
key.upper().ljust(key_len),
self.to_unicode_str(value).ljust(val_len),
self.to_unicode_str(reqd).ljust(8),
desc))
print('')
else:
print('')
print('%sNo options available for this module.' % (self.spacer))
print('')
示例12: table
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def table(self, data, header=[], title=''):
'''Accepts a list of rows and outputs a table.'''
tdata = list(data)
if header:
tdata.insert(0, header)
if len(set([len(x) for x in tdata])) > 1:
raise FrameworkException('Row lengths not consistent.')
lens = []
cols = len(tdata[0])
# create a list of max widths for each column
for i in range(0,cols):
lens.append(len(max([self.to_unicode_str(x[i]) if x[i] != None else '' for x in tdata], key=len)))
# calculate dynamic widths based on the title
title_len = len(title)
tdata_len = sum(lens) + (3*(cols-1))
diff = title_len - tdata_len
if diff > 0:
diff_per = diff / cols
lens = [x+diff_per for x in lens]
diff_mod = diff % cols
for x in range(0, diff_mod):
lens[x] += 1
# build ascii table
if len(tdata) > 0:
separator_str = f"{self.spacer}+-{'%s---'*(cols-1)}%s-+"
separator_sub = tuple(['-'*x for x in lens])
separator = separator_str % separator_sub
data_str = f"{self.spacer}| {'%s | '*(cols-1)}%s |"
# top of ascii table
print('')
print(separator)
# ascii table data
if title:
print(f"{self.spacer}| {title.center(tdata_len)} |")
print(separator)
if header:
rdata = tdata.pop(0)
data_sub = tuple([rdata[i].center(lens[i]) for i in range(0,cols)])
print(data_str % data_sub)
print(separator)
for rdata in tdata:
data_sub = tuple([self.to_unicode_str(rdata[i]).ljust(lens[i]) if rdata[i] != None else ''.ljust(lens[i]) for i in range(0,cols)])
print(data_str % data_sub)
# bottom of ascii table
print(separator)
print('')
#==================================================
# DATABASE METHODS
#==================================================
示例13: table
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def table(self, data, header, title='', linear=False, sep='-'):
'''Accepts a list of rows and outputs a table.'''
tdata = list(data)
if header:
tdata.insert(0, header)
if len(set([len(x) for x in tdata])) > 1:
raise FrameworkException('Row lengths not consistent.')
lens = []
cols = len(tdata[0])
# create a list of max widths for each column
for i in range(0, cols):
lens.append(len(max([self.to_unicode_str(x[i]) if x[i] != None else '' for x in tdata], key=len)))
# calculate dynamic widths based on the title
title_len = len(title)
tdata_len = sum(lens) + (3*(cols-1))
diff = title_len - tdata_len
if diff > 0:
diff_per = diff / cols
lens = [x+diff_per for x in lens]
diff_mod = diff % cols
for x in range(0, diff_mod):
lens[x] += 1
# build ascii table
if len(tdata) > 0:
separator_str = f"{self.spacer}+{sep}{f'%s{sep*3}'*(cols-1)}%s{sep}+"
separator_sub = tuple([sep*x for x in lens])
separator = separator_str % separator_sub
data_str = f"{self.spacer}| {'%s | '*(cols-1)}%s |"
# top of ascii table
print('')
print(separator)
# ascii table data
if title:
print(f"{self.spacer}| {title.center(tdata_len)} |")
print(separator)
if header:
rdata = tdata.pop(0)
data_sub = tuple([rdata[i].center(lens[i]) for i in range(0,cols)])
print(data_str % data_sub)
print(separator)
for rdata in tdata:
data_sub = tuple([self.to_unicode_str(rdata[i]).ljust(lens[i]) if rdata[i] != None else ''.ljust(lens[i]) for i in range(0,cols)])
print(data_str % data_sub)
if linear:
print(separator)
if not linear:
# bottom of ascii table
print(separator)
print('')
# ==================================================
# EXPORT METHODS
# ==================================================
示例14: do_history
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def do_history(self, params):
'''Manage history of commands'''
if not params:
self.help_history()
return
params = params.split()
arg = params.pop(0).lower()
cmds = self._get_history()
if arg == 'list':
if len(cmds) > 50:
cmds = cmds[:50]
header = '\nCommands:\n'
print(header + self.ruler * len(header[2:]))
for i in cmds:
print(''.ljust(5) + i)
print('')
elif arg == 'clear':
self._init_history(reborn=True)
elif (arg == 'from' and params) or arg == "all":
try:
if params:
to = int(params[0])
else:
# Show all commands
to = 0
except TypeError:
print('Usage: history from <num>')
else:
header = '\nCommands:\n'
print(header + self.ruler * len(header[2:]))
# Limit the show commands
if len(cmds) > to:
cmds = cmds[to:]
for i in cmds:
print(''.ljust(5) + i)
print('')
elif arg == 'status':
print(f'History logger: {self._global_options["history"]}')
elif arg == 'on':
self._global_options['history'] = True
elif arg == 'off':
self._global_options['history'] = False
else:
self.help_history()
示例15: table
# 需要导入模块: import cmd [as 别名]
# 或者: from cmd import ljust [as 别名]
def table(self, data, header=[], title=''):
'''Accepts a list of rows and outputs a table.'''
tdata = list(data)
if header:
tdata.insert(0, header)
if len(set([len(x) for x in tdata])) > 1:
raise FrameworkException('Row lengths not consistent.')
lens = []
cols = len(tdata[0])
# create a list of max widths for each column
for i in range(0,cols):
lens.append(len(max([self.to_unicode_str(x[i]) if x[i] != None else '' for x in tdata], key=len)))
# calculate dynamic widths based on the title
title_len = len(title)
tdata_len = sum(lens) + (3*(cols-1))
diff = title_len - tdata_len
if diff > 0:
diff_per = diff / cols
lens = [x+diff_per for x in lens]
diff_mod = diff % cols
for x in range(0, diff_mod):
lens[x] += 1
# build ascii table
if len(tdata) > 0:
separator_str = '%s+-%s%%s-+' % (self.spacer, '%s---'*(cols-1))
separator_sub = tuple(['-'*x for x in lens])
separator = separator_str % separator_sub
data_str = '%s| %s%%s |' % (self.spacer, '%s | '*(cols-1))
# top of ascii table
print('')
print(separator)
# ascii table data
if title:
print('%s| %s |' % (self.spacer, title.center(tdata_len)))
print(separator)
if header:
rdata = tdata.pop(0)
data_sub = tuple([rdata[i].center(lens[i]) for i in range(0,cols)])
print(data_str % data_sub)
print(separator)
for rdata in tdata:
data_sub = tuple([self.to_unicode_str(rdata[i]).ljust(lens[i]) if rdata[i] != None else ''.ljust(lens[i]) for i in range(0,cols)])
print(data_str % data_sub)
# bottom of ascii table
print(separator)
print('')
#==================================================
# DATABASE METHODS
#==================================================