Index: lib/operation.py |
diff --git a/lib/operation.py b/lib/operation.py |
index efbd53d7bf5eb76402f5af6b6f18b21926e4b1d8..b1a1eb970c0a1cc06937e544395da38e07bcf7aa 100644 |
--- a/lib/operation.py |
+++ b/lib/operation.py |
@@ -33,18 +33,6 @@ class Operation: |
Each operation has a name, and this class handles displaying this name |
as it reports progress. |
- |
- |
- Operation Objects |
- ================= |
- |
- verbose: True / False |
- In verbose mode all output from subprocesses is displayed, otherwise |
- this output is normally supressed, unless we think it indicates an error. |
- |
- progress: True / False |
- The output from subprocesses can be analysed in a very basic manner to |
- try to present progress information to the user. |
""" |
# Force color on/off, or use color only if stdout is a terminal. |
COLOR_OFF, COLOR_ON, COLOR_IF_TERMINAL = range(3) |
@@ -60,8 +48,8 @@ class Operation: |
COLOR_IF_TERMINAL: send color if output apperas to be a terminal. |
""" |
self._name = name # Operation name. |
- self.verbose = False # True to echo subprocess output. |
- self.progress = True # True to report progress of the operation |
+ self._verbose = False # True to echo subprocess output. |
+ self._progress = True # True to report progress of the operation |
self._column = 0 # Current output column (always 0 unless verbose). |
self._update_len = 0 # Length of last progress update message. |
self._line = '' # text of current line, so far |
@@ -92,8 +80,8 @@ class Operation: |
This finishes any output line currently in progress and resets the color |
back to normal. |
""" |
- self._FinishLine(self.verbose, final=True) |
- if self._column and self.verbose: |
+ self._FinishLine(self._verbose, final=True) |
+ if self._column and self._verbose: |
print self._color.Stop() |
self._column = 0 |
@@ -106,6 +94,28 @@ class Operation: |
""" |
return self._error_count > 0 |
+ def SetVerbose(self, verbose): |
+ """Enable / disable verbose mode. |
+ |
+ In verbose mode all output from subprocesses is displayed, otherwise |
+ this output is normally supressed, unless we think it indicates an error. |
+ |
+ Args: |
+ verbose: True to display all subprocess output, False to supress. |
+ """ |
+ self._verbose = verbose |
+ |
+ def SetProgress(self, progress): |
+ """Enable / disable progress display. |
+ |
+ The output from subprocesses can be analysed in a very basic manner to |
+ try to present progress information to the user. |
+ |
+ Args: |
+ progress: True to enable progress display, False to disable. |
+ """ |
+ self._progress = progress |
+ |
def SetName(self, name): |
"""Set the name of the operation as displayed to the user. |
@@ -123,7 +133,7 @@ class Operation: |
Args: |
line: the output line to filter, as a string. |
- print_error: True to print the error, False to just record it. |
+ print_it: True to print the error, False to just record it. |
""" |
bad_things = ['Cannot GET', 'ERROR', '!!!', 'FAILED'] |
for bad_thing in bad_things: |
@@ -158,9 +168,9 @@ class Operation: |
if total > 0: |
update_str = '%s...%d%% (%d of %d)' % (self._name, |
upto * 100 // total, upto, total) |
- if self.progress: |
+ if self._progress: |
# Finish the current line, print progress, and remember its length. |
- self._FinishLine(self.verbose) |
+ self._FinishLine(self._verbose) |
# Sometimes the progress string shrinks and in this case we need to |
# blank out the characters at the end of the line that will not be |
@@ -284,7 +294,7 @@ class Operation: |
# If we now have a whole line, check it for errors and progress. |
if newline: |
- self._FilterOutputForErrors(self._line, print_error=not display) |
+ self._FilterOutputForErrors(self._line, print_it=not display) |
self._FilterOutputForProgress(self._line) |
self._line = '' |
@@ -306,17 +316,16 @@ class Operation: |
#TODO(sjg): Just use a list as the input parameter to avoid the split. |
""" |
- # We cannot use splitlines() here as we need this exact behavior |
- lines = data.split('\r\n') |
+ lines = data.splitlines() |
# Output each full line, with a \n after it. |
for line in lines[:-1]: |
- self._Out(stream, line, display=self.verbose, newline=True) |
+ self._Out(stream, line, display=self._verbose, newline=True) |
# If we have a partial line at the end, output what we have. |
# We will continue it later. |
if lines[-1]: |
- self._Out(stream, lines[-1], display=self.verbose) |
+ self._Out(stream, lines[-1], display=self._verbose) |
# Flush so that the terminal will receive partial line output (now!) |
sys.stdout.flush() |
@@ -333,13 +342,3 @@ class Operation: |
""" |
self._Out(None, line, display=True, newline=True) |
self._FinishLine(display=True) |
- |
- def Info(self, line): |
- """Output a line of information text to the display in verbose mode. |
- |
- Args: |
- line: text to output (without \n on the end) |
- """ |
- self._Out(None, self._color.Color(self._color.BLUE, line), |
- display=self.verbose, newline=True) |
- self._FinishLine(display=True) |