From 92e2f54228269a75a12f4612e1d5fe79802adcd9 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 14 Aug 2015 22:00:15 -0400 Subject: [PATCH] fixed issues with utf-8 encoding in docs, moved pager to use display class instad of bare prints --- lib/ansible/cli/__init__.py | 15 +++++++-------- lib/ansible/cli/doc.py | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index a9599da1a47..f21d3528f36 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -432,21 +432,20 @@ class CLI(object): return result - @staticmethod - def pager(text): + def pager(self, text): ''' find reasonable way to display text ''' # this is a much simpler form of what is in pydoc.py if not sys.stdout.isatty(): - print(text) + self.display.display(text) elif 'PAGER' in os.environ: if sys.platform == 'win32': - print(text) + self.display.display(text) else: - CLI.pager_pipe(text, os.environ['PAGER']) + self.pager_pipe(text, os.environ['PAGER']) elif subprocess.call('(less --version) 2> /dev/null', shell = True) == 0: - CLI.pager_pipe(text, 'less') + self.pager_pipe(text, 'less') else: - print(text) + self.display.display(text) @staticmethod def pager_pipe(text, cmd): @@ -455,7 +454,7 @@ class CLI(object): os.environ['LESS'] = CLI.LESS_OPTS try: cmd = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=sys.stdout) - cmd.communicate(input=text) + cmd.communicate(input=text.encode(sys.stdout.encoding)) except IOError: pass except KeyboardInterrupt: diff --git a/lib/ansible/cli/doc.py b/lib/ansible/cli/doc.py index 910255cda77..dfdb8583ec3 100644 --- a/lib/ansible/cli/doc.py +++ b/lib/ansible/cli/doc.py @@ -73,7 +73,7 @@ class DocCLI(CLI): for path in paths: self.find_modules(path) - CLI.pager(self.get_module_list_text()) + self.pager(self.get_module_list_text()) return 0 if len(self.args) == 0: @@ -125,7 +125,7 @@ class DocCLI(CLI): self.display.vvv(traceback.print_exc()) raise AnsibleError("module %s missing documentation (or could not parse documentation): %s\n" % (module, str(e))) - CLI.pager(text) + self.pager(text) return 0 def find_modules(self, path):