Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(761)

Side by Side Diff: webkit/tools/layout_tests/layout_package/metered_stream.py

Issue 545145: Move the layout test scripts into a 'webkitpy' subdirectory in preparation... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: try to de-confuse svn and the try bots Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """
7 Package that implements a stream wrapper that has 'meters' as well as
8 regular output. A 'meter' is a single line of text that can be erased
9 and rewritten repeatedly, without producing multiple lines of output. It
10 can be used to produce effects like progress bars.
11 """
12
13
14 class MeteredStream:
15 """This class is a wrapper around a stream that allows you to implement
16 meters.
17
18 It can be used like a stream, but calling update() will print
19 the string followed by only a carriage return (instead of a carriage
20 return and a line feed). This can be used to implement progress bars and
21 other sorts of meters. Note that anything written by update() will be
22 erased by a subsequent update(), write(), or flush()."""
23
24 def __init__(self, verbose, stream):
25 """
26 Args:
27 verbose: whether update is a no-op
28 stream: output stream to write to
29 """
30 self._dirty = False
31 self._verbose = verbose
32 self._stream = stream
33 self._last_update = ""
34
35 def write(self, txt):
36 """Write text directly to the stream, overwriting and resetting the
37 meter."""
38 if self._dirty:
39 self.update("")
40 self._dirty = False
41 self._stream.write(txt)
42
43 def flush(self):
44 """Flush any buffered output."""
45 self._stream.flush()
46
47 def update(self, str):
48 """Write an update to the stream that will get overwritten by the next
49 update() or by a write().
50
51 This is used for progress updates that don't need to be preserved in
52 the log. Note that verbose disables this routine; we have this in
53 case we are logging lots of output and the update()s will get lost
54 or won't work properly (typically because verbose streams are
55 redirected to files.
56
57 TODO(dpranke): figure out if there is a way to detect if we're writing
58 to a stream that handles CRs correctly (e.g., terminals). That might
59 be a cleaner way of handling this.
60 """
61 if self._verbose:
62 return
63
64 # Print the necessary number of backspaces to erase the previous
65 # message.
66 self._stream.write("\b" * len(self._last_update))
67 self._stream.write(str)
68 num_remaining = len(self._last_update) - len(str)
69 if num_remaining > 0:
70 self._stream.write(" " * num_remaining + "\b" * num_remaining)
71 self._last_update = str
72 self._dirty = True
OLDNEW
« no previous file with comments | « webkit/tools/layout_tests/layout_package/lighttpd.conf ('k') | webkit/tools/layout_tests/layout_package/path_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698