From bbef1f916c8ab65ed7f9717859caf516ebedb335 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Mon, 9 Jul 2018 19:24:42 +0200 Subject: [cli] Output: handle bytes in API responses Closes #548 --- gitlab/v4/cli.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gitlab/v4/cli.py') diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py index 880b07d..b786e75 100644 --- a/gitlab/v4/cli.py +++ b/gitlab/v4/cli.py @@ -366,3 +366,6 @@ def run(gl, what, action, args, verbose, output, fields): printer.display(get_dict(data, fields), verbose=verbose, obj=data) elif isinstance(data, six.string_types): print(data) + else: + # We assume we got bytes + print(data.decode()) -- cgit v1.2.1 From a139179ea8246b2f000327bd1e106d5708077b31 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Thu, 12 Jul 2018 19:43:06 +0200 Subject: [cli] Fix the case where we have nothing to print --- gitlab/v4/cli.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'gitlab/v4/cli.py') diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py index b786e75..eca7d38 100644 --- a/gitlab/v4/cli.py +++ b/gitlab/v4/cli.py @@ -366,6 +366,5 @@ def run(gl, what, action, args, verbose, output, fields): printer.display(get_dict(data, fields), verbose=verbose, obj=data) elif isinstance(data, six.string_types): print(data) - else: - # We assume we got bytes + elif hasattr(data, 'decode'): print(data.decode()) -- cgit v1.2.1 From facbc8cb858ac400e912a905be3668ee2d33e2cd Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Sat, 25 Aug 2018 16:22:28 +0200 Subject: [cli] Fix the project-export download Closes #559 --- gitlab/v4/cli.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'gitlab/v4/cli.py') 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) -- cgit v1.2.1 From d29a48981b521bf31d6f0304b88f39a63185328a Mon Sep 17 00:00:00 2001 From: Max Wittig Date: Sun, 7 Oct 2018 17:34:44 +0200 Subject: docs(cli): add PyYAML requirement notice Fixes #606 --- gitlab/v4/cli.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'gitlab/v4/cli.py') diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py index a876f9e..242874d 100644 --- a/gitlab/v4/cli.py +++ b/gitlab/v4/cli.py @@ -302,14 +302,24 @@ class JSONPrinter(object): class YAMLPrinter(object): def display(self, d, **kwargs): - import yaml # noqa - print(yaml.safe_dump(d, default_flow_style=False)) + try: + import yaml # noqa + print(yaml.safe_dump(d, default_flow_style=False)) + except ImportError: + exit("PyYaml is not installed.\n" + "Install it with `pip install PyYaml` " + "to use the yaml output feature") def display_list(self, data, fields, **kwargs): - import yaml # noqa - print(yaml.safe_dump( - [get_dict(obj, fields) for obj in data], - default_flow_style=False)) + try: + import yaml # noqa + print(yaml.safe_dump( + [get_dict(obj, fields) for obj in data], + default_flow_style=False)) + except ImportError: + exit("PyYaml is not installed.\n" + "Install it with `pip install PyYaml` " + "to use the yaml output feature") class LegacyPrinter(object): -- cgit v1.2.1