From 252f10e8f32eef6279a9b1ea6eccfe77787c0312 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Fri, 16 Sep 2022 07:48:22 -0300 Subject: [PATCH] Added command line option to specify warnings to be excluded. - Useful for warnings issued before applying the global options (i.e during import). Fixes #296 --- CHANGELOG.md | 3 +++ README.md | 3 ++- kibot/__main__.py | 29 +++++++++++++++++++++++------ kibot/log.py | 4 ++-- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 626d9a8c..efad267c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 (See #261) - Environment and text variables expansion is now recursive. So in `${VAR}` the *VAR* can contain `${OTHER_VAR}` + - Command line option to specify warnings to be excluded. Useful for + warnings issued before applying the global options (i.e during + import). (#296) - New outputs: - PCB_Variant: saves a PCB with filters and variants applied. - File_Copy: used to copy files to the output directory. (#279) diff --git a/README.md b/README.md index ea611cc3..c402f666 100644 --- a/README.md +++ b/README.md @@ -3659,7 +3659,7 @@ KiBot: KiCad automation tool for documents generation Usage: kibot [-b BOARD] [-e SCHEMA] [-c CONFIG] [-d OUT_DIR] [-s PRE] [-D] [-q | -v...] [-C | -i | -n] [-m MKFILE] [-A] [-g DEF] ... - [-E DEF] ... [TARGET...] + [-E DEF] ... [-w LIST] [TARGET...] kibot [-v...] [-b BOARD] [-e SCHEMA] [-c PLOT_CONFIG] [-E DEF] ... --list kibot [-v...] [-b BOARD] [-d OUT_DIR] [-p | -P] --example kibot [-v...] [--start PATH] [-d OUT_DIR] [--dry] [-t, --type TYPE]... @@ -3698,6 +3698,7 @@ Options: -s PRE, --skip-pre PRE Skip preflights, comma separated or `all` -v, --verbose Show debugging information -V, --version Show program's version number and exit + -w, --no-warn LIST Exclude the mentioned warnings (comma sep) -x, --example Create a template configuration file Quick start options: diff --git a/kibot/__main__.py b/kibot/__main__.py index 599f8456..38c03a19 100644 --- a/kibot/__main__.py +++ b/kibot/__main__.py @@ -10,7 +10,7 @@ Usage: kibot [-b BOARD] [-e SCHEMA] [-c CONFIG] [-d OUT_DIR] [-s PRE] [-D] [-q | -v...] [-C | -i | -n] [-m MKFILE] [-A] [-g DEF] ... - [-E DEF] ... [TARGET...] + [-E DEF] ... [-w LIST] [TARGET...] kibot [-v...] [-b BOARD] [-e SCHEMA] [-c PLOT_CONFIG] [-E DEF] ... --list kibot [-v...] [-b BOARD] [-d OUT_DIR] [-p | -P] --example kibot [-v...] [--start PATH] [-d OUT_DIR] [--dry] [-t, --type TYPE]... @@ -49,6 +49,7 @@ Options: -s PRE, --skip-pre PRE Skip preflights, comma separated or `all` -v, --verbose Show debugging information -V, --version Show program's version number and exit + -w, --no-warn LIST Exclude the mentioned warnings (comma sep) -x, --example Create a template configuration file Quick start options: @@ -69,13 +70,13 @@ Help options: --help-variants List supported variants and details """ -import os -import sys -from sys import path as sys_path -import re +from glob import glob import gzip import locale -from glob import glob +import os +import re +import sys +from sys import path as sys_path from . import __version__, __copyright__, __license__ # Import log first to set the domain from . import log @@ -262,6 +263,21 @@ def parse_global_redef(args): GS.cli_global_defs[var] = redef[len(var)+1:] +class SimpleFilter(object): + def __init__(self, num): + self.number = num + self.regex = re.compile('') + + +def apply_warning_filter(args): + if args.no_warn: + try: + log.set_filters([SimpleFilter(int(n)) for n in args.no_warn.split(',')]) + except ValueError: + logger.error('-w/--no-warn must specify a comma separated list of numbers ({})'.format(args.no_warn)) + sys.exit(EXIT_BAD_ARGS) + + def main(): set_locale() ver = 'KiBot '+__version__+' - '+__copyright__+' - License: '+__license__ @@ -272,6 +288,7 @@ def main(): GS.debug_enabled = log.set_verbosity(logger, args.verbose, args.quiet) log.debug_level = GS.debug_level = args.verbose logger.debug('KiBot {} verbose level: {}'.format(__version__, args.verbose)) + apply_warning_filter(args) # Now we have the debug level set we can check (and optionally inform) KiCad info detect_kicad() diff --git a/kibot/log.py b/kibot/log.py index da413243..b3c132b8 100644 --- a/kibot/log.py +++ b/kibot/log.py @@ -26,7 +26,7 @@ else: colorama_init() # Default domain, base name for the tool domain = 'kilog' -filters = None +filters = [] root_logger = None visual_level = None debug_level = 0 @@ -55,7 +55,7 @@ def set_domain(name): def set_filters(f): """Set the list of warning filters""" global filters - filters = f + filters = f+filters class MyLogger(logging.Logger):