Commit 25f0c0cf authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Expand stream output to pithos print methods

parent fbb253e8
......@@ -362,9 +362,9 @@ class file_list(_file_container_command, _optional_json, _name_filter):
enum=FlagArgument('Enumerate results', '--enumerate')
)
def print_objects(self, object_list):
def print_objects(self, object_list, out=stdout):
if self['json_output']:
print_json(object_list)
print_json(object_list, out=out)
return
out = StringIO() if self['more'] else stdout
for index, obj in enumerate(object_list):
......@@ -396,9 +396,9 @@ class file_list(_file_container_command, _optional_json, _name_filter):
if self['more']:
pager(out.getvalue())
def print_containers(self, container_list):
def print_containers(self, container_list, out=stdout):
if self['json_output']:
print_json(container_list)
print_json(container_list, out=out)
return
out = StringIO() if self['more'] else stdout
for index, container in enumerate(container_list):
......@@ -1613,10 +1613,10 @@ class file_permissions(_pithos_init):
"""
def print_permissions(permissions_dict):
def print_permissions(permissions_dict, out=stdout):
expected_keys = ('read', 'write')
if set(permissions_dict).issubset(expected_keys):
print_dict(permissions_dict)
print_dict(permissions_dict, out=out)
else:
invalid_keys = set(permissions_dict.keys()).difference(expected_keys)
raiseCLIError(
......@@ -2069,10 +2069,12 @@ class file_sharers(_file_account_command, _optional_json):
self._run()
def version_print(versions):
print_items([dict(id=vitem[0], created=strftime(
'%d-%m-%Y %H:%M:%S',
localtime(float(vitem[1])))) for vitem in versions])
def version_print(versions, out=stdout):
print_items(
[dict(id=vitem[0], created=strftime(
'%d-%m-%Y %H:%M:%S',
localtime(float(vitem[1])))) for vitem in versions],
out=out)
@command(pithos_cmds)
......
......@@ -149,10 +149,8 @@ class RequestManager(Logged):
sendlog.info('%s %s://%s%s%s' % (
self.method, self.scheme, self.netloc, self.path, plog))
for key, val in self.headers.items():
#if (not self.LOG_TOKEN) and key.lower() == 'x-auth-token':
# continue
show = (key.lower() != 'x-auth-token') or self.LOG_TOKEN
sendlog.info(' %s: %s%s' % (key, val if show else '', plog))
sendlog.info(' %s: %s%s' % (key, val if show else '...', plog))
if self.data:
sendlog.info('data size:%s%s' % (len(self.data), plog))
if self.LOG_DATA:
......@@ -230,12 +228,11 @@ class ResponseManager(Logged):
self.status_code, self.status, plog))
self._headers = dict()
for k, v in r.getheaders():
if (not self.LOG_TOKEN) and (
k.lower() == 'x-auth-token'):
continue
show = (k.lower() != 'x-auth-token') or self.LOG_TOKEN
v = unquote(v)
self._headers[k] = v
recvlog.info(' %s: %s%s' % (k, v, plog))
recvlog.info(' %s: %s%s' % (
k, v if show else '...', plog))
self._content = r.read()
recvlog.info('data size: %s%s' % (
len(self._content) if self._content else 0, plog))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment