sb: Update code base to support Python3 and Python2.

Fix Windows support to allow MSYS2 Python to be used.

Updates #2619.
This commit is contained in:
Chris Johns
2016-03-07 11:56:02 +11:00
parent b537e55364
commit 3a972f6102
29 changed files with 412 additions and 314 deletions

View File

@@ -21,6 +21,8 @@
# Log output to stdout and/or a file.
#
from __future__ import print_function
import os
import sys
@@ -56,16 +58,16 @@ def _output(text = os.linesep, log = None):
default.output(text)
else:
for l in text.replace(chr(13), '').splitlines():
print l
print(l)
sys.stdout.flush()
def stdout_raw(text = os.linesep):
print text,
print(text, end=' ')
sys.stdout.flush()
def stderr(text = os.linesep, log = None):
for l in text.replace(chr(13), '').splitlines():
print >> sys.stderr, l
print(l, file = sys.stderr)
sys.stderr.flush()
def output(text = os.linesep, log = None):
@@ -75,7 +77,7 @@ def output(text = os.linesep, log = None):
def notice(text = os.linesep, log = None):
if not quiet and default is not None and not default.has_stdout():
for l in text.replace(chr(13), '').splitlines():
print l
print(l)
sys.stdout.flush()
_output(text, log)
@@ -114,8 +116,8 @@ class log:
self.fhs[1] = sys.stderr
else:
try:
self.fhs.append(file(s, 'w'))
except IOError, ioe:
self.fhs.append(open(s, 'w'))
except IOError as ioe:
raise error.general("creating log file '" + s + \
"': " + str(ioe))
@@ -168,41 +170,41 @@ if __name__ == "__main__":
l.output('log: hello world CRLF\r\n')
l.output('log: hello world NONE')
l.flush()
print '=-' * 40
print 'tail: %d' % (len(l.tail))
print l
print '=-' * 40
print('=-' * 40)
print('tail: %d' % (len(l.tail)))
print(l)
print('=-' * 40)
for i in range(0, 10):
l.output('log: hello world 2: %d\n' % (i))
l.flush()
print '=-' * 40
print 'tail: %d' % (len(l.tail))
print l
print '=-' * 40
print('=-' * 40)
print('tail: %d' % (len(l.tail)))
print(l)
print('=-' * 40)
for i in [0, 1]:
quiet = False
tracing = False
print '- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30)
print('- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30))
trace('trace with quiet and trace off')
notice('notice with quiet and trace off')
quiet = True
tracing = False
print '- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30)
print('- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30))
trace('trace with quiet on and trace off')
notice('notice with quiet on and trace off')
quiet = False
tracing = True
print '- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30)
print('- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30))
trace('trace with quiet off and trace on')
notice('notice with quiet off and trace on')
quiet = True
tracing = True
print '- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30)
print('- quiet:%s - trace:%s %s' % (str(quiet), str(tracing), '-' * 30))
trace('trace with quiet on and trace on')
notice('notice with quiet on and trace on')
default = l
print '=-' * 40
print 'tail: %d' % (len(l.tail))
print l
print '=-' * 40
print('=-' * 40)
print('tail: %d' % (len(l.tail)))
print(l)
print('=-' * 40)
del l