Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improves the cli flag handling and it adds support for loglevels #654

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions kivy_ios/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,23 @@

initial_working_directory = getcwd()

# For more detailed logging, use something like
# format='%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(funcName)s():%(lineno)d] %(message)s'
logging.basicConfig(format='[%(levelname)-8s] %(message)s',
datefmt='%Y-%m-%d:%H:%M:%S',
level=logging.DEBUG)
logger = logging.getLogger(__name__)

# Quiet the loggers we don't care about
sh_logging = logging.getLogger('sh')
sh_logging.setLevel(logging.WARNING)

logger = logging.getLogger(__name__)
def log_setup(level, quiet=True):
""" Setup logging at level. """
# customize loging here
if quiet:
level -= 1
level = logging.DEBUG if level > 0 else logging.WARNING if level < 0 else logging.INFO
# For more detailed logging, use something like
# format='%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(funcName)s():%(lineno)d] %(message)s'
logging.basicConfig(format='[%(levelname)-8s] %(message)s',
datefmt='%Y-%m-%d:%H:%M:%S',
level=level)
# Quiet the loggers we don't care about
sh_logging = logging.getLogger('sh')
sh_logging.setLevel(logging.WARNING)


def shprint(command, *args, **kwargs):
Expand Down Expand Up @@ -1284,11 +1290,29 @@ def __init__(self):
pip Install a pip dependency into the distribution
""")
parser.add_argument("command", help="Command to run")
args = parser.parse_args(sys.argv[1:2])
parser.add_argument('--verbose', '-v', action='append_const', const=1)
parser.add_argument('--quiet', '-q', action='append_const', const=-1)

if len(sys.argv) == 1 or sys.argv[1] in { "--help", "-h" }:
parser.print_help()
exit(1)

# holding --help|-h flag for commands
has_help = { "--help", "-h"} & set(sys.argv)
sys.argv = [ a for a in sys.argv if a not in { "--help", "-h" } ]

args, other = parser.parse_known_args()

if not hasattr(self, args.command):
print('Unrecognized command')
parser.print_help()
exit(1)

log_setup(sum((args.verbose or [0]) + (args.quiet or [0])))

sys.argv = [sys.argv[0], args.command] + other
if has_help:
sys.argv.append("--help")
getattr(self, args.command)()

@staticmethod
Expand Down