Skip to content

Commit faeb1c1

Browse files
committed
add a Simplified example for streamed artifacts
Going through an object adds a lot of complication. Adding example for unzipping on the fly
1 parent 1ca3080 commit faeb1c1

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

docs/gl_objects/builds.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
build_or_job.artifacts()
7373
# end artifacts
7474

75-
# stream artifacts
75+
# stream artifacts with class
7676
class Foo(object):
7777
def __init__(self):
7878
self._fd = open('artifacts.zip', 'wb')
@@ -83,7 +83,15 @@ def __call__(self, chunk):
8383
target = Foo()
8484
build_or_job.artifacts(streamed=True, action=target)
8585
del(target) # flushes data on disk
86-
# end stream artifacts
86+
# end stream artifacts with class
87+
88+
# stream artifacts with unzip
89+
zipfn = "___artifacts.zip"
90+
with open(zipfn, "wb") as f:
91+
build_or_job.artifacts(streamed=True, action=f.write)
92+
subprocess.run(["unzip", "-bo", zipfn])
93+
os.unlink(zipfn)
94+
# end stream artifacts with unzip
8795

8896
# keep artifacts
8997
build_or_job.keep_artifacts()

docs/gl_objects/builds.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,14 @@ You can download artifacts as a stream. Provide a callable to handle the
201201
stream:
202202

203203
.. literalinclude:: builds.py
204-
:start-after: # stream artifacts
205-
:end-before: # end stream artifacts
204+
:start-after: # stream artifacts with class
205+
:end-before: # end stream artifacts with class
206+
207+
In this second example, you can directly stream the output into a file, and unzip it afterwards:
208+
209+
.. literalinclude:: builds.py
210+
:start-after: # stream artifacts with unzip
211+
:end-before: # end stream artifacts with unzip
206212

207213
Mark a job artifact as kept when expiration is set:
208214

0 commit comments

Comments
 (0)