jp (base): added no_lf in disp() to avoid printing a line feed

This commit is contained in:
Goffi 2017-06-28 01:21:49 +02:00
commit e8409b13e6

View file

@ -244,18 +244,25 @@ class Jp(object):
for cache_data in cache:
cache_data[0](*cache_data[1:])
def disp(self, msg, verbosity=0, error=False):
def disp(self, msg, verbosity=0, error=False, no_lf=False):
"""Print a message to user
@param msg(unicode): message to print
@param verbosity(int): minimal verbosity to display the message
@param error(bool): if True, print to stderr instead of stdout
@param no_lf(bool): if True, do not emit line feed at the end of line
"""
if self.verbosity >= verbosity:
if error:
print >>sys.stderr,msg.encode('utf-8')
if no_lf:
print >>sys.stderr,msg.encode('utf-8'),
else:
print >>sys.stderr,msg.encode('utf-8')
else:
print msg.encode('utf-8')
if no_lf:
print msg.encode('utf-8'),
else:
print msg.encode('utf-8')
def output(self, type_, name, extra_outputs, data):
if name in extra_outputs:
@ -762,8 +769,8 @@ class CommandBase(object):
"""
self.disp(_(u"Error while doing operation: {}").format(error_msg), error=True)
def disp(self, msg, verbosity=0, error=False):
return self.host.disp(msg, verbosity, error)
def disp(self, msg, verbosity=0, error=False, no_lf=False):
return self.host.disp(msg, verbosity, error, no_lf)
def output(self, data):
try: