Allow objects to be streamed to stdout

Change-Id: Icd8de6b2122fe77926d93da9bda08f56c3672a7a
This commit is contained in:
Honza Pokorny
2017-06-21 12:53:38 -03:00
parent c0719c36d1
commit ae35a29169
7 changed files with 70 additions and 7 deletions

View File

@@ -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,