There is no need for subclasses to return the log directly; they can
just get the result, and the log viewer can check whether the result
has a log attached to it.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
mods/git.py | 7 ++-----
mods/testing.py | 5 ++---
patchew/logviewer.py | 14 ++++++++------
3 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/mods/git.py b/mods/git.py
index 2b24b24..a2b6d86 100644
--- a/mods/git.py
+++ b/mods/git.py
@@ -35,15 +35,12 @@ Message.git_result = property(_get_git_result)
class GitLogViewer(LogView):
- def content(self, request, **kwargs):
+ def get_result(self, request, **kwargs):
series = kwargs['series']
obj = Message.objects.find_series(series)
if not obj:
raise Http404("Object not found: " + series)
- r = obj.git_result
- if r is None or not r.is_completed():
- raise Http404("Git apply log not found")
- return r.log
+ return obj.git_result
class GitModule(PatchewModule):
diff --git a/mods/testing.py b/mods/testing.py
index 7dfc5a2..0a80b3d 100644
--- a/mods/testing.py
+++ b/mods/testing.py
@@ -35,7 +35,7 @@ exit 0
"""
class TestingLogViewer(LogView):
- def content(self, request, **kwargs):
+ def get_result(self, request, **kwargs):
project_or_series = kwargs['project_or_series']
testing_name = kwargs['testing_name']
if request.GET.get("type") == "project":
@@ -44,8 +44,7 @@ class TestingLogViewer(LogView):
obj = Message.objects.find_series(project_or_series)
if not obj:
raise Http404("Object not found: " + project_or_series)
- r = _instance.get_testing_result(obj, testing_name)
- return r.log
+ return _instance.get_testing_result(obj, testing_name)
class TestingModule(PatchewModule):
diff --git a/patchew/logviewer.py b/patchew/logviewer.py
index fe0f3ca..9918890 100644
--- a/patchew/logviewer.py
+++ b/patchew/logviewer.py
@@ -436,7 +436,7 @@ def ansi2html(input, white_bg=False):
class LogView(View, metaclass=abc.ABCMeta):
@abc.abstractmethod
- def content(request, **kwargs):
+ def get_result(request, **kwargs):
return None
# Unfortunately <pre> items cannot be focused; for arrow keys to
@@ -463,16 +463,18 @@ if (parent.jQuery && parent.jQuery.colorbox) {
});
}</script><body>""")
- def generate_html(self):
+ def generate_html(self, result):
yield self.HTML_PROLOG
- yield from ansi2html(self.text)
+ yield from ansi2html(result.log)
def get(self, request, **kwargs):
- self.text = self.content(request, **kwargs)
+ result = self.get_result(request, **kwargs)
+ if result is None or not result.is_completed() or result.log is None:
+ raise Http404("No log found")
if request.GET.get('html', None) != '1':
- return HttpResponse(self.text, content_type='text/plain')
+ return HttpResponse(result.log, content_type='text/plain')
- return StreamingHttpResponse(self.generate_html())
+ return StreamingHttpResponse(self.generate_html(result.log))
if __name__ == "__main__":
import io
--
2.17.0
_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel