diff options
| author | Honza Pokorny <honza@redhat.com> | 2017-06-21 12:53:38 -0300 |
|---|---|---|
| committer | Honza Pokorny <honza@redhat.com> | 2017-07-05 20:08:18 -0300 |
| commit | ae35a29169ab460cdd5d6b8c26d376c000a5c10e (patch) | |
| tree | dd11ee942ea877cfbeb329b21516e456f3476a83 /openstackclient/api | |
| parent | c0719c36d1a3f268b6bfba4c83aac632f1b546fe (diff) | |
| download | python-openstackclient-ae35a29169ab460cdd5d6b8c26d376c000a5c10e.tar.gz | |
Allow objects to be streamed to stdout
Change-Id: Icd8de6b2122fe77926d93da9bda08f56c3672a7a
Diffstat (limited to 'openstackclient/api')
| -rw-r--r-- | openstackclient/api/object_store_v1.py | 15 |
1 files changed, 10 insertions, 5 deletions
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, |
