Files
firebase-ios-sdk/scripts/lib/command_trace.py
T
Gil 3e3bcb41f7 Rewrite lint.sh as check_lint.py (#3161)
* Rewrite lint.sh as check_lint.py

This makes several beneficial changes:

  * Runs in parallel: lint all now takes 5.5 seconds, down from 25.
  * Supports linting specific files, passed on the command-line.
  * Defaults to linting files changed since master, pass --all to lint
    everything.
  * Infers header language based on related files.
  * Lays the groundwork for linting more than just C++.
  * Adds support for linting python.

* Fix lint errors

* Use check_lint.py in check.sh

* Remove lint.sh

* Python lint configuration

* Enable python linting in travis
2019-06-14 09:22:55 -07:00

80 lines
2.1 KiB
Python

# Copyright 2019 Google
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from lib import terminal
_commands = logging.getLogger('commands')
def log(command_args):
"""Logs that a command has run.
Args:
command_args: A list of the command and its arguments.
"""
if _commands.isEnabledFor(logging.DEBUG):
columns = terminal.columns()
text = ' '.join(command_args)
# When just passing --trace, shorten output to the width of the current
# window. When running extra verbose don't shorten.
if not logging.root.isEnabledFor(logging.INFO):
if len(text) >= columns:
text = text[0:columns - 5] + ' ...'
_commands.debug('%s', text)
def add_arguments(parser):
"""Adds standard arguments to the given ArgumentParser."""
parser.add_argument('--trace', action='store_true',
help='show commands')
parser.add_argument('--verbose', '-v', action='count', default=0,
help='run verbosely')
def enable_tracing():
"""Enables tracing of command execution."""
_commands.setLevel(logging.DEBUG)
def setup(args):
"""Prepares for tracing/verbosity based on the given parsed arguments."""
level = logging.WARN
if args.trace:
enable_tracing()
if args.verbose >= 2:
level = logging.DEBUG
elif args.verbose >= 1:
level = logging.INFO
logging.basicConfig(format='%(message)s', level=level)
def parse_args(parser):
"""Shortcut that adds arguments, parses, and runs setup.
Returns:
The args result from parser.parse_args().
"""
add_arguments(parser)
args = parser.parse_args()
setup(args)
return args