[MERGE] nested-progress-bar api
Aaron Bentley
aaron.bentley at utoronto.ca
Tue Mar 7 14:59:37 GMT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Robert Collins wrote:
> This adds the nested progress bar api and converts the existing code to
> use nested_progress_bar everywhere that a progress bar was being
> created, and to release them.
> === modified file 'a/bzrlib/errors.py'
> --- a/bzrlib/errors.py
> +++ b/bzrlib/errors.py
> @@ -764,3 +764,7 @@
>
> class LocalRequiresBoundBranch(BzrNewError):
> """Cannot perform local-only commits on unbound branches."""
> +
> +
> +class MissingProgressBarFinish(BzrNewError):
> + """A nested progress bar was not 'finished' correctly."""
>
> === modified file 'a/bzrlib/progress.py'
> --- a/bzrlib/progress.py
> +++ b/bzrlib/progress.py
> @@ -1,5 +1,5 @@
> # Copyright (C) 2005 Aaron Bentley <aaron.bentley at utoronto.ca>
> -# Copyright (C) 2005 Canonical <canonical.com>
> +# Copyright (C) 2005, 2006 Canonical <canonical.com>
> #
> # This program is free software; you can redistribute it and/or modify
> # it under the terms of the GNU General Public License as published by
> @@ -42,6 +42,9 @@
> from collections import deque
>
>
> +import bzrlib.errors as errors
> +
> +
> def _supports_progress(f):
> if not hasattr(f, 'isatty'):
> return False
> @@ -61,8 +64,10 @@
> else:
> return DotsProgressBar(to_file=to_file, **kwargs)
>
> -
> -class _BaseProgressBar(object):
> +
> +class ProgressBarStack(object):
> + """A stack of progress bars."""
> +
> def __init__(self,
> to_file=sys.stderr,
> show_pct=False,
> @@ -71,6 +76,48 @@
> show_bar=True,
> show_count=True,
> to_messages_file=sys.stdout):
> + """Setup the stack with the parameters the progress bars should have."""
> + self._to_file = to_file
> + self._show_pct = show_pct
> + self._show_spinner = show_spinner
> + self._show_eta = show_eta
> + self._show_bar = show_bar
> + self._show_count = show_count
> + self._to_messages_file = to_messages_file
> + self._stack = []
> +
> + def get_nested(self):
> + """Return a nested progress bar."""
> + # initial implementation - return a new bar each time.
> + new_bar = TTYProgressBar(to_file=self._to_file,
> + show_pct=self._show_pct,
> + show_spinner=self._show_spinner,
> + show_eta=self._show_eta,
> + show_bar=self._show_bar,
> + show_count=self._show_count,
> + to_messages_file=self._to_messages_file,
> + _stack=self)
> + self._stack.append(new_bar)
> + return new_bar
> +
> + def return_pb(self, bar):
> + """Return bar after its been used."""
> + if bar != self._stack[-1]:
Shouldn't this be "if bar is not"? You want to get the same thing back,
not an equivalent thing, right?
> class TextUIFactory(UIFactory):
> -
> - def __init__(self):
> - super(TextUIFactory, self).__init__()
> - self._progress_bar_stack = None
Huh? Why'd we have this in the first place?
> if self.bzrdir.root_transport.is_readonly():
> raise errors.UpgradeReadonly
> self.transport = self.bzrdir.root_transport
> - self.convert()
> + self.pb = ui.ui_factory.nested_progress_bar()
> + try:
> + self.convert()
> + finally:
> + self.pb.finished()
Personally, I'd pass the pb in, because it's not part of the object's
permanent state. If you're doing this, you should probably do self.pb =
None after the finished() call.
+1, possibly with a tweak or two.
Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFEDZ/Z0F+nu1YWqI0RAtoTAJ9UAVDBUHFy6Xjo6SuhWqRH2v8hAgCdHJI9
NoUDu1ZkKzv8tOwJ88COTsQ=
=l9HI
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list