avocado: Paginator changes

Some plugins don't really need to be started in paginator
mode (such as the test runner). Only plugins that need to
list things as opposed to execute test operations will
need it. Therefore:

1) Remove use_paginator=True from test runner, remote
   and vm plugins
2) Add use_paginator=True for the test lister plugin
3) Fix bug in paginator use that will make echo to
   be turned off if you use the paginator (causing
   input to not be displayed in your terminal after
   you use 'avocado list', for example).

The problem with the paginator bug is that it is
explicitly necessary to close the paginator once
we are done with it, as opposed to let it get
garbage collected. For that, we introduced the method
View.cleanup().
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 7f5dde3a
......@@ -71,15 +71,18 @@ class Paginator(object):
self.pipe = os.popen(paginator, 'w')
def __del__(self):
self.close()
def close(self):
try:
self.pipe.close()
except IOError:
except:
pass
def write(self, msg):
try:
self.pipe.write(msg)
except IOError:
except:
pass
......@@ -366,6 +369,10 @@ class View(object):
self.throbber = Throbber()
self.tests_info = {}
def cleanup(self):
if self.use_paginator:
self.paginator.close()
def notify(self, event='message', msg=None):
mapping = {'message': self._log_ui_header,
'minor': self._log_ui_minor,
......
......@@ -49,3 +49,4 @@ class PluginsList(plugin.Plugin):
else:
status = "(Disabled)"
view.notify(event='minor', msg=format_str % (plug.name, plug.description, status))
view.cleanup()
......@@ -223,7 +223,7 @@ class RunRemote(plugin.Plugin):
if missing:
from avocado.core import output, exit_codes
import sys
view = output.View(app_args=app_args, use_paginator=True)
view = output.View(app_args=app_args)
e_msg = ('Use of %s requires %s arguments to be set. Please set %s'
'.' % (enable_arg, ', '.join(required_args),
', '.join(missing)))
......
......@@ -125,7 +125,7 @@ class TestRunner(plugin.Plugin):
:param args: Command line args received from the run subparser.
"""
view = output.View(app_args=args, use_paginator=True)
view = output.View(app_args=args)
if args.unique_job_id is not None:
try:
int(args.unique_job_id, 16)
......
......@@ -62,7 +62,7 @@ class TestLister(plugin.Plugin):
:param args: Command line args received from the list subparser.
"""
self.view = output.View(app_args=args)
self.view = output.View(app_args=args, use_paginator=True)
paths = [data_dir.get_test_dir()]
if args.paths:
......@@ -154,13 +154,16 @@ class TestLister(plugin.Plugin):
stats['broken_symlink']))
def run(self, args):
rc = 0
try:
self._run(args)
except KeyboardInterrupt:
rc = exit_codes.AVOCADO_FAIL
msg = ('Command interrupted by '
'user...')
if self.view is not None:
self.view.notify(event='error', msg=msg)
else:
sys.stderr.write(msg)
sys.exit(exit_codes.AVOCADO_FAIL)
self.view.cleanup()
sys.exit(rc)
......@@ -146,7 +146,7 @@ class RunVM(plugin.Plugin):
if missing:
from avocado.core import output, exit_codes
import sys
view = output.View(app_args=app_args, use_paginator=True)
view = output.View(app_args=app_args)
e_msg = ('Use of %s requires %s arguments to be set. Please set %s'
'.' % (enable_arg, ', '.join(required_args),
', '.join(missing)))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册