Skip to content

Commit facbc8c

Browse files
author
Gauvain Pocentek
committed
[cli] Fix the project-export download
Closes python-gitlab#559
1 parent e9506d1 commit facbc8c

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

gitlab/v4/cli.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from __future__ import print_function
2020
import inspect
2121
import operator
22+
import sys
2223

2324
import six
2425

@@ -54,11 +55,18 @@ def __init__(self, gl, what, action, args):
5455
self.args[attr_name] = obj.get()
5556

5657
def __call__(self):
58+
# Check for a method that matches object + action
59+
method = 'do_%s_%s' % (self.what, self.action)
60+
if hasattr(self, method):
61+
return getattr(self, method)()
62+
63+
# Fallback to standard actions (get, list, create, ...)
5764
method = 'do_%s' % self.action
5865
if hasattr(self, method):
5966
return getattr(self, method)()
60-
else:
61-
return self.do_custom()
67+
68+
# Finally try to find custom methods
69+
return self.do_custom()
6270

6371
def do_custom(self):
6472
in_obj = cli.custom_actions[self.cls_name][self.action][2]
@@ -77,6 +85,20 @@ def do_custom(self):
7785
else:
7886
return getattr(self.mgr, self.action)(**self.args)
7987

88+
def do_project_export_download(self):
89+
try:
90+
project = self.gl.projects.get(int(self.args['project_id']),
91+
lazy=True)
92+
data = project.exports.get().download()
93+
if hasattr(sys.stdout, 'buffer'):
94+
# python3
95+
sys.stdout.buffer.write(data)
96+
else:
97+
sys.stdout.write(data)
98+
99+
except Exception as e:
100+
cli.die("Impossible to download the export", e)
101+
80102
def do_create(self):
81103
try:
82104
return self.mgr.create(self.args)

0 commit comments

Comments
 (0)