Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
digitalearth
DASF Data Analytics Software Framework
dasf-progress-api
Commits
3f1511d9
Unverified
Commit
3f1511d9
authored
Dec 03, 2021
by
Philipp Sommer
Browse files
add show_methods class attribute for reports
parent
f274aea3
Pipeline
#35643
failed with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
deprogressapi/base.py
View file @
3f1511d9
...
...
@@ -2,7 +2,16 @@ from __future__ import annotations
import
curses
from
enum
import
Enum
from
typing
import
TYPE_CHECKING
,
Any
,
Dict
,
Optional
,
Type
,
Union
from
typing
import
(
TYPE_CHECKING
,
Any
,
Callable
,
ClassVar
,
Dict
,
Optional
,
Type
,
Union
,
)
from
deprogressapi.settings
import
ReportSettings
,
ShowReportMethod
from
pydantic
import
BaseModel
,
Field
,
create_model
...
...
@@ -35,6 +44,12 @@ class BaseReport(BaseModel):
_response_properties
:
Optional
[
Dict
]
=
None
_window
:
Optional
[
curses
.
window
]
=
None
# type: ignore
show_methods
:
ClassVar
[
Dict
[
ShowReportMethod
,
str
]]
=
{
ShowReportMethod
.
none
:
"show_none"
,
ShowReportMethod
.
print_
:
"show_print"
,
ShowReportMethod
.
curses
:
"show_curses"
,
}
# settings for this report
settings
:
ReportSettings
=
Field
(
default_factory
=
ReportSettings
,
description
=
"Settings for the report."
...
...
@@ -181,18 +196,13 @@ class BaseReport(BaseModel):
def
show
(
self
)
->
None
:
"""Output the report.
This method, supposed to be implemented by subclasses, reports to the
final user on the command-line.
The default implementation just prints the json string of this report.
This uses the methods defined in the :attr:`show_methods` attribute
based on the specified show method in the :attr:`settings`.
"""
method
=
self
.
settings
.
get_show_method
()
if
method
==
ShowReportMethod
.
print_
:
self
.
show_print
()
elif
method
==
ShowReportMethod
.
curses
:
self
.
show_curses
()
elif
method
==
ShowReportMethod
.
none
:
self
.
show_none
()
method_identifier
=
self
.
settings
.
get_show_method
()
method_name
=
self
.
show_methods
[
method_identifier
]
method
:
Callable
[[],
None
]
=
getattr
(
self
,
method_name
)
return
method
()
def
show_print
(
self
)
->
None
:
"""Show the report using pythons built-in :func:`print` function."""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment