2018-09-21 08:34:55 +00:00
|
|
|
from __future__ import print_function
|
2017-11-08 04:27:57 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
_COLOR_CODES = {
|
2018-09-26 06:09:00 +00:00
|
|
|
"white": u'\033[0m',
|
|
|
|
"red": u'\033[31m',
|
|
|
|
"green": u'\033[32m',
|
|
|
|
"orange": u'\033[33m',
|
|
|
|
"blue": u'\033[34m',
|
|
|
|
"purple": u'\033[35m',
|
|
|
|
"W": u'\033[0m',
|
|
|
|
"R": u'\033[31m',
|
|
|
|
"G": u'\033[32m',
|
|
|
|
"O": u'\033[33m',
|
|
|
|
"B": u'\033[34m',
|
|
|
|
"P": u'\033[35m'
|
2017-11-08 04:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-21 08:34:55 +00:00
|
|
|
def console_log(data, color="white", end="\n"):
|
2017-11-08 04:27:57 +00:00
|
|
|
"""
|
|
|
|
log data to console.
|
|
|
|
(if not flush console log, Gitlab-CI won't update logs during job execution)
|
|
|
|
|
|
|
|
:param data: data content
|
|
|
|
:param color: color
|
|
|
|
"""
|
|
|
|
if color not in _COLOR_CODES:
|
|
|
|
color = "white"
|
|
|
|
color_codes = _COLOR_CODES[color]
|
2018-09-26 06:09:00 +00:00
|
|
|
if type(data) is type(b''):
|
|
|
|
data = data.decode('utf-8', 'replace')
|
2018-09-21 08:34:55 +00:00
|
|
|
print(color_codes + data, end=end)
|
2017-11-08 04:27:57 +00:00
|
|
|
if color not in ["white", "W"]:
|
|
|
|
# reset color to white for later logs
|
2018-09-26 06:09:00 +00:00
|
|
|
print(_COLOR_CODES["white"] + u"\r")
|
2018-09-21 08:34:55 +00:00
|
|
|
sys.stdout.flush()
|