From f0167fddfd909ed6b5f4252f55504288dcb16405 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 18 Mar 2015 18:16:23 +0000 Subject: Make warning messages more user friendly. Printing the file and line number of the warning's origin makes the warning itself harder to spot, and can make it appear as if something has actually gone wrong. Change-Id: Ie77357d9a061d31e234e6e434521d2d274409773 --- morphlib/app.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/morphlib/app.py b/morphlib/app.py index c8fe397d..654451f4 100644 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -20,6 +20,7 @@ import pipes import sys import time import urlparse +import warnings import extensions import morphlib @@ -213,6 +214,12 @@ class Morph(cliapp.Application): with morphlib.util.hide_password_environment_variables(os.environ): cliapp.Application.log_config(self) + def pretty_warnings(message, category, filename, lineno, + file=None, line=None): + return 'WARNING: %s' % (message) + + warnings.formatwarning = pretty_warnings + def process_args(self, args): self.check_time() -- cgit v1.2.1