[diffoscope] 04/05: presenters: Instantiate our presenter classes directly instead of wrapping a method
Chris Lamb
chris at chris-lamb.co.uk
Sat Jan 21 12:16:21 CET 2017
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch master
in repository diffoscope.
commit 574f235c81fef7c7f8227a9bcabd0523819cd300
Author: Chris Lamb <lamby at debian.org>
Date: Sat Jan 21 17:59:51 2017 +1100
presenters: Instantiate our presenter classes directly instead of wrapping a method
Signed-off-by: Chris Lamb <lamby at debian.org>
---
diffoscope/presenters/markdown.py | 4 ----
diffoscope/presenters/restructuredtext.py | 4 ----
diffoscope/presenters/text.py | 14 -------------
diffoscope/presenters/utils.py | 34 +++++++++++++++++--------------
4 files changed, 19 insertions(+), 37 deletions(-)
diff --git a/diffoscope/presenters/markdown.py b/diffoscope/presenters/markdown.py
index 88fc4c6..df847c4 100644
--- a/diffoscope/presenters/markdown.py
+++ b/diffoscope/presenters/markdown.py
@@ -48,7 +48,3 @@ class MarkdownTextPresenter(Presenter):
self.print_func("{} {}".format(prefix, val))
self.print_func()
-
-def output_markdown(difference, print_func, color=False):
- presenter = MarkdownTextPresenter(print_func)
- presenter.visit(difference)
diff --git a/diffoscope/presenters/restructuredtext.py b/diffoscope/presenters/restructuredtext.py
index 84bd20d..6f711e6 100644
--- a/diffoscope/presenters/restructuredtext.py
+++ b/diffoscope/presenters/restructuredtext.py
@@ -56,7 +56,3 @@ class RestructuredTextPresenter(Presenter):
self.print_func(val)
self.print_func(len(val) * char)
self.print_func()
-
-def output_restructuredtext(difference, print_func, color=False):
- presenter = RestructuredTextPresenter(print_func)
- presenter.visit(difference)
diff --git a/diffoscope/presenters/text.py b/diffoscope/presenters/text.py
index e8860ea..111fd3c 100644
--- a/diffoscope/presenters/text.py
+++ b/diffoscope/presenters/text.py
@@ -18,15 +18,11 @@
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import re
-import sys
-import logging
from diffoscope.diff import color_unified_diff
from .base import Presenter
-logger = logging.getLogger(__name__)
-
class TextPresenter(Presenter):
PREFIX = u'│ '
@@ -63,13 +59,3 @@ class TextPresenter(Presenter):
r'\1{}'.format(self.PREFIX * (self.depth + 0 if raw else -1)),
val,
))
-
-def output_text(difference, print_func, color=False):
- presenter = TextPresenter(print_func, color)
-
- try:
- presenter.visit(difference)
- except UnicodeEncodeError:
- logger.critical("Console is unable to print Unicode characters. "
- "Set e.g. PYTHONIOENCODING=utf-8")
- sys.exit(2)
diff --git a/diffoscope/presenters/utils.py b/diffoscope/presenters/utils.py
index 3b3d704..b472f34 100644
--- a/diffoscope/presenters/utils.py
+++ b/diffoscope/presenters/utils.py
@@ -24,10 +24,10 @@ import contextlib
from ..profiling import profile
-from .text import output_text
+from .text import TextPresenter
from .html import output_html, output_html_directory
-from .markdown import output_markdown
-from .restructuredtext import output_restructuredtext
+from .markdown import MarkdownTextPresenter
+from .restructuredtext import RestructuredTextPresenter
logger = logging.getLogger(__name__)
@@ -50,11 +50,11 @@ def output_all(difference, parsed_args, has_differences):
'target': parsed_args.html_output,
},
'markdown': {
- 'fn': markdown,
+ 'klass': MarkdownTextPresenter,
'target': parsed_args.markdown_output,
},
'restructuredtext': {
- 'fn': restructuredtext,
+ 'klass': RestructuredTextPresenter,
'target': parsed_args.restructuredtext_output,
},
'html_directory': {
@@ -74,7 +74,12 @@ def output_all(difference, parsed_args, has_differences):
logger.debug("Generating %r output at %r", name, data['target'])
with profile('output', name):
- data['fn'](difference, parsed_args, has_differences)
+ if 'fn' in data:
+ data['fn'](difference, parsed_args, has_differences)
+ continue
+
+ with make_printer(data['target']) as fn:
+ data['klass'](fn).visit(difference)
def text(difference, parsed_args, has_differences):
# As a special case, write an empty file instead of an empty diff.
@@ -89,7 +94,14 @@ def text(difference, parsed_args, has_differences):
'always': True,
}[parsed_args.text_color]
- output_text(difference, print_func=fn, color=color)
+ presenter = TextPresenter(fn, color)
+
+ try:
+ presenter.visit(difference)
+ except UnicodeEncodeError:
+ logger.critical("Console is unable to print Unicode characters. "
+ "Set e.g. PYTHONIOENCODING=utf-8")
+ sys.exit(2)
def html(difference, parsed_args, has_differences):
with make_printer(parsed_args.html_output) as fn:
@@ -99,14 +111,6 @@ def html(difference, parsed_args, has_differences):
print_func=fn,
)
-def markdown(difference, parsed_args, has_differences):
- with make_printer(parsed_args.markdown_output) as fn:
- output_markdown(difference, print_func=fn)
-
-def restructuredtext(difference, parsed_args, has_differences):
- with make_printer(parsed_args.restructuredtext_output) as fn:
- output_restructuredtext(difference, print_func=fn)
-
def html_directory(difference, parsed_args, has_differences):
output_html_directory(
parsed_args.html_output_directory,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list