Skip to content

Commit

Permalink
Merge pull request #634 from lmr/add-paginator-config
Browse files Browse the repository at this point in the history
avocado config: Add --paginator to command
  • Loading branch information
lmr committed Jun 8, 2015
2 parents b18a056 + c6f84d0 commit 0267379
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
71 changes: 39 additions & 32 deletions avocado/core/plugins/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,48 @@ def configure(self, parser):
help='Shows avocado config keys')
self.parser.add_argument('--datadir', action='store_true', default=False,
help='Shows the data directories currently being used by avocado')
self.parser.add_argument('--paginator',
choices=('on', 'off'), default='on',
help='Turn the paginator on/off. '
'Current: %(default)s')
super(ConfigOptions, self).configure(self.parser)

def run(self, args):
view = output.View()
view.notify(event="message", msg='Config files read (in order):')
for cfg_path in settings.config_paths:
view.notify(event="message", msg=' %s' % cfg_path)
if settings.config_paths_failed:
view = output.View(use_paginator=(args.paginator == 'on'))
try:
view.notify(event="message", msg='Config files read (in order):')
for cfg_path in settings.config_paths:
view.notify(event="message", msg=' %s' % cfg_path)
if settings.config_paths_failed:
view.notify(event="minor", msg='')
view.notify(event="error", msg='Config files that failed to read:')
for cfg_path in settings.config_paths_failed:
view.notify(event="error", msg=' %s' % cfg_path)
view.notify(event="minor", msg='')
view.notify(event="error", msg='Config files that failed to read:')
for cfg_path in settings.config_paths_failed:
view.notify(event="error", msg=' %s' % cfg_path)
view.notify(event="minor", msg='')
if not args.datadir:
blength = 0
for section in settings.config.sections():
for value in settings.config.items(section):
clength = len('%s.%s' % (section, value[0]))
if clength > blength:
blength = clength
if not args.datadir:
blength = 0
for section in settings.config.sections():
for value in settings.config.items(section):
clength = len('%s.%s' % (section, value[0]))
if clength > blength:
blength = clength

format_str = " %-" + str(blength) + "s %s"
format_str = " %-" + str(blength) + "s %s"

view.notify(event="minor", msg=format_str % ('Section.Key', 'Value'))
for section in settings.config.sections():
for value in settings.config.items(section):
config_key = ".".join((section, value[0]))
view.notify(event="minor", msg=format_str % (config_key, value[1]))
else:
view.notify(event="minor", msg="Avocado replaces config dirs that can't be accessed")
view.notify(event="minor", msg="with sensible defaults. Please edit your local config")
view.notify(event="minor", msg="file to customize values")
view.notify(event="message", msg='')
view.notify(event="message", msg='Avocado Data Directories:')
view.notify(event="minor", msg=' base ' + data_dir.get_base_dir())
view.notify(event="minor", msg=' tests ' + data_dir.get_test_dir())
view.notify(event="minor", msg=' data ' + data_dir.get_data_dir())
view.notify(event="minor", msg=' logs ' + data_dir.get_logs_dir())
view.notify(event="minor", msg=format_str % ('Section.Key', 'Value'))
for section in settings.config.sections():
for value in settings.config.items(section):
config_key = ".".join((section, value[0]))
view.notify(event="minor", msg=format_str % (config_key, value[1]))
else:
view.notify(event="minor", msg="Avocado replaces config dirs that can't be accessed")
view.notify(event="minor", msg="with sensible defaults. Please edit your local config")
view.notify(event="minor", msg="file to customize values")
view.notify(event="message", msg='')
view.notify(event="message", msg='Avocado Data Directories:')
view.notify(event="minor", msg=' base ' + data_dir.get_base_dir())
view.notify(event="minor", msg=' tests ' + data_dir.get_test_dir())
view.notify(event="minor", msg=' data ' + data_dir.get_data_dir())
view.notify(event="minor", msg=' logs ' + data_dir.get_logs_dir())
finally:
view.cleanup()
4 changes: 2 additions & 2 deletions selftests/all/functional/avocado/basic_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def test_plugin_list(self):

def test_config_plugin(self):
os.chdir(basedir)
cmd_line = './scripts/avocado config'
cmd_line = './scripts/avocado config --paginator off'
result = process.run(cmd_line, ignore_status=True)
output = result.stdout
expected_rc = 0
Expand All @@ -405,7 +405,7 @@ def test_config_plugin(self):

def test_config_plugin_datadir(self):
os.chdir(basedir)
cmd_line = './scripts/avocado config --datadir'
cmd_line = './scripts/avocado config --datadir --paginator off'
result = process.run(cmd_line, ignore_status=True)
output = result.stdout
expected_rc = 0
Expand Down

0 comments on commit 0267379

Please sign in to comment.