Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-journal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nicolas Dandrimont
swh-journal
Commits
a208f882
Commit
a208f882
authored
2 years ago
by
David Douard
Browse files
Options
Downloads
Patches
Plain Diff
Make the stream journal client accept a string as output_stream config entry
and support the "-" value (for stdout).
parent
0e90328a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/journal/tests/test_stream.py
+36
-0
36 additions, 0 deletions
swh/journal/tests/test_stream.py
swh/journal/writer/__init__.py
+11
-1
11 additions, 1 deletion
swh/journal/writer/__init__.py
with
47 additions
and
1 deletion
swh/journal/tests/test_stream.py
+
36
−
0
View file @
a208f882
...
...
@@ -23,6 +23,7 @@ def fill_writer(writer: JournalWriterInterface) -> List[Tuple[str, Dict]]:
objd
.
pop
(
"
data
"
)
expected
.
append
((
object_type
,
objd
))
writer
.
flush
()
return
expected
...
...
@@ -41,3 +42,38 @@ def test_stream_journal_writer_stream():
for
i
,
(
objtype
,
objd
)
in
enumerate
(
unpacker
,
start
=
1
):
assert
(
objtype
,
objd
)
in
expected
assert
len
(
expected
)
==
i
def
test_stream_journal_writer_filename
(
tmp_path
):
out_fname
=
str
(
tmp_path
/
"
journal.msgpack
"
)
writer
=
get_journal_writer
(
cls
=
"
stream
"
,
value_sanitizer
=
model_object_dict_sanitizer
,
output_stream
=
out_fname
,
)
expected
=
fill_writer
(
writer
)
with
open
(
out_fname
,
"
rb
"
)
as
outs
:
unpacker
=
kafka_stream_to_value
(
outs
)
for
i
,
(
objtype
,
objd
)
in
enumerate
(
unpacker
,
start
=
1
):
assert
(
objtype
,
objd
)
in
expected
assert
len
(
expected
)
==
i
def
test_stream_journal_writer_stdout
(
capfdbinary
):
writer
=
get_journal_writer
(
cls
=
"
stream
"
,
value_sanitizer
=
model_object_dict_sanitizer
,
output_stream
=
"
-
"
,
)
expected
=
fill_writer
(
writer
)
captured
=
capfdbinary
.
readouterr
()
assert
captured
.
err
==
b
""
outs
=
io
.
BytesIO
(
captured
.
out
)
unpacker
=
kafka_stream_to_value
(
outs
)
for
i
,
(
objtype
,
objd
)
in
enumerate
(
unpacker
,
start
=
1
):
assert
(
objtype
,
objd
)
in
expected
assert
len
(
expected
)
==
i
This diff is collapsed.
Click to expand it.
swh/journal/writer/__init__.py
+
11
−
1
View file @
a208f882
...
...
@@ -3,7 +3,9 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
from
typing
import
Any
,
Dict
,
Type
import
os
import
sys
from
typing
import
Any
,
BinaryIO
,
Dict
,
Type
import
warnings
from
.interface
import
JournalWriterInterface
...
...
@@ -50,6 +52,14 @@ def get_journal_writer(cls, **kwargs) -> JournalWriterInterface:
JournalWriter
=
StreamJournalWriter
assert
"
output_stream
"
in
kwargs
outstream
:
BinaryIO
if
kwargs
[
"
output_stream
"
]
in
(
"
-
"
,
b
"
-
"
):
outstream
=
os
.
fdopen
(
sys
.
stdout
.
fileno
(),
"
wb
"
,
closefd
=
False
)
elif
isinstance
(
kwargs
[
"
output_stream
"
],
(
str
,
bytes
)):
outstream
=
open
(
kwargs
[
"
output_stream
"
],
"
wb
"
)
else
:
outstream
=
kwargs
[
"
output_stream
"
]
kwargs
[
"
output_stream
"
]
=
outstream
else
:
raise
ValueError
(
"
Unknown journal writer class `%s`
"
%
cls
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment