Unverified Commit 3cf5300b authored by Philipp Sommer's avatar Philipp Sommer
Browse files

use show instead of report when it comes to display methods

parent bc8f5d52
......@@ -4,7 +4,7 @@ import curses
from enum import Enum
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type, Union
from deprogressapi.settings import ReportMethod, ReportSettings
from deprogressapi.settings import ReportSettings, ShowReportMethod
from pydantic import BaseModel, Field, create_model
......@@ -97,7 +97,7 @@ class BaseReport(BaseModel):
"""Submit the report.
This method submits the report and submits it via the pulsar or
calls the :meth:`report` method."""
calls the :meth:`show` method."""
if self._pulsar is not None:
from demessaging.PulsarMessageConstants import (
MessageType,
......@@ -113,9 +113,9 @@ class BaseReport(BaseModel):
response_properties=response_properties,
)
else:
self.report()
self.show()
def report(self) -> None:
def show(self) -> None:
"""Output the report.
This method, supposed to be implemented by subclasses, reports to the
......@@ -123,18 +123,18 @@ class BaseReport(BaseModel):
The default implementation just prints the json string of this report.
"""
method = self._settings.get_report_method()
if method == ReportMethod.print_:
self.print_()
elif method == ReportMethod.curses:
self.print_curses()
method = self._settings.get_show_method()
if method == ShowReportMethod.print_:
self.show_print()
elif method == ShowReportMethod.curses:
self.show_curses()
def print_(self):
print(self.render_report())
def show_print(self):
print(self.report_as_string())
def print_curses(self):
def show_curses(self):
"""Update the :attr:`window`."""
report = self.render_report()
report = self.report_as_string()
height, width = self.window.getmaxyx()
lines = report.splitlines()[-height + 1 :]
report = "\n".join([line[: width - 1] for line in lines])
......@@ -143,7 +143,7 @@ class BaseReport(BaseModel):
self.window.clearok(1)
self.window.refresh()
def render_report(self) -> str:
def report_to_string(self) -> str:
return self.json(indent=2)
def complete(self, status: Status = Status.SUCCESS):
......
......@@ -8,7 +8,7 @@ def is_running_in_notebook():
"""Test if we are running inside a notebook."""
class ReportMethod(str, Enum):
class ShowReportMethod(str, Enum):
"""Methods for reporting."""
auto = "AUTO"
......@@ -23,8 +23,8 @@ class ReportSettings(BaseSettings):
class Config:
env_prefix = "DASF_REPORT_"
report_method: ReportMethod = Field(
ReportMethod.auto,
show_method: ShowReportMethod = Field(
ShowReportMethod.auto,
description="The method to use for printing the reports.",
)
use_curses: bool = Field(
......@@ -33,25 +33,27 @@ class ReportSettings(BaseSettings):
)
@property
def auto_report_method(self) -> ReportMethod:
def auto_report_method(self) -> ShowReportMethod:
"""Automatically determine the report method."""
method = (
ReportMethod.curses if self.use_curses else ReportMethod.print_
ShowReportMethod.curses
if self.use_curses
else ShowReportMethod.print_
)
try:
from IPython import get_ipython
except (ImportError, ModuleNotFoundError):
return ReportMethod.curses
return ShowReportMethod.curses
try:
shell = get_ipython().__class__.__name__
if shell == "ZMQInteractiveShell":
method = ReportMethod.jupyter
method = ShowReportMethod.jupyter
except NameError:
pass
return method
def get_report_method(self) -> ReportMethod:
if self.report_method == ReportMethod.auto:
def get_show_method(self) -> ShowReportMethod:
if self.show_method == ShowReportMethod.auto:
return self.auto_report_method
else:
return self.report_method
return self.show_method
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment