Skip to content
This repository was archived by the owner on Dec 17, 2018. It is now read-only.

Commit 2ee057a

Browse files
committed
Implement preliminary quiet logging mode
Enable quiet console logging when the --quiet argument is passed into the command. When enabled, console logging will be less verbose. Regards issue codecov#102
1 parent 0743daa commit 2ee057a

File tree

1 file changed

+52
-27
lines changed

1 file changed

+52
-27
lines changed

codecov/__init__.py

+52-27
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
version = VERSION = __version__ = '2.0.15'
3434

3535
COLOR = True
36+
QUIET = False
3637

3738
is_merge_commit = re.compile(r'^Merge\s\w{40}\sinto\s\w{40}$')
3839

@@ -110,29 +111,47 @@
110111

111112
def write(text, color=None):
112113
global COLOR
114+
global QUIET
115+
113116
if COLOR:
114-
text = text.replace('==>', '\033[90m==>\033[0m')
115-
text = text.replace(' +', ' \033[32m+\033[0m')
116-
text = text.replace('XX>', '\033[31mXX>\033[0m')
117-
if text[:6] == 'Error:':
118-
text = '\033[41mError:\033[0m\033[91m%s\033[0m' % text[6:]
119-
elif text[:4] == 'Tip:':
120-
text = '\033[42mTip:\033[0m\033[32m%s\033[0m' % text[4:]
121-
elif text.strip()[:4] == 'http':
122-
text = '\033[92m%s\033[0m' % text
123-
elif text[:7] == 'Codecov':
124-
text = """
125-
_____ _
126-
/ ____| | |
127-
| | ___ __| | ___ ___ _____ __
128-
| | / _ \ / _ |/ _ \/ __/ _ \ \ / /
129-
| |___| (_) | (_| | __/ (_| (_) \ V /
130-
\_____\___/ \____|\___|\___\___/ \_/
131-
%s\n""" % text.split(' ')[1]
132-
elif color == 'red':
133-
text = '\033[91m%s\033[0m' % text
134-
elif color == 'green':
135-
text = '\033[92m%s\033[0m' % text
117+
if not QUIET:
118+
text = text.replace('==>', '\033[90m==>\033[0m')
119+
text = text.replace(' +', ' \033[32m+\033[0m')
120+
text = text.replace('XX>', '\033[31mXX>\033[0m')
121+
if text[:6] == 'Error:':
122+
text = '\033[41mError:\033[0m\033[91m%s\033[0m' % text[6:]
123+
elif text[:4] == 'Tip:':
124+
text = '\033[42mTip:\033[0m\033[32m%s\033[0m' % text[4:]
125+
elif text.strip()[:4] == 'http':
126+
text = '\033[92m%s\033[0m' % text
127+
elif text[:7] == 'Codecov':
128+
text = """
129+
_____ _
130+
/ ____| | |
131+
| | ___ __| | ___ ___ _____ __
132+
| | / _ \ / _ |/ _ \/ __/ _ \ \ / /
133+
| |___| (_) | (_| | __/ (_| (_) \ V /
134+
\_____\___/ \____|\___|\___\___/ \_/
135+
%s\n""" % text.split(' ')[1]
136+
elif color == 'red':
137+
text = '\033[91m%s\033[0m' % text
138+
elif color == 'green':
139+
text = '\033[92m%s\033[0m' % text
140+
else:
141+
text = text.replace('==> ', '')
142+
text = text.replace(' + ', '')
143+
text = text.replace(' ', '')
144+
text = text.replace('XX>', '')
145+
text = text.replace(' -> ', '')
146+
text = text.replace(' x> ', '')
147+
if text[:4] == 'Tip:':
148+
text = ''
149+
elif text.strip()[:4] == 'http':
150+
text = '\033[92m%s\033[0m' % text
151+
elif color == 'red':
152+
text = '\033[91m%s\033[0m' % text
153+
elif color == 'green':
154+
text = '\033[92m%s\033[0m' % text
136155

137156
sys.stdout.write(text + '\n')
138157

@@ -197,6 +216,7 @@ def _add_env_if_not_empty(lst, value):
197216

198217

199218
def main(*argv, **kwargs):
219+
global QUIET
200220
root = os.getcwd()
201221

202222
# Build Parser
@@ -212,6 +232,7 @@ def main(*argv, **kwargs):
212232
basics.add_argument('--env', '-e', nargs="*", default=None, help="Store environment variables to help distinguish CI builds.")
213233
basics.add_argument('--required', action="store_true", default=False, help="If Codecov fails it will exit 1 - possibly failing the CI build.")
214234
basics.add_argument('--name', '-n', default=None, help="Custom defined name of the upload. Visible in Codecov UI.")
235+
basics.add_argument('--quiet', '-q', action='store_true', help="Enable quiet console logging. Helps minimize file size of large logs.")
215236

216237
gcov = parser.add_argument_group('======================== gcov ========================')
217238
gcov.add_argument('--gcov-root', default=None, help="Project root directory when preparing gcov")
@@ -251,6 +272,9 @@ def main(*argv, **kwargs):
251272

252273
include_env = set()
253274

275+
if codecov.quiet:
276+
QUIET = True
277+
254278
# add from cli
255279
if codecov.env:
256280
# -e VAR1,VAR2 or -e VAR1 -e VAR2
@@ -777,11 +801,12 @@ def main(*argv, **kwargs):
777801
else:
778802
write('Tip: See all example repositories: https://github.com/codecov?query=example')
779803

780-
write('Support channels:', 'green')
781-
write(' Email: [email protected]\n'
782-
' IRC: #codecov\n'
783-
' Gitter: https://gitter.im/codecov/support\n'
784-
' Twitter: @codecov\n')
804+
if not QUIET:
805+
write('Support channels:', 'green')
806+
write(' Email: [email protected]\n'
807+
' IRC: #codecov\n'
808+
' Gitter: https://gitter.im/codecov/support\n'
809+
' Twitter: @codecov\n')
785810
sys.exit(1 if codecov.required else 0)
786811

787812
else:

0 commit comments

Comments
 (0)