Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-pipeline
csst_common
Commits
0dd6f9d4
Commit
0dd6f9d4
authored
Dec 25, 2023
by
BO ZHANG
🏀
Browse files
implement Pipeline.message.write() and Pipeline.timestamp.record()
parent
43be4795
Pipeline
#2731
passed with stage
in 0 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
csst_common/pipeline.py
View file @
0dd6f9d4
...
...
@@ -266,18 +266,21 @@ class Message:
def
__repr__
(
self
):
return
f
"< Message [
{
self
.
file_path
}
] >"
def
write
(
self
,
dlist
):
def
write
(
self
,
dlist
:
list
[
dict
]):
"""Write messages to file."""
with
open
(
self
.
file_path
,
"w+"
)
as
f
:
for
d
in
dlist
:
f
.
write
(
self
.
dict2msg
(
d
)
+
"
\n
"
)
@
staticmethod
def
dict2msg
(
d
):
def
dict2msg
(
d
:
dict
):
"""Convert `dict` to JSON format string."""
m
=
json
.
dumps
(
d
).
replace
(
" "
,
""
)
return
m
@
staticmethod
def
msg2dict
(
m
):
def
msg2dict
(
m
:
str
):
"""Convert JSON format string to `dict`."""
d
=
json
.
loads
(
m
)
return
d
...
...
@@ -322,8 +325,8 @@ class Timestamp:
with
open
(
self
.
file_path
,
"w"
)
as
file
:
file
.
truncate
(
0
)
def
touch
(
self
):
"""
Write
a time stamp."""
def
record
(
self
):
"""
Record
a time stamp."""
with
open
(
self
.
file_path
,
"a+"
)
as
f
:
f
.
write
(
f
"
{
Time
.
now
().
isot
}
+00:00
\n
"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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