From ae35a29169ab460cdd5d6b8c26d376c000a5c10e Mon Sep 17 00:00:00 2001 From: Honza Pokorny Date: Wed, 21 Jun 2017 12:53:38 -0300 Subject: Allow objects to be streamed to stdout Change-Id: Icd8de6b2122fe77926d93da9bda08f56c3672a7a --- openstackclient/api/object_store_v1.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'openstackclient/api/object_store_v1.py') diff --git a/openstackclient/api/object_store_v1.py b/openstackclient/api/object_store_v1.py index 74c4a46f..31033525 100644 --- a/openstackclient/api/object_store_v1.py +++ b/openstackclient/api/object_store_v1.py @@ -16,6 +16,7 @@ import io import logging import os +import sys from osc_lib import utils import six @@ -376,12 +377,16 @@ class APIv1(api.BaseAPI): stream=True, ) if response.status_code == 200: - if not os.path.exists(os.path.dirname(file)): - if len(os.path.dirname(file)) > 0: - os.makedirs(os.path.dirname(file)) - with open(file, 'wb') as f: + if file == '-': for chunk in response.iter_content(64 * 1024): - f.write(chunk) + sys.stdout.write(chunk) + else: + if not os.path.exists(os.path.dirname(file)): + if len(os.path.dirname(file)) > 0: + os.makedirs(os.path.dirname(file)) + with open(file, 'wb') as f: + for chunk in response.iter_content(64 * 1024): + f.write(chunk) def object_set( self, -- cgit v1.2.1