| OLD | NEW |
| 1 # Copyright (C) 2010, 2012 Google Inc. All rights reserved. | 1 # Copyright (C) 2010, 2012 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 import logging | 29 import logging |
| 30 import os | 30 import os |
| 31 import sys | 31 import sys |
| 32 import time | 32 import time |
| 33 | 33 |
| 34 LOG_HANDLER_NAME = 'MeteredStreamLogHandler' | 34 LOG_HANDLER_NAME = 'MeteredStreamLogHandler' |
| 35 | 35 |
| 36 | 36 |
| 37 class MeteredStream(object): | 37 class MeteredStream(object): |
| 38 """ | 38 """This class implements a stream wrapper that has 'meters' as well as |
| 39 This class implements a stream wrapper that has 'meters' as well as | |
| 40 regular output. A 'meter' is a single line of text that can be erased | 39 regular output. A 'meter' is a single line of text that can be erased |
| 41 and rewritten repeatedly, without producing multiple lines of output. It | 40 and rewritten repeatedly, without producing multiple lines of output. It |
| 42 can be used to produce effects like progress bars. | 41 can be used to produce effects like progress bars. |
| 43 """ | 42 """ |
| 44 | 43 |
| 45 @staticmethod | 44 @staticmethod |
| 46 def _erasure(txt): | 45 def _erasure(txt): |
| 47 num_chars = len(txt) | 46 num_chars = len(txt) |
| 48 return '\b' * num_chars + ' ' * num_chars + '\b' * num_chars | 47 return '\b' * num_chars + ' ' * num_chars + '\b' * num_chars |
| 49 | 48 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 129 |
| 131 class _LogHandler(logging.Handler): | 130 class _LogHandler(logging.Handler): |
| 132 | 131 |
| 133 def __init__(self, meter): | 132 def __init__(self, meter): |
| 134 logging.Handler.__init__(self) | 133 logging.Handler.__init__(self) |
| 135 self._meter = meter | 134 self._meter = meter |
| 136 self.name = LOG_HANDLER_NAME | 135 self.name = LOG_HANDLER_NAME |
| 137 | 136 |
| 138 def emit(self, record): | 137 def emit(self, record): |
| 139 self._meter.writeln(record.getMessage(), record.created, record.process) | 138 self._meter.writeln(record.getMessage(), record.created, record.process) |
| OLD | NEW |