Skip to content

Commit

Permalink
Add command line option to disable individual warnings.
Browse files Browse the repository at this point in the history
Also show the warning number associated with the warning when outputting it to
let the users know which warning do they need to disable if they don't want to
see some message.
  • Loading branch information
vadz committed Sep 28, 2014
1 parent 4d2ece1 commit 74acdf0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
v1.2.6 (????-??-??)
===================

New Features
------------

- Add "-w" command line option to disable specific warnings.

Bug fixes
---------

Expand Down
5 changes: 4 additions & 1 deletion src/bkl/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,11 @@ def warning(wnum, msg, *args, **kwargs):
bkl.error.warning(WARN.NOT_SUPPORTED, "target %s not supported", t.name, pos=t.source_pos)
"""
if wnum in logging.getLogger().disabled_warnings:
return

text = msg % args
e = {}
e = { "wnum": wnum }
try:
e["pos"] = kwargs["pos"]
except KeyError:
Expand Down
22 changes: 21 additions & 1 deletion src/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ def format(self, record):
if hasattr(record, "pos") and record.pos:
msg = "%s: " % record.pos
if level != logging.INFO:
msg += "%s: " % record.levelname.lower()
msg += record.levelname.lower()
if hasattr(record, "wnum"):
msg += " "
msg += str(record.wnum)
msg += ": "
msg += record.getMessage()
if level == logging.ERROR:
msg = self.format_error(msg)
Expand All @@ -69,6 +73,7 @@ def format(self, record):
log_handler = logging.StreamHandler()
log_handler.setFormatter(BklFormatter())
logger.addHandler(log_handler)
logger.disabled_warnings = set()

# OptionParser only allows a string version argument, it can't be a callback.
# That's too bad, because it's too early to import bkl.version now, it would
Expand Down Expand Up @@ -102,6 +107,11 @@ def get_version(self):
action="append", dest="toolsets",
metavar="TOOLSET",
help="only generate files for the given toolset (may be specified more than once)")
parser.add_option(
"-w", "--warning",
action="append", dest="warnings",
metavar="WNUM",
help="disable the given warning(s) (separate with commas to specify more than one)")

debug_group = OptionGroup(parser, "Debug Options")
debug_group.add_option(
Expand Down Expand Up @@ -157,6 +167,16 @@ def get_version(self):
intr = Interpreter()
if options.toolsets:
intr.limit_toolsets(options.toolsets)

for optval in options.warnings:
for s in optval.split(','):
try:
wnum = int(s)
except ValueError:
sys.stderr.write('invalid warning number "%s" specified\n' % s)
sys.exit(3)
logger.disabled_warnings.add(wnum)

intr.process_file(args[0])
logger.info("created files: %d, updated files: %d (time: %.1fs)",
bkl.io.num_created, bkl.io.num_modified, time() - start_time)
Expand Down

0 comments on commit 74acdf0

Please sign in to comment.