Writes text to the stdout (console) stream
(data, forceOutput=False, bold=False, contentType=None, status=CONTENT_STATUS.IN_PROGRESS, coloring=True)
| 1024 | return retVal |
| 1025 | |
| 1026 | def dataToStdout(data, forceOutput=False, bold=False, contentType=None, status=CONTENT_STATUS.IN_PROGRESS, coloring=True): |
| 1027 | """ |
| 1028 | Writes text to the stdout (console) stream |
| 1029 | """ |
| 1030 | |
| 1031 | if not IS_TTY and isinstance(data, six.string_types) and data.startswith("\r"): |
| 1032 | if re.search(r"\(\d+%\)", data): |
| 1033 | data = "" |
| 1034 | else: |
| 1035 | data = "\n%s" % data.strip("\r") |
| 1036 | |
| 1037 | if not kb.get("threadException"): |
| 1038 | if forceOutput or not (getCurrentThreadData().disableStdOut or kb.get("wizardMode")): |
| 1039 | multiThreadMode = kb.get("multiThreadMode") |
| 1040 | if multiThreadMode: |
| 1041 | logging._acquireLock() |
| 1042 | |
| 1043 | try: |
| 1044 | if conf.get("api"): |
| 1045 | sys.stdout.write(stdoutEncode(clearColors(data)), status, contentType) |
| 1046 | else: |
| 1047 | sys.stdout.write(stdoutEncode(setColor(data, bold=bold) if coloring else clearColors(data))) |
| 1048 | except IOError: |
| 1049 | pass |
| 1050 | except UnicodeEncodeError: |
| 1051 | sys.stdout.write(re.sub(r"[^ -~]", '?', clearColors(data))) |
| 1052 | finally: |
| 1053 | try: |
| 1054 | sys.stdout.flush() |
| 1055 | except IOError: |
| 1056 | raise SystemExit |
| 1057 | |
| 1058 | if multiThreadMode: |
| 1059 | logging._releaseLock() |
| 1060 | |
| 1061 | kb.prependFlag = isinstance(data, six.string_types) and (len(data) == 1 and data not in ('\n', '\r') or len(data) > 2 and data[0] == '\r' and data[-1] != '\n') |
| 1062 | |
| 1063 | def dataToTrafficFile(data): |
| 1064 | if not conf.trafficFile: |
searching dependent graphs…