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
3cf5300b
Unverified
Commit
3cf5300b
authored
Nov 26, 2021
by
Philipp Sommer
Browse files
use show instead of report when it comes to display methods
parent
bc8f5d52
Changes
2
Hide whitespace changes
Inline
Side-by-side
deprogressapi/progress_report.py
View file @
3cf5300b
...
...
@@ -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
Report
M
et
hod
,
Report
S
et
tings
from
deprogressapi.settings
import
Report
S
et
tings
,
Show
Report
M
et
hod
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
==
Show
ReportMethod
.
print_
:
self
.
show_
print
()
elif
method
==
Show
ReportMethod
.
curses
:
self
.
show
_curses
()
def
print
_
(
self
):
print
(
self
.
re
nder_report
())
def
show_
print
(
self
):
print
(
self
.
re
port_as_string
())
def
print
_curses
(
self
):
def
show
_curses
(
self
):
"""Update the :attr:`window`."""
report
=
self
.
re
nder_report
()
report
=
self
.
re
port_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
re
nder_report
(
self
)
->
str
:
def
re
port_to_string
(
self
)
->
str
:
return
self
.
json
(
indent
=
2
)
def
complete
(
self
,
status
:
Status
=
Status
.
SUCCESS
):
...
...
deprogressapi/settings.py
View file @
3cf5300b
...
...
@@ -8,7 +8,7 @@ def is_running_in_notebook():
"""Test if we are running inside a notebook."""
class
ReportMethod
(
str
,
Enum
):
class
Show
ReportMethod
(
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
:
Show
ReportMethod
=
Field
(
Show
ReportMethod
.
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
)
->
Show
ReportMethod
:
"""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
Show
ReportMethod
.
curses
try
:
shell
=
get_ipython
().
__class__
.
__name__
if
shell
==
"ZMQInteractiveShell"
:
method
=
ReportMethod
.
jupyter
method
=
Show
ReportMethod
.
jupyter
except
NameError
:
pass
return
method
def
get_
report
_method
(
self
)
->
ReportMethod
:
if
self
.
report
_method
==
ReportMethod
.
auto
:
def
get_
show
_method
(
self
)
->
Show
ReportMethod
:
if
self
.
show
_method
==
Show
ReportMethod
.
auto
:
return
self
.
auto_report_method
else
:
return
self
.
report
_method
return
self
.
show
_method
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