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

Commit

Permalink
Implement preliminary quiet logging mode
Browse files Browse the repository at this point in the history
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
  • Loading branch information
samuelpiltch committed Oct 25, 2018
1 parent 0743daa commit 2ee057a
Showing 1 changed file with 52 additions and 27 deletions.
79 changes: 52 additions & 27 deletions codecov/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
version = VERSION = __version__ = '2.0.15'

COLOR = True
QUIET = False

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

Expand Down Expand Up @@ -110,29 +111,47 @@

def write(text, color=None):
global COLOR
global QUIET

if COLOR:
text = text.replace('==>', '\033[90m==>\033[0m')
text = text.replace(' +', ' \033[32m+\033[0m')
text = text.replace('XX>', '\033[31mXX>\033[0m')
if text[:6] == 'Error:':
text = '\033[41mError:\033[0m\033[91m%s\033[0m' % text[6:]
elif text[:4] == 'Tip:':
text = '\033[42mTip:\033[0m\033[32m%s\033[0m' % text[4:]
elif text.strip()[:4] == 'http':
text = '\033[92m%s\033[0m' % text
elif text[:7] == 'Codecov':
text = """
_____ _
/ ____| | |
| | ___ __| | ___ ___ _____ __
| | / _ \ / _ |/ _ \/ __/ _ \ \ / /
| |___| (_) | (_| | __/ (_| (_) \ V /
\_____\___/ \____|\___|\___\___/ \_/
%s\n""" % text.split(' ')[1]
elif color == 'red':
text = '\033[91m%s\033[0m' % text
elif color == 'green':
text = '\033[92m%s\033[0m' % text
if not QUIET:
text = text.replace('==>', '\033[90m==>\033[0m')
text = text.replace(' +', ' \033[32m+\033[0m')
text = text.replace('XX>', '\033[31mXX>\033[0m')
if text[:6] == 'Error:':
text = '\033[41mError:\033[0m\033[91m%s\033[0m' % text[6:]
elif text[:4] == 'Tip:':
text = '\033[42mTip:\033[0m\033[32m%s\033[0m' % text[4:]
elif text.strip()[:4] == 'http':
text = '\033[92m%s\033[0m' % text
elif text[:7] == 'Codecov':
text = """
_____ _
/ ____| | |
| | ___ __| | ___ ___ _____ __
| | / _ \ / _ |/ _ \/ __/ _ \ \ / /
| |___| (_) | (_| | __/ (_| (_) \ V /
\_____\___/ \____|\___|\___\___/ \_/
%s\n""" % text.split(' ')[1]
elif color == 'red':
text = '\033[91m%s\033[0m' % text
elif color == 'green':
text = '\033[92m%s\033[0m' % text
else:
text = text.replace('==> ', '')
text = text.replace(' + ', '')
text = text.replace(' ', '')
text = text.replace('XX>', '')
text = text.replace(' -> ', '')
text = text.replace(' x> ', '')
if text[:4] == 'Tip:':
text = ''
elif text.strip()[:4] == 'http':
text = '\033[92m%s\033[0m' % text
elif color == 'red':
text = '\033[91m%s\033[0m' % text
elif color == 'green':
text = '\033[92m%s\033[0m' % text

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

Expand Down Expand Up @@ -197,6 +216,7 @@ def _add_env_if_not_empty(lst, value):


def main(*argv, **kwargs):
global QUIET
root = os.getcwd()

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

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

include_env = set()

if codecov.quiet:
QUIET = True

# add from cli
if codecov.env:
# -e VAR1,VAR2 or -e VAR1 -e VAR2
Expand Down Expand Up @@ -777,11 +801,12 @@ def main(*argv, **kwargs):
else:
write('Tip: See all example repositories: https://github.com/codecov?query=example')

write('Support channels:', 'green')
write(' Email: hello@codecov.io\n'
' IRC: #codecov\n'
' Gitter: https://gitter.im/codecov/support\n'
' Twitter: @codecov\n')
if not QUIET:
write('Support channels:', 'green')
write(' Email: hello@codecov.io\n'
' IRC: #codecov\n'
' Gitter: https://gitter.im/codecov/support\n'
' Twitter: @codecov\n')
sys.exit(1 if codecov.required else 0)

else:
Expand Down

0 comments on commit 2ee057a

Please sign in to comment.