mirror of https://github.com/tLDP/python-tldp
better production of status list
This commit is contained in:
parent
e9ad013eb3
commit
57055e582d
|
@ -6,11 +6,12 @@ from __future__ import absolute_import, division, print_function
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
from argparse import Namespace
|
||||||
|
|
||||||
import tldp
|
import tldp
|
||||||
|
from tldp.utils import arg_isloglevel
|
||||||
|
|
||||||
from argparse import Namespace
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def detail(config, args):
|
def detail(config, args):
|
||||||
|
@ -54,12 +55,14 @@ def status(config, args):
|
||||||
print('\t'.join(getattr(i, status).keys()))
|
print('\t'.join(getattr(i, status).keys()))
|
||||||
else:
|
else:
|
||||||
abbrev = getattr(i, status).keys()
|
abbrev = getattr(i, status).keys()
|
||||||
displaynum = 3
|
s = ''
|
||||||
if len(abbrev) > displaynum:
|
if abbrev:
|
||||||
abbrev = abbrev[:displaynum]
|
s = s + abbrev.pop(0)
|
||||||
remainder = count - displaynum
|
while abbrev and len(s) < 50:
|
||||||
abbrev.append('[and %d more]' % (remainder,))
|
s = s + ', ' + abbrev.pop()
|
||||||
print('\t'.join(abbrev))
|
if abbrev:
|
||||||
|
s = s + ', and %d more ...' % (len(abbrev))
|
||||||
|
print(s)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,10 +104,20 @@ def build(config, args):
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
|
# -- may want to see option parsing, so set --loglevel as
|
||||||
|
# soon as possible
|
||||||
|
if '--loglevel' in sys.argv:
|
||||||
|
levelarg = 1 + sys.argv.index('--loglevel')
|
||||||
|
level = arg_isloglevel(sys.argv[levelarg])
|
||||||
|
logger.setLevel(level)
|
||||||
|
|
||||||
|
# -- produce a configuration from CLI, ENV and CFG
|
||||||
|
#
|
||||||
tag = os.path.basename(sys.argv[0]).strip('.py')
|
tag = os.path.basename(sys.argv[0]).strip('.py')
|
||||||
argv = sys.argv[1:]
|
argv = sys.argv[1:]
|
||||||
config, args = tldp.config.collectconfiguration(tag, argv)
|
config, args = tldp.config.collectconfiguration(tag, argv)
|
||||||
|
|
||||||
|
|
||||||
# -- check to see if the user wishes to --list things
|
# -- check to see if the user wishes to --list things
|
||||||
# this function and friends is called 'detail', because
|
# this function and friends is called 'detail', because
|
||||||
# Python reserves a special (fundamental) meaning for the word
|
# Python reserves a special (fundamental) meaning for the word
|
||||||
|
@ -127,5 +140,9 @@ def run():
|
||||||
config.all = True
|
config.all = True
|
||||||
sys.exit(build(config, args))
|
sys.exit(build(config, args))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run()
|
||||||
|
|
||||||
#
|
#
|
||||||
# -- end of file
|
# -- end of file
|
||||||
|
|
Loading…
Reference in New Issue