diff options
author | Nejc Habjan <hab.nejc@gmail.com> | 2020-04-05 16:12:11 +0200 |
---|---|---|
committer | Nejc Habjan <hab.nejc@gmail.com> | 2020-04-05 16:12:11 +0200 |
commit | 6ce5d1f14060a403f05993d77bf37720c25534ba (patch) | |
tree | dbede14206cb7466a3abfee99cea8b2d13f2b4d0 /gitlab/mixins.py | |
parent | 50fcd1237613645031410386e87b96b81ef5fb78 (diff) | |
download | gitlab-6ce5d1f14060a403f05993d77bf37720c25534ba.tar.gz |
chore(mixins): factor out export download into ExportMixin
Diffstat (limited to 'gitlab/mixins.py')
-rw-r--r-- | gitlab/mixins.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/gitlab/mixins.py b/gitlab/mixins.py index dde11d0..39d13c9 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -443,6 +443,35 @@ class AccessRequestMixin(object): self._update_attrs(server_data) +class ExportMixin(object): + @cli.register_custom_action("ProjectExport") + @exc.on_http_error(exc.GitlabGetError) + def download(self, streamed=False, action=None, chunk_size=1024, **kwargs): + """Download the archive of a resource export. + + Args: + streamed (bool): If True the data will be processed by chunks of + `chunk_size` and each chunk is passed to `action` for + reatment + action (callable): Callable responsible of dealing with chunk of + data + chunk_size (int): Size of each chunk + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabGetError: If the server failed to perform the request + + Returns: + str: The blob content if streamed is False, None otherwise + """ + path = "%s/download" % (self.manager.path) + result = self.manager.gitlab.http_get( + path, streamed=streamed, raw=True, **kwargs + ) + return utils.response_content(result, streamed, action, chunk_size) + + class SubscribableMixin(object): @cli.register_custom_action( ("ProjectIssue", "ProjectMergeRequest", "ProjectLabel", "GroupLabel") |