Chromium Code Reviews| Index: gclient_utils.py |
| diff --git a/gclient_utils.py b/gclient_utils.py |
| index 7003fc88676b49e79aba8acbd5f68bdd2cdb7fd3..931054238b7ca74b6010bb20dc0ac8d4382d1c55 100644 |
| --- a/gclient_utils.py |
| +++ b/gclient_utils.py |
| @@ -4,6 +4,7 @@ |
| """Generic utils.""" |
| +import atexit |
| import codecs |
| import cStringIO |
| import logging |
| @@ -27,6 +28,9 @@ RETRY_MAX = 3 |
| RETRY_INITIAL_SLEEP = 0.5 |
| +_WARNINGS = [] |
| + |
| + |
| class Error(Exception): |
| """gclient exception class.""" |
| def __init__(self, msg, *args, **kwargs): |
| @@ -36,6 +40,21 @@ class Error(Exception): |
| super(Error, self).__init__(msg, *args, **kwargs) |
| +def _DisplayWarningsAtExit(): |
| + """Display any stored warnings when the program exits.""" |
| + if _WARNINGS: |
| + print >> sys.stderr, '\n\nWarnings:' |
| + for warning in _WARNINGS: |
| + print >> sys.stderr, warning |
| + |
| +atexit.register(_DisplayWarningsAtExit) |
|
M-A Ruel
2014/03/24 16:25:30
I'd prefer something more formal, a try/finally in
|
| + |
| + |
| +def WarnOnExit(msg): |
| + """Display the given warning when the program exits.""" |
| + _WARNINGS.append(msg) |
| + |
| + |
| def SplitUrlRevision(url): |
| """Splits url and returns a two-tuple: url, rev""" |
| if url.startswith('ssh:'): |