summaryrefslogtreecommitdiff
path: root/gitlab/v4/cli.py
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2018-08-25 16:22:28 +0200
committerGauvain Pocentek <gauvain@pocentek.net>2018-08-25 16:22:28 +0200
commitfacbc8cb858ac400e912a905be3668ee2d33e2cd (patch)
tree4c780fc0681e56bece927ed8fa5aaf828a7339af /gitlab/v4/cli.py
parente9506d15a971888a9af72b37d3e7dbce55e49126 (diff)
downloadgitlab-facbc8cb858ac400e912a905be3668ee2d33e2cd.tar.gz
[cli] Fix the project-export download
Closes #559
Diffstat (limited to 'gitlab/v4/cli.py')
-rw-r--r--gitlab/v4/cli.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py
index eca7d38..a876f9e 100644
--- a/gitlab/v4/cli.py
+++ b/gitlab/v4/cli.py
@@ -19,6 +19,7 @@
from __future__ import print_function
import inspect
import operator
+import sys
import six
@@ -54,11 +55,18 @@ class GitlabCLI(object):
self.args[attr_name] = obj.get()
def __call__(self):
+ # Check for a method that matches object + action
+ method = 'do_%s_%s' % (self.what, self.action)
+ if hasattr(self, method):
+ return getattr(self, method)()
+
+ # Fallback to standard actions (get, list, create, ...)
method = 'do_%s' % self.action
if hasattr(self, method):
return getattr(self, method)()
- else:
- return self.do_custom()
+
+ # Finally try to find custom methods
+ return self.do_custom()
def do_custom(self):
in_obj = cli.custom_actions[self.cls_name][self.action][2]
@@ -77,6 +85,20 @@ class GitlabCLI(object):
else:
return getattr(self.mgr, self.action)(**self.args)
+ def do_project_export_download(self):
+ try:
+ project = self.gl.projects.get(int(self.args['project_id']),
+ lazy=True)
+ data = project.exports.get().download()
+ if hasattr(sys.stdout, 'buffer'):
+ # python3
+ sys.stdout.buffer.write(data)
+ else:
+ sys.stdout.write(data)
+
+ except Exception as e:
+ cli.die("Impossible to download the export", e)
+
def do_create(self):
try:
return self.mgr.create(self.args)