use stdout in format() closes #469
This commit is contained in:
parent
15a82c59f0
commit
23009fe4a9
1 changed files with 8 additions and 1 deletions
|
|
@ -1071,7 +1071,11 @@ class ReplApplication(Cmd, BaseApplication):
|
||||||
def set_formatter_header(self, string):
|
def set_formatter_header(self, string):
|
||||||
self.formatter.set_header(string)
|
self.formatter.set_header(string)
|
||||||
|
|
||||||
def format(self, result):
|
def format(self, result, output=sys.stdout):
|
||||||
|
if output != sys.stdout:
|
||||||
|
saveout = sys.stdout
|
||||||
|
fsock = open(output, 'w')
|
||||||
|
sys.stdout = fsock
|
||||||
fields = self.selected_fields
|
fields = self.selected_fields
|
||||||
if fields in ('$direct', '$full'):
|
if fields in ('$direct', '$full'):
|
||||||
fields = None
|
fields = None
|
||||||
|
|
@ -1081,6 +1085,9 @@ class ReplApplication(Cmd, BaseApplication):
|
||||||
print e
|
print e
|
||||||
except MandatoryFieldsNotFound, e:
|
except MandatoryFieldsNotFound, e:
|
||||||
print >> sys.stderr, '%s Hint: select missing fields or use another formatter (ex: multiline).' % e
|
print >> sys.stderr, '%s Hint: select missing fields or use another formatter (ex: multiline).' % e
|
||||||
|
if output != sys.stdout:
|
||||||
|
sys.stdout = saveout
|
||||||
|
fsock.close()
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
self.formatter.flush()
|
self.formatter.flush()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue