[PATCH] progress: check stderr.isatty() before each print
Augie Fackler
durin42 at gmail.com
Sun Jun 27 22:25:18 CDT 2010
D'oh, typo in this one. Resending presently, ignore this one.
On Jun 27, 2010, at 10:21 PM, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <durin42 at gmail.com>
> # Date 1277695247 18000
> # Branch stable
> # Node ID 2b079be584dca14b53ef3794360b12c0909fe9ce
> # Parent 51021f4c80b5dcf608626ddc24b21c155df2cae8
> progress: check stderr.isatty() before each print
>
> This prevents writing progress information to a non-tty stderr if one is
> swapped in after startup, which happens in `hg serve`.
>
> diff --git a/hgext/progress.py b/hgext/progress.py
> --- a/hgext/progress.py
> +++ b/hgext/progress.py
> @@ -51,6 +51,9 @@
> def spacejoin(*args):
> return ' '.join(s for s in args if s)
>
> +def shouldprint(ui):
> + return sys.stderr.isatty() or ui.configbool('progress', 'assume-tty')
> +
> class progbar(object):
> def __init__(self, ui):
> self.ui = ui
> @@ -69,6 +72,8 @@
> default=['topic', 'bar', 'number'])
>
> def show(self, topic, pos, item, unit, total):
> + if not shouldprint(self.ui):
> + return
> termwidth = self.width()
> self.printed = True
> head = ''
> @@ -137,9 +142,13 @@
> sys.stderr.flush()
>
> def clear(self):
> + if not shouldprint(self.ui):
> + return
> sys.stderr.write('\r%s\r' % (' ' * self.width()))
>
> def complete(self):
> + if not shouldprint(self.ui):
> + return
> if self.ui.configbool('progress', 'clear-complete', default=True):
> self.clear()
> else:
> @@ -177,8 +186,7 @@
> # setconfig('progress', 'disable', 'True') to disable this extension
> if ui.configbool('progress', 'disable'):
> return
> - if ((sys.stderr.isatty() or ui.configbool('progress', 'assume-tty'))
> - and not ui.debugflag and not ui.quiet):
> + if shouldprint(ui) and and not ui.debugflag and not ui.quiet:
> # we instantiate one globally shared progress bar to avoid
> # competing progress bars when multiple UI objects get created
> global sharedprog
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list