Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
commit 71390ef55bd0238cb978477c19ce481596182cc5 Author: Peter Hatina phatina@redhat.com Date: Wed Jan 30 15:11:07 2013 +0100
fix pager dimensions issue when using interactive iface
cli-tools/lmi/lmi_client_shell.py | 28 +++++++++++++++++++++------- 1 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 58e183d..b043a5f 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -36,6 +36,9 @@ class LmiUnknownParameterError(Exception): class LmiMethodCallError(Exception): """Raised, when an error occurs within method call"""
+class LmiNoPagerError(Exception): + """Raised, when tere is no default pager like less or more""" + class _LmiTextFormatter(object): def __init__(self, text): self._text = text @@ -55,9 +58,8 @@ class _LmiFormatter(object): __metaclass__ = abc.ABCMeta
def __init__(self): - self._width = int(os.popen('stty size', 'r').read().split()[1]) - if not self._width: - self._width = 80 + stty_dimensions = os.popen("stty size 2> /dev/null", "r").read().split() + self._width = int(stty_dimensions[1]) if stty_dimensions else 80
@abc.abstractmethod def format(self, indent = 0, sub_indent = 0, width = 80, f = sys.stdout): @@ -80,11 +82,19 @@ class _LmiFormatter(object): @staticmethod def __get_pager(): if "PAGER" in os.environ: - return os.environ["PAGER"] + pager = os.environ["PAGER"].split() + if os.path.exists(pager[0]) and os.access(pager[0], X_OK): + return pager for p in ["less", "more"]: path = _LmiFormatter.__which(p) - if path: - return path + if not path: + continue + elif p == "less": + return [path, "-S"] + return [path] + if LmiBaseClient._get_use_exceptions(): + raise LmiNoPagerError("No default pager found") + return []
def fancy_format(self, interactive): if interactive: @@ -92,7 +102,11 @@ class _LmiFormatter(object): f = os.fdopen(tmpfile[0], "w") self.format(0, 0, self._width, f) f.close() - subprocess.call([_LmiFormatter.__get_pager(), tmpfile[1]]) + subprocess_params = _LmiFormatter.__get_pager() + if not subprocess_params: + return + subprocess_params.append(tmpfile[1]) + subprocess.call(subprocess_params) os.remove(tmpfile[1]) else: self.format(0, 0, self._width)
cura-tools-devel@lists.fedorahosted.org