8000 Simplify the example for streamed artifacts by tardyp · Pull Request #419 · python-gitlab/python-gitlab · GitHub
[go: up one dir, main page]

Skip to content

Simplify the example for streamed artifacts #419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/gl_objects/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
build_or_job.artifacts()
# end artifacts

# stream artifacts
# stream artifacts with class
class Foo(object):
def __init__(self):
self._fd = open('artifacts.zip', 'wb')
Expand All @@ -83,7 +83,15 @@ def __call__(self, chunk):
target = Foo()
build_or_job.artifacts(streamed=True, action=target)
del(target) # flushes data on disk
# end stream artifacts
# end stream artifacts with class

# stream artifacts with unzip
zipfn = "___artifacts.zip"
with open(zipfn, "wb") as f:
build_or_job.artifacts(streamed=True, action=f.write)
subprocess.run(["unzip", "-bo", zipfn])
os.unlink(zipfn)
# end stream artifacts with unzip

# keep artifacts
build_or_job.keep_artifacts()
Expand Down
10 changes: 8 additions & 2 deletions docs/gl_objects/builds.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,14 @@ You can download artifacts as a stream. Provide a callable to handle the
stream:

.. literalinclude:: builds.py
:start-after: # stream artifacts
:end-before: # end stream artifacts
:start-after: # stream artifacts with class
:end-before: # end stream artifacts with class

In this second example, you can directly stream the output into a file, and unzip it afterwards:

.. literalinclude:: builds.py
:start-after: # stream artifacts with unzip
:end-before: # end stream artifacts with unzip

Mark a job artifact as kept when expiration is set:

Expand Down
0