Skip to content

Commit 6ce5d1f

Browse files
committed
chore(mixins): factor out export download into ExportMixin
1 parent 50fcd12 commit 6ce5d1f

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

gitlab/mixins.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,35 @@ def approve(self, access_level=gitlab.DEVELOPER_ACCESS, **kwargs):
443443
self._update_attrs(server_data)
444444

445445

446+
class ExportMixin(object):
447+
@cli.register_custom_action("ProjectExport")
448+
@exc.on_http_error(exc.GitlabGetError)
449+
def download(self, streamed=False, action=None, chunk_size=1024, **kwargs):
450+
"""Download the archive of a resource export.
451+
452+
Args:
453+
streamed (bool): If True the data will be processed by chunks of
454+
`chunk_size` and each chunk is passed to `action` for
455+
reatment
456+
action (callable): Callable responsible of dealing with chunk of
457+
data
458+
chunk_size (int): Size of each chunk
459+
**kwargs: Extra options to send to the server (e.g. sudo)
460+
461+
Raises:
462+
GitlabAuthenticationError: If authentication is not correct
463+
GitlabGetError: If the server failed to perform the request
464+
465+
Returns:
466+
str: The blob content if streamed is False, None otherwise
467+
"""
468+
path = "%s/download" % (self.manager.path)
469+
result = self.manager.gitlab.http_get(
470+
path, streamed=streamed, raw=True, **kwargs
471+
)
472+
return utils.response_content(result, streamed, action, chunk_size)
473+
474+
446475
class SubscribableMixin(object):
447476
@cli.register_custom_action(
448477
("ProjectIssue", "ProjectMergeRequest", "ProjectLabel", "GroupLabel")

gitlab/v4/objects.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4097,36 +4097,9 @@ class ProjectWikiManager(CRUDMixin, RESTManager):
40974097
_list_filters = ("with_content",)
40984098

40994099

4100-
class ProjectExport(RefreshMixin, RESTObject):
4100+
class ProjectExport(ExportMixin, RefreshMixin, RESTObject):
41014101
_id_attr = None
41024102

4103-
@cli.register_custom_action("ProjectExport")
4104-
@exc.on_http_error(exc.GitlabGetError)
4105-
def download(self, streamed=False, action=None, chunk_size=1024, **kwargs):
4106-
"""Download the archive of a project export.
4107-
4108-
Args:
4109-
streamed (bool): If True the data will be processed by chunks of
4110-
`chunk_size` and each chunk is passed to `action` for
4111-
reatment
4112-
action (callable): Callable responsible of dealing with chunk of
4113-
data
4114-
chunk_size (int): Size of each chunk
4115-
**kwargs: Extra options to send to the server (e.g. sudo)
4116-
4117-
Raises:
4118-
GitlabAuthenticationError: If authentication is not correct
4119-
GitlabGetError: If the server failed to perform the request
4120-
4121-
Returns:
4122-
str: The blob content if streamed is False, None otherwise
4123-
"""
4124-
path = "/projects/%s/export/download" % self.project_id
4125-
result = self.manager.gitlab.http_get(
4126-
path, streamed=streamed, raw=True, **kwargs
4127-
)
4128-
return utils.response_content(result, streamed, action, chunk_size)
4129-
41304103

41314104
class ProjectExportManager(GetWithoutIdMixin, CreateMixin, RESTManager):
41324105
_path = "/projects/%(project_id)s/export"

0 commit comments

Comments
 (0)