Check pager's executable before subprocess.Popen

Get the value of `PAGER` environment variable in case it's defined, check the executable, if it exists - use a pager, otherwise - print function.

Fixes: https://pagure.io/freeipa/issue/7746
Reviewed-By: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
This commit is contained in:
Oleg Kozlov
2018-12-05 14:54:29 +01:00
parent 03edd82d1a
commit a0e09526b3
3 changed files with 43 additions and 5 deletions

View File

@@ -49,7 +49,7 @@ import six
from six.moves import input
from ipalib.util import (
check_client_configuration, get_terminal_height, open_in_pager
check_client_configuration, get_pager, get_terminal_height, open_in_pager
)
if six.PY3:
@@ -721,9 +721,11 @@ class help(frontend.Local):
self.buffer.append(unicode(string))
def write(self):
if self.buffer_length > get_terminal_height():
pager = get_pager()
if pager and self.buffer_length > get_terminal_height():
data = "\n".join(self.buffer).encode("utf-8")
open_in_pager(data)
open_in_pager(data, pager)
else:
try:
for line in self.buffer: