19
19
from __future__ import print_function
20
20
import inspect
21
21
import operator
22
+ import sys
22
23
23
24
import six
24
25
@@ -54,11 +55,18 @@ def __init__(self, gl, what, action, args):
54
55
self .args [attr_name ] = obj .get ()
55
56
56
57
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, ...)
57
64
method = 'do_%s' % self .action
58
65
if hasattr (self , method ):
59
66
return getattr (self , method )()
60
- else :
61
- return self .do_custom ()
67
+
68
+ # Finally try to find custom methods
69
+ return self .do_custom ()
62
70
63
71
def do_custom (self ):
64
72
in_obj = cli .custom_actions [self .cls_name ][self .action ][2 ]
@@ -77,6 +85,20 @@ def do_custom(self):
77
85
else :
78
86
return getattr (self .mgr , self .action )(** self .args )
79
87
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
+
80
102
def do_create (self ):
81
103
try :
82
104
return self .mgr .create (self .args )
0 commit comments