Files
zulip/tools/linter_lib/printer.py
rht a603a4f9f5 Remove from __future__ import absolute_import.
Except in:
- docs/writing-bots-guide.md, because bots are supposed to be Python 2
  compatible
- puppet/zulip_ops/files/zulip-ec2-configure-interfaces, because this
  script is still on python2.7
- tools/lint
- tools/linter_lib
- tools/lister.py

For the latter two, because they might be yanked away to a separate repo
for general use with other FLOSS projects.
2017-10-17 22:59:42 -07:00

35 lines
923 B
Python

from __future__ import print_function
from __future__ import absolute_import
import sys
import os
from itertools import cycle
sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
from scripts.lib.zulip_tools import ENDC, BOLDRED, GREEN, YELLOW, BLUE, MAGENTA, CYAN
from typing import Union, Text
colors = cycle([GREEN, YELLOW, BLUE, MAGENTA, CYAN])
def print_err(name, color, line):
# type: (str, str, Union[Text, bytes]) -> None
# Decode with UTF-8 if in Python 3 and `line` is of bytes type.
# (Python 2 does this automatically)
if sys.version_info[0] == 3 and isinstance(line, bytes):
line = line.decode('utf-8')
print('{}{}{}|{end} {}{}{end}'.format(
color,
name,
' ' * max(0, 10 - len(name)),
BOLDRED,
line.rstrip(),
end=ENDC)
)
# Python 2's print function does not have a `flush` option.
sys.stdout.flush()