From 5153c068d02a31b23629b0cc383e85ef71bbf5cb Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 11 Mar 2015 15:40:06 +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. --- morphlib/app.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/morphlib/app.py b/morphlib/app.py index b8bae850..fd4a3516 100644 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -21,6 +21,7 @@ import pipes import sys import time import urlparse +import warnings import extensions import morphlib @@ -214,6 +215,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