From 500186e1033f6288c17670cc595b9abcd275cd58 Mon Sep 17 00:00:00 2001 From: antonio Date: Mon, 4 Oct 2021 12:27:41 -0400 Subject: [PATCH 1/2] improves the cli flag handling and it adds support for loglevels --- kivy_ios/toolchain.py | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/kivy_ios/toolchain.py b/kivy_ios/toolchain.py index ff4a8a6a..298304a3 100755 --- a/kivy_ios/toolchain.py +++ b/kivy_ios/toolchain.py @@ -33,11 +33,6 @@ 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) # Quiet the loggers we don't care about sh_logging = logging.getLogger('sh') @@ -85,6 +80,18 @@ def remove_junk(d): unlink(join(root, fn)) +def log_setup(level, quiet=True): + """ Setup logging at level. """ + 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) + + class ChromeDownloader(FancyURLopener): version = ( 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 ' @@ -1284,11 +1291,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 From 4c903d5e14c2b65d5537fe571d4ed834663a51df Mon Sep 17 00:00:00 2001 From: antonio Date: Tue, 5 Oct 2021 08:17:01 -0400 Subject: [PATCH 2/2] consolidate logging config in place --- kivy_ios/toolchain.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/kivy_ios/toolchain.py b/kivy_ios/toolchain.py index 298304a3..9d8ce033 100755 --- a/kivy_ios/toolchain.py +++ b/kivy_ios/toolchain.py @@ -33,12 +33,23 @@ initial_working_directory = getcwd() +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): @@ -80,18 +91,6 @@ def remove_junk(d): unlink(join(root, fn)) -def log_setup(level, quiet=True): - """ Setup logging at level. """ - 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) - - class ChromeDownloader(FancyURLopener): version = ( 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 '